blob: 1caec339b66b8e3eb176ac5e4a74858002a19c66 [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;
Andrew Sappersteinabef55a2016-06-19 12:49:00 -070041import android.content.ContextWrapper;
Chris Wren40c5ed32014-06-24 18:24:23 -040042import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070045import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070046import android.content.SharedPreferences;
Sunny Goyal745bad92016-05-02 10:54:12 -070047import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Winson Chungaafa03c2010-06-11 17:34:16 -070048import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.pm.PackageManager;
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;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070057import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.drawable.Drawable;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020060import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Sunny Goyale26d1002016-06-20 14:52:14 -070066import android.os.Trace;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070067import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070073import android.view.Display;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.HapticFeedbackConstants;
75import android.view.KeyEvent;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070077import android.view.MotionEvent;
78import android.view.Surface;
79import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070080import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080081import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070082import android.view.ViewGroup;
83import android.view.ViewTreeObserver;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080085import android.view.accessibility.AccessibilityEvent;
Tony Wickhame2217252016-03-22 16:34:23 -070086import android.view.accessibility.AccessibilityManager;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070087import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.widget.Advanceable;
Adam Cohen96d30a12013-07-16 18:13:21 -070090import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080091import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Toast;
Sunny Goyala1d1bf32015-06-26 13:24:53 -070093
Sunny Goyal651077b2014-06-30 14:15:31 -070094import com.android.launcher3.DropTarget.DragObject;
Sunny Goyala7ce1662016-05-31 15:01:35 -070095import com.android.launcher3.LauncherSettings.Favorites;
Sunny Goyalae502842016-06-17 08:43:56 -070096import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070097import com.android.launcher3.allapps.AllAppsContainerView;
Hyunyoung Song645764e2016-06-06 14:19:02 -070098import com.android.launcher3.allapps.AllAppsTransitionController;
Sunny Goyal0ac7ede2016-01-29 13:14:14 -080099import com.android.launcher3.allapps.DefaultAppSearchController;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700100import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100101import com.android.launcher3.compat.LauncherActivityInfoCompat;
102import com.android.launcher3.compat.LauncherAppsCompat;
103import com.android.launcher3.compat.UserHandleCompat;
104import com.android.launcher3.compat.UserManagerCompat;
Tony Wickhame0c33232016-02-08 11:37:04 -0800105import com.android.launcher3.config.FeatureFlags;
Sunny Goyal6c56c682015-07-16 14:09:05 -0700106import com.android.launcher3.config.ProviderConfig;
Vadim Tryshevfedca432015-08-19 17:55:02 -0700107import com.android.launcher3.dragndrop.DragController;
108import com.android.launcher3.dragndrop.DragLayer;
109import com.android.launcher3.dragndrop.DragView;
Tony Wickham827cef22016-03-17 15:39:39 -0700110import com.android.launcher3.dynamicui.ExtractedColors;
Sunny Goyal26119432016-02-18 22:09:23 +0000111import com.android.launcher3.folder.Folder;
112import com.android.launcher3.folder.FolderIcon;
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700113import com.android.launcher3.keyboard.ViewGroupFocusHelper;
Sunny Goyala7ce1662016-05-31 15:01:35 -0700114import com.android.launcher3.logging.FileLog;
Hyunyoung Songaa953652016-04-19 18:30:24 -0700115import com.android.launcher3.logging.UserEventDispatcher;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700116import com.android.launcher3.model.WidgetsModel;
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700117import com.android.launcher3.pageindicators.PageIndicator;
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700118import com.android.launcher3.shortcuts.DeepShortcutManager;
Tony Wickham49c8d292016-07-01 11:44:34 -0700119import com.android.launcher3.shortcuts.DeepShortcutsContainer;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700120import com.android.launcher3.shortcuts.ShortcutKey;
Hyunyoung Song5aa27142016-07-21 11:48:37 -0700121import com.android.launcher3.userevent.nano.LauncherLogProto;
Winson Chung6b1c73f2015-06-18 11:38:42 -0700122import com.android.launcher3.util.ComponentKey;
Sunny Goyald3b87ef2016-07-28 12:11:54 -0700123import com.android.launcher3.util.ItemInfoMatcher;
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700124import com.android.launcher3.util.MultiHashMap;
Sunny Goyal04cc3a72016-05-17 10:32:43 -0700125import com.android.launcher3.util.PackageManagerHelper;
Sunny Goyal322d5562015-06-25 19:35:49 -0700126import com.android.launcher3.util.TestingUtils;
Adam Cohen091440a2015-03-18 14:16:05 -0700127import com.android.launcher3.util.Thunk;
Sunny Goyal527c7d32015-08-28 15:19:36 -0700128import com.android.launcher3.util.ViewOnDrawExecutor;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700129import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700130import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700131import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700132
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700133import java.io.FileDescriptor;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700134import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700135import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700136import java.util.Collection;
Sunny Goyal29538332016-02-18 09:10:19 -0800137import java.util.Collections;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700138import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700139import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700140import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700141
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142/**
143 * Default launcher application.
144 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100145public class Launcher extends Activity
Adam Cohen79d90c52016-04-22 13:29:20 -0700146 implements LauncherExterns, View.OnClickListener, OnLongClickListener,
147 LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener,
Tony Wickhame2217252016-03-22 16:34:23 -0700148 AccessibilityManager.AccessibilityStateChangeListener {
Vadim Tryshevfedca432015-08-19 17:55:02 -0700149 public static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700150 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
Sunny Goyalc84e6e12015-10-02 12:48:37 -0700152 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700153 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400154 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700155
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700157 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700158 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700159 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Michael Jurka8b805b12012-04-18 14:23:14 -0700161 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyald478c832016-04-01 12:04:16 -0700162 private static final int REQUEST_BIND_PENDING_APPWIDGET = 14;
Sunny Goyalff572272014-07-23 13:58:07 -0700163 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700164
Sunny Goyal28c6b962015-10-12 11:42:05 -0700165 private static final int REQUEST_PERMISSION_CALL_PHONE = 13;
166
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700167 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
168 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
169 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
170
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700171 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
172
Mathew Inwood876a8462013-06-14 14:12:41 +0100173 /**
174 * IntentStarter uses request codes starting with this. This must be greater than all activity
175 * request codes used internally.
176 */
177 protected static final int REQUEST_LAST = 100;
178
Michael Jurka0a457bf2012-11-19 14:05:05 -0800179 // To turn on these properties, type
Hyunyoung Songddec1c72016-04-12 18:32:04 -0700180 // adb shell setprop logTap.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800181 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182
Winson Chung2672ff92012-05-04 16:22:30 -0700183 // The Intent extra that defines whether to ignore the launch animation
184 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400185 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700186
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700187 public static final String ACTION_APPWIDGET_HOST_RESET =
188 "com.android.launcher3.intent.ACTION_APPWIDGET_HOST_RESET";
189
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 // Type: int
191 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700192 // Type: int
193 private static final String RUNTIME_STATE = "launcher.state";
Sunny Goyal756cd262015-08-20 12:33:21 -0700194 // Type: Content Values / parcelable
195 private static final String RUNTIME_STATE_PENDING_ADD_ITEM = "launcher.add_item";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700196 // Type: parcelable
197 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000198 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800200
Adam Cohen432609a2014-03-13 17:03:22 -0700201 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800202 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
Hyunyoung Songc001cf52016-07-21 17:32:43 -0700203 static final String APPS_VIEW_SHOWN = "launcher.apps_view_shown";
Adam Cohenb54a5982014-01-08 15:21:04 -0800204
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700205 /** The different states that Launcher can be in. */
Tony Wickham94e0d372015-09-11 12:17:48 -0700206 enum State { NONE, WORKSPACE, WORKSPACE_SPRING_LOADED, APPS, APPS_SPRING_LOADED,
207 WIDGETS, WIDGETS_SPRING_LOADED }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700208
Adam Cohen091440a2015-03-18 14:16:05 -0700209 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700210 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700211
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700212 private boolean mIsSafeModeEnabled;
213
Joe Onorato9c1289c2009-08-17 11:03:03 -0400214 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohen4f8071b2016-02-13 16:06:05 -0800215 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 500;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700216 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700217 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
Winson Chunga2413752012-04-03 14:22:34 -0700219 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700220 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
221 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700222 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700223
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700224 private final BroadcastReceiver mUiBroadcastReceiver = new BroadcastReceiver() {
225
226 @Override
227 public void onReceive(Context context, Intent intent) {
228 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
229 closeSystemDialogs();
230 } else if (ACTION_APPWIDGET_HOST_RESET.equals(intent.getAction())) {
231 if (mAppWidgetHost != null) {
232 mAppWidgetHost.startListening();
233 }
234 }
235 }
236 };
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800237
Adam Cohen091440a2015-03-18 14:16:05 -0700238 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700239 private View mLauncherView;
Adam Cohen091440a2015-03-18 14:16:05 -0700240 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800241 private DragController mDragController;
Sunny Goyal6178f132016-07-11 17:30:03 -0700242 private View mQsbContainer;
Sunny Goyal322d5562015-06-25 19:35:49 -0700243
244 public View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700245
Sunny Goyalffe83f12014-08-14 17:39:34 -0700246 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700247 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700248
Sunny Goyalaa8ef112015-06-12 20:04:41 -0700249 @Thunk final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800250 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800251 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700252
Michael Jurka0280c3b2010-09-17 15:00:07 -0700253 private int[] mTmpAddItemCellCoordinates = new int[2];
254
Sunny Goyal316490e2015-06-02 09:38:28 -0700255 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800256 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700257
Michael Jurka838a4ca2011-02-07 13:33:06 -0800258 private View mAllAppsButton;
Hyunyoung Song98ff38a2015-07-10 17:50:13 -0700259 private View mWidgetsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700260
Sunny Goyal47328fd2016-05-25 18:56:41 -0700261 private DropTargetBar mDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700262
263 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700264 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song645764e2016-06-06 14:19:02 -0700265 AllAppsTransitionController mAllAppsController;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700266
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700267 // Main container view and the model for the widget tray screen.
268 @Thunk WidgetsContainerView mWidgetsView;
269 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700270
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700272 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
273 // scroll issues (because the workspace may not have been measured yet) and extra work.
274 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
275 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276
277 private SpannableStringBuilder mDefaultKeySsb = null;
278
Adam Cohen091440a2015-03-18 14:16:05 -0700279 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400280
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800281 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 private boolean mRestoring;
283 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700284 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285
Michael Jurka1e2f4652013-07-08 18:03:46 -0700286 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700287 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Sunny Goyal527c7d32015-08-28 15:19:36 -0700288 private ViewOnDrawExecutor mPendingExecutor;
Michael Jurka7607c2f2013-04-03 14:33:19 -0700289
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800291 private IconCache mIconCache;
Tony Wickham827cef22016-03-17 15:39:39 -0700292 private ExtractedColors mExtractedColors;
Sunny Goyalae502842016-06-17 08:43:56 -0700293 private LauncherAccessibilityDelegate mAccessibilityDelegate;
Hyunyoung Songc001cf52016-07-21 17:32:43 -0700294 private boolean mIsResumeFromActionScreenOff;
Adam Cohen091440a2015-03-18 14:16:05 -0700295 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800296 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700297 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800298 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400299
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700300 /** Maps launcher activity components to their list of shortcut ids. */
301 private MultiHashMap<ComponentKey, String> mDeepShortcutMap = new MultiHashMap<>();
302
Adam Cohen61f560d2013-09-30 15:58:20 -0700303 private View.OnTouchListener mHapticFeedbackTouchListener;
304
Adam Cohended9f8d2010-11-03 13:25:16 -0700305 // Related to the auto-advancing of widgets
306 private final int ADVANCE_MSG = 1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700307 private static final int ADVANCE_INTERVAL = 20000;
308 private static final int ADVANCE_STAGGER = 250;
309
310 private boolean mAutoAdvanceRunning = false;
Adam Cohended9f8d2010-11-03 13:25:16 -0700311 private long mAutoAdvanceSentTime;
312 private long mAutoAdvanceTimeLeft = -1;
Sunny Goyal756cd262015-08-20 12:33:21 -0700313 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700314
Winson Chung400438b2011-01-16 17:53:48 -0800315 // Determines how long to wait after a rotation before restoring the screen orientation to
316 // match the sensor state.
Sunny Goyal756cd262015-08-20 12:33:21 -0700317 private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800318
Adam Cohen091440a2015-03-18 14:16:05 -0700319 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700320
Adam Cohen1462de32012-07-24 22:34:36 -0700321 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700322 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700323
Winson Chung46353de2012-02-16 14:05:10 -0800324 // We only want to get the SharedPreferences once since it does an FS stat each time we get
325 // it from the context.
326 private SharedPreferences mSharedPrefs;
327
Winson Chungf0c6ae02012-03-21 16:10:31 -0700328 // Holds the page that we need to animate to, and the icon views that we need to animate up
329 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700330 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700331 private Bitmap mFolderIconBitmap;
332 private Canvas mFolderIconCanvas;
333 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700334
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700335 private DeviceProfile mDeviceProfile;
336
Adam Cohen4b66bf32015-09-18 12:15:19 -0700337 private boolean mMoveToDefaultScreenFromNewIntent;
338
Winson Chung13eb5272015-05-11 16:30:13 -0700339 // This is set to the view that launched the activity that navigated the user away from
340 // launcher. Since there is no callback for when the activity has finished launching, enable
341 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800342 private BubbleTextView mWaitingForResume;
343
Adam Cohen59400422014-03-05 18:07:04 -0800344 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
345 new HashMap<String, CustomAppWidget>();
346
Adam Cohen59400422014-03-05 18:07:04 -0800347 static {
Sunny Goyal322d5562015-06-25 19:35:49 -0700348 if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
349 TestingUtils.addDummyWidget(sCustomAppWidgets);
Adam Cohen59400422014-03-05 18:07:04 -0800350 }
351 }
352
Hyunyoung Song06ca7562016-07-29 13:03:54 -0700353 // Exiting spring loaded mode happens with a delay. This runnable object triggers the
354 // state transition. If another state transition happened during this delay,
355 // simply unregister this runnable.
356 private Runnable mExitSpringLoadedModeRunnable;
357
Adam Cohen091440a2015-03-18 14:16:05 -0700358 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700359 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700360 if (mWorkspace != null) {
361 mWorkspace.buildPageHardwareLayers();
362 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700363 }
364 };
365
Adam Cohendb364c32014-05-20 14:23:40 -0700366 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800367
Adam Cohen091440a2015-03-18 14:16:05 -0700368 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800369 int requestCode;
370 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700371 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700372 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800373 int cellX;
374 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700375 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800376 }
377
Hyunyoung Songaa953652016-04-19 18:30:24 -0700378 private UserEventDispatcher mUserEventDispatcher;
Hyunyoung Songfbf19cc2016-02-19 12:14:47 -0800379
Sunny Goyal3333b0c2016-05-09 20:43:21 -0700380 public ViewGroupFocusHelper mFocusHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700381 private boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400382
383 @Thunk void setOrientation() {
384 if (mRotationEnabled) {
385 unlockScreenOrientation(true);
386 } else {
387 setRequestedOrientation(
388 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700389 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400390 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700391
Sunny Goyal745bad92016-05-02 10:54:12 -0700392 private RotationPrefChangeHandler mRotationPrefChangeHandler;
Sunny Goyal7779d622015-06-11 16:18:39 -0700393
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394 @Override
395 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700396 if (DEBUG_STRICT_MODE) {
397 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
398 .detectDiskReads()
399 .detectDiskWrites()
400 .detectNetwork() // or .detectAll() for all detectable problems
401 .penaltyLog()
402 .build());
403 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
404 .detectLeakedSqlLiteObjects()
405 .detectLeakedClosableObjects()
406 .penaltyLog()
407 .penaltyDeath()
408 .build());
409 }
Sunny Goyale26d1002016-06-20 14:52:14 -0700410 if (LauncherAppState.PROFILE_STARTUP) {
411 Trace.beginSection("Launcher-onCreate");
412 }
Winson Chunga2413752012-04-03 14:22:34 -0700413
Adam Cohen9211d422014-10-07 18:14:53 -0700414 if (mLauncherCallbacks != null) {
415 mLauncherCallbacks.preOnCreate();
416 }
417
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400419
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400420 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700421
Adam Cohen2e6da152015-05-06 11:42:25 -0700422 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700423 mDeviceProfile = getResources().getConfiguration().orientation
424 == Configuration.ORIENTATION_LANDSCAPE ?
Tony Wickham3a3517f2015-10-06 11:27:04 -0700425 app.getInvariantDeviceProfile().landscapeProfile
426 : app.getInvariantDeviceProfile().portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700427
Sunny Goyalf7258242015-10-19 16:59:07 -0700428 mSharedPrefs = Utilities.getPrefs(this);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700429 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800430 mModel = app.setLauncher(this);
431 mIconCache = app.getIconCache();
Sunny Goyalae502842016-06-17 08:43:56 -0700432 mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);
Adam Cohen2e6da152015-05-06 11:42:25 -0700433
Joe Onorato41a12d22009-10-31 18:30:00 -0400434 mDragController = new DragController(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -0700435 mAllAppsController = new AllAppsTransitionController(this);
436 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, mAllAppsController);
Romain Guycbb89e42009-06-08 15:52:54 -0700437
Sunny Goyalffe83f12014-08-14 17:39:34 -0700438 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700439
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700440 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
441 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700442
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700443 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
444 // this also ensures that any synchronous binding below doesn't re-trigger another
445 // LauncherModel load.
446 mPaused = false;
447
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 setupViews();
Winson1f064272016-07-18 17:18:02 -0700451 mDeviceProfile.layout(this, false /* notifyListeners */);
Tony Wickham827cef22016-03-17 15:39:39 -0700452 mExtractedColors = new ExtractedColors();
453 loadExtractedColorsAndColorItems();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454
Tony Wickhame2217252016-03-22 16:34:23 -0700455 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
456 .addAccessibilityStateChangeListener(this);
457
Joe Onorato7c312c12009-08-13 21:36:53 -0700458 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 mSavedState = savedInstanceState;
461 restoreState(mSavedState);
462
Sunny Goyale26d1002016-06-20 14:52:14 -0700463 if (LauncherAppState.PROFILE_STARTUP) {
464 Trace.endSection();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 }
466
467 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700468 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 // If the user leaves launcher, then we should just load items asynchronously when
470 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700471 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700472 } else {
473 // We only load the page synchronously if the user rotates (or triggers a
474 // configuration change) while launcher is in the foreground
Sunny Goyalb5b9ad62016-04-02 11:23:39 -0700475 if (!mModel.startLoader(mWorkspace.getRestorePage())) {
476 // If we are not binding synchronously, show a fade in animation when
477 // the first page bind completes.
478 mDragLayer.setAlpha(0);
479 }
Winson Chung4a2afa32012-07-19 14:53:05 -0700480 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800481 }
482
483 // For handling default keys
484 mDefaultKeySsb = new SpannableStringBuilder();
485 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800486
487 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
Sunny Goyalda4fe1a2016-05-26 16:05:17 -0700488 filter.addAction(ACTION_APPWIDGET_HOST_RESET);
489 registerReceiver(mUiBroadcastReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800490
Sunny Goyal8f3819b2016-02-23 14:49:22 -0800491 mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700492 // In case we are on a device with locked rotation, we should look at preferences to check
493 // if the user has specifically allowed rotation.
494 if (!mRotationEnabled) {
Sunny Goyal21bf5312015-08-21 11:08:24 -0700495 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
Sunny Goyal745bad92016-05-02 10:54:12 -0700496 mRotationPrefChangeHandler = new RotationPrefChangeHandler();
497 mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700498 }
499
500 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
501 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400502 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700503
Adam Cohen9211d422014-10-07 18:14:53 -0700504 if (mLauncherCallbacks != null) {
505 mLauncherCallbacks.onCreate(savedInstanceState);
506 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700507
508 if (shouldShowIntroScreen()) {
509 showIntroScreen();
510 } else {
511 showFirstRunActivity();
Adam Cohenc3e12c72014-10-31 16:15:36 -0700512 }
Adam Cohen9211d422014-10-07 18:14:53 -0700513 }
514
Sunny Goyal7779d622015-06-11 16:18:39 -0700515 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700516 public void onExtractedColorsChanged() {
517 loadExtractedColorsAndColorItems();
518 }
519
520 private void loadExtractedColorsAndColorItems() {
Tony Wickham462b5cc2016-04-01 16:00:49 -0700521 // TODO: do this in pre-N as well, once the extraction part is complete.
522 if (mExtractedColors != null && Utilities.isNycOrAbove()) {
Tony Wickham827cef22016-03-17 15:39:39 -0700523 mExtractedColors.load(this);
Tony Wickham462b5cc2016-04-01 16:00:49 -0700524 mHotseat.updateColor(mExtractedColors, !mPaused);
Sunny Goyald0a6ae72016-06-16 12:29:03 -0700525 mWorkspace.getPageIndicator().updateColor(mExtractedColors);
Tony Wickham827cef22016-03-17 15:39:39 -0700526 }
527 }
528
Adam Cohen9211d422014-10-07 18:14:53 -0700529 private LauncherCallbacks mLauncherCallbacks;
530
531 public void onPostCreate(Bundle savedInstanceState) {
532 super.onPostCreate(savedInstanceState);
533 if (mLauncherCallbacks != null) {
534 mLauncherCallbacks.onPostCreate(savedInstanceState);
535 }
536 }
537
Winson1f064272016-07-18 17:18:02 -0700538 public void onInsetsChanged(Rect insets) {
539 mDeviceProfile.updateInsets(insets);
540 mDeviceProfile.layout(this, true /* notifyListeners */);
541 }
542
Sunny Goyal32554d12015-12-03 15:31:25 -0800543 /**
544 * Call this after onCreate to set or clear overlay.
545 */
546 public void setLauncherOverlay(LauncherOverlay overlay) {
547 if (overlay != null) {
548 overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl());
549 }
550 mWorkspace.setLauncherOverlay(overlay);
551 }
552
Adam Cohen9211d422014-10-07 18:14:53 -0700553 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
554 mLauncherCallbacks = callbacks;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700555 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700556 private boolean mWorkspaceImportanceStored = false;
557 private boolean mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700558 private int mWorkspaceImportanceForAccessibility =
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800559 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700560 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
561
562 @Override
563 public void onSearchOverlayOpened() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700564 if (mWorkspaceImportanceStored || mHotseatImportanceStored) {
Jun Mukai8af0cd82015-05-12 12:32:12 -0700565 return;
566 }
567 // The underlying workspace and hotseat are temporarily suppressed by the search
Sunny Goyal08442b82015-10-21 17:15:08 -0700568 // overlay. So they shouldn't be accessible.
Jun Mukaie9819e62015-06-17 10:58:59 -0700569 if (mWorkspace != null) {
570 mWorkspaceImportanceForAccessibility =
571 mWorkspace.getImportantForAccessibility();
572 mWorkspace.setImportantForAccessibility(
573 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
574 mWorkspaceImportanceStored = true;
575 }
576 if (mHotseat != null) {
577 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
578 mHotseat.setImportantForAccessibility(
579 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
580 mHotseatImportanceStored = true;
581 }
Jun Mukai8af0cd82015-05-12 12:32:12 -0700582 }
583
584 @Override
585 public void onSearchOverlayClosed() {
Jun Mukaie9819e62015-06-17 10:58:59 -0700586 if (mWorkspaceImportanceStored && mWorkspace != null) {
587 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
588 }
589 if (mHotseatImportanceStored && mHotseat != null) {
590 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
591 }
592 mWorkspaceImportanceStored = false;
593 mHotseatImportanceStored = false;
Jun Mukai8af0cd82015-05-12 12:32:12 -0700594 }
595 });
Adam Cohen9211d422014-10-07 18:14:53 -0700596 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700597 }
598
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700599 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700600 public void onLauncherProviderChange() {
601 if (mLauncherCallbacks != null) {
602 mLauncherCallbacks.onLauncherProviderChange();
603 }
604 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700605
Adam Cohen9211d422014-10-07 18:14:53 -0700606 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700607 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700608 if (mLauncherCallbacks != null) {
609 return mLauncherCallbacks.hasCustomContentToLeft();
610 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700611 return false;
612 }
613
Dave Hawkeya8881582013-09-17 15:55:33 -0600614 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500615 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600616 * {@link #addToCustomContentPage}. This will only be invoked if
617 * {@link #hasCustomContentToLeft()} is {@code true}.
618 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500619 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700620 if (mLauncherCallbacks != null) {
621 mLauncherCallbacks.populateCustomContentContainer();
622 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600623 }
624
625 /**
626 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
627 * ensure the custom content page is added or removed if necessary.
628 */
629 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600630 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600631 // Not bound yet, wait for bindScreens to be called.
632 return;
633 }
634
635 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
636 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500637 mWorkspace.createCustomContentContainer();
638 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600639 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
640 mWorkspace.removeCustomContentPage();
641 }
642 }
643
Hyunyoung Songaa953652016-04-19 18:30:24 -0700644 public UserEventDispatcher getUserEventDispatcher() {
645 if (mLauncherCallbacks != null) {
646 UserEventDispatcher dispatcher = mLauncherCallbacks.getUserEventDispatcher();
647 if (dispatcher != null) {
648 return dispatcher;
649 }
650 }
651
Sunny Goyal64976d52016-06-20 14:56:28 -0700652 // Logger object is a singleton and does not have to be coupled with the foreground
653 // activity. Since most user event logging is done on the UI, the object is retrieved
654 // from the callback for convenience.
Hyunyoung Songaa953652016-04-19 18:30:24 -0700655 if (mUserEventDispatcher == null) {
Sunny Goyal64976d52016-06-20 14:56:28 -0700656 mUserEventDispatcher = new UserEventDispatcher();
Hyunyoung Songaa953652016-04-19 18:30:24 -0700657 }
658 return mUserEventDispatcher;
Hyunyoung Song8fd5e932016-03-08 16:55:47 -0800659 }
Anton Hanssona2f665f2013-09-26 12:18:32 +0100660
Hyunyoung Song3f471442015-04-08 19:01:34 -0700661 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700662 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
663 // that is subsequently removed from the workspace in startBinding().
Sunny Goyal639e9062015-08-19 19:17:06 -0700664 return !isWorkspaceLoading();
Winson Chung36a62fe2012-05-06 18:04:42 -0700665 }
666
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000667 public int getViewIdForItem(ItemInfo info) {
Sunny Goyale2fd14b2015-08-27 17:45:46 -0700668 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
669 // This cast is safe as long as the id < 0x00FFFFFF
670 // Since we jail all the dynamically generated views, there should be no clashes
671 // with any other views.
672 return (int) info.id;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000673 }
674
675 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700676 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
677 * a configuration step, this allows the proper animations to run after other transitions.
678 */
Adam Cohendb364c32014-05-20 14:23:40 -0700679 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700680 long screenId = args.screenId;
681 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
682 // When the screen id represents an actual screen (as opposed to a rank) we make sure
683 // that the drop page actually exists.
684 screenId = ensurePendingDropLayoutExists(args.screenId);
685 }
Adam Cohendb364c32014-05-20 14:23:40 -0700686
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800687 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800688 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700689 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700690 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700691 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800692 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700693 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700694 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700695 case REQUEST_RECONFIGURE_APPWIDGET:
Sunny Goyald478c832016-04-01 12:04:16 -0700696 completeRestoreAppWidget(args.appWidgetId, LauncherAppWidgetInfo.RESTORE_COMPLETED);
Sunny Goyalff572272014-07-23 13:58:07 -0700697 break;
Sunny Goyald478c832016-04-01 12:04:16 -0700698 case REQUEST_BIND_PENDING_APPWIDGET: {
699 int widgetId = args.appWidgetId;
700 LauncherAppWidgetInfo info =
701 completeRestoreAppWidget(widgetId, LauncherAppWidgetInfo.FLAG_UI_NOT_READY);
702 if (info != null) {
703 // Since the view was just bound, also launch the configure activity if needed
704 LauncherAppWidgetProviderInfo provider = mAppWidgetManager
705 .getLauncherAppWidgetInfo(widgetId);
706 if (provider != null && provider.configure != null) {
707 startRestoredWidgetReconfigActivity(provider, info);
708 }
709 }
710 break;
711 }
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800712 }
Michael Jurka27614d22012-04-02 06:40:22 -0700713 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
714 // if you turned the screen off and then back while in All Apps, Launcher would not
715 // return to the workspace. Clearing mAddInfo.container here fixes this issue
716 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700717 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800718 }
719
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800720 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700721 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700722 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700723 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700724 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800725 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700726
Adam Cohenad4e15c2013-10-17 16:21:35 -0700727 Runnable exitSpringLoaded = new Runnable() {
728 @Override
729 public void run() {
730 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
731 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
732 }
733 };
734
Michael Jurka8b805b12012-04-18 14:23:14 -0700735 if (requestCode == REQUEST_BIND_APPWIDGET) {
Winsona1f79d32015-08-05 14:00:45 -0700736 // This is called only if the user did not previously have permissions to bind widgets
Adam Cohenad4e15c2013-10-17 16:21:35 -0700737 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700738 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
739 if (resultCode == RESULT_CANCELED) {
740 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700741 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700742 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700743 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800744 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700745 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700746 }
747 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200748 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
749 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Tony Wickhame3054412015-09-09 09:05:25 -0700750 // User could have free-scrolled between pages before picking a wallpaper; make sure
751 // we move to the closest one now.
752 mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
Winson Chungdc61c4d2015-04-20 18:26:57 -0700753 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200754 }
755 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700756 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200757
Adam Cohened66b2b2012-01-23 17:28:51 -0800758 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700759 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700760
Adam Cohendb364c32014-05-20 14:23:40 -0700761 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800762 // We have special handling for widgets
763 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800764 final int appWidgetId;
765 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
766 : -1;
767 if (widgetId < 0) {
768 appWidgetId = pendingAddWidgetId;
769 } else {
770 appWidgetId = widgetId;
771 }
772
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800774 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700775 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
776 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700777 result = RESULT_CANCELED;
778 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700779 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 @Override
781 public void run() {
782 exitSpringLoadedDragModeDelayed(false, 0, null);
783 }
784 };
Adam Cohendb364c32014-05-20 14:23:40 -0700785 if (workspaceLocked) {
786 // No need to remove the empty screen if we're mid-binding, as the
787 // the bind will not add the empty screen.
788 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
789 } else {
790 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
791 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
792 }
Winson Chung5aaab772012-04-27 15:24:02 -0700793 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700794 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700795 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
796 // When the screen id represents an actual screen (as opposed to a rank)
797 // we make sure that the drop page actually exists.
798 mPendingAddInfo.screenId =
799 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
800 }
Adam Cohendb364c32014-05-20 14:23:40 -0700801 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
802
803 dropLayout.setDropPending(true);
804 final Runnable onComplete = new Runnable() {
805 @Override
806 public void run() {
807 completeTwoStageWidgetDrop(resultCode, appWidgetId);
808 dropLayout.setDropPending(false);
809 }
810 };
811 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
812 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
813 } else {
814 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
815 mPendingAddInfo);
816 sPendingAddItem = args;
817 }
Winson Chung5aaab772012-04-27 15:24:02 -0700818 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800819 return;
820 }
821
Sunny Goyald478c832016-04-01 12:04:16 -0700822 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET
823 || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
Sunny Goyalff572272014-07-23 13:58:07 -0700824 if (resultCode == RESULT_OK) {
825 // Update the widget view.
826 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
827 pendingAddWidgetId, mPendingAddInfo);
828 if (workspaceLocked) {
829 sPendingAddItem = args;
830 } else {
831 completeAdd(args);
832 }
833 }
834 // Leave the widget in the pending state if the user canceled the configure.
835 return;
836 }
837
Sunny Goyalaad90582015-07-09 14:22:50 -0700838 if (requestCode == REQUEST_CREATE_SHORTCUT) {
839 // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
840 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
841 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
842 mPendingAddInfo);
843 if (isWorkspaceLocked()) {
844 sPendingAddItem = args;
845 } else {
846 completeAdd(args);
847 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
848 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
849 }
850 } else if (resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700851 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
852 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800855 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800856
857 }
858
859 @Override
860 protected void onActivityResult(
861 final int requestCode, final int resultCode, final Intent data) {
862 handleActivityResult(requestCode, resultCode, data);
863 if (mLauncherCallbacks != null) {
864 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
865 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800866 }
867
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600868 /** @Override for MNC */
Sunny Goyaldd2e6df2015-07-07 10:57:57 -0700869 public void onRequestPermissionsResult(int requestCode, String[] permissions,
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600870 int[] grantResults) {
Sunny Goyal28c6b962015-10-12 11:42:05 -0700871 if (requestCode == REQUEST_PERMISSION_CALL_PHONE && sPendingAddItem != null
872 && sPendingAddItem.requestCode == REQUEST_PERMISSION_CALL_PHONE) {
873 View v = null;
874 CellLayout layout = getCellLayout(sPendingAddItem.container, sPendingAddItem.screenId);
875 if (layout != null) {
876 v = layout.getChildAt(sPendingAddItem.cellX, sPendingAddItem.cellY);
877 }
878 Intent intent = sPendingAddItem.intent;
879 sPendingAddItem = null;
880 if (grantResults.length > 0
881 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Sunny Goyal85fc55a2016-05-31 10:44:03 -0700882 startActivitySafely(v, intent, null);
Sunny Goyal28c6b962015-10-12 11:42:05 -0700883 } else {
884 // TODO: Show a snack bar with link to settings
885 Toast.makeText(this, getString(R.string.msg_no_phone_permission,
886 getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
887 }
888 }
Dave Hawkey3a43ed62015-06-26 10:27:47 -0600889 if (mLauncherCallbacks != null) {
890 mLauncherCallbacks.onRequestPermissionsResult(requestCode, permissions,
891 grantResults);
892 }
893 }
894
Adam Cohendb364c32014-05-20 14:23:40 -0700895 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
896 appWidgetId, ItemInfo info) {
897 PendingAddArguments args = new PendingAddArguments();
898 args.requestCode = requestCode;
899 args.intent = data;
900 args.container = info.container;
901 args.screenId = info.screenId;
902 args.cellX = info.cellX;
903 args.cellY = info.cellY;
904 args.appWidgetId = appWidgetId;
905 return args;
906 }
907
908 /**
909 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
910 *
911 * @param screenId the screen id to check
912 * @return the new screen, or screenId if it exists
913 */
914 private long ensurePendingDropLayoutExists(long screenId) {
Sunny Goyal32554d12015-12-03 15:31:25 -0800915 CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
Adam Cohendb364c32014-05-20 14:23:40 -0700916 if (dropLayout == null) {
917 // it's possible that the add screen was removed because it was
918 // empty and a re-bind occurred
919 mWorkspace.addExtraEmptyScreen();
920 return mWorkspace.commitExtraEmptyScreen();
921 } else {
922 return screenId;
923 }
924 }
925
Adam Cohen091440a2015-03-18 14:16:05 -0700926 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Tony Wickhama501d492015-11-03 18:05:01 -0800927 CellLayout cellLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800928 Runnable onCompleteRunnable = null;
929 int animationType = 0;
930
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700931 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800932 if (resultCode == RESULT_OK) {
933 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
934 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700935 mPendingAddWidgetInfo);
936 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 onCompleteRunnable = new Runnable() {
938 @Override
939 public void run() {
940 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700941 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700942 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
943 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800944 }
945 };
946 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800947 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800948 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800949 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700950 if (mDragLayer.getAnimatedView() != null) {
951 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
952 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
953 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700954 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700955 // The animated view may be null in the case of a rotation during widget configuration
956 onCompleteRunnable.run();
957 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800958 }
959
960 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700961 protected void onStop() {
962 super.onStop();
963 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700964
965 if (mLauncherCallbacks != null) {
966 mLauncherCallbacks.onStop();
967 }
Sunny Goyal5da78f42016-06-17 14:00:22 -0700968
969 if (Utilities.isNycMR1OrAbove()) {
970 mAppWidgetHost.stopListening();
971 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700972 }
973
974 @Override
975 protected void onStart() {
976 super.onStart();
977 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700978
979 if (mLauncherCallbacks != null) {
980 mLauncherCallbacks.onStart();
981 }
Sunny Goyal5da78f42016-06-17 14:00:22 -0700982
983 if (Utilities.isNycMR1OrAbove()) {
984 mAppWidgetHost.startListening();
985 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700986 }
987
988 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200990 long startTime = 0;
991 if (DEBUG_RESUME_TIME) {
992 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400993 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200994 }
Adam Cohen9211d422014-10-07 18:14:53 -0700995
996 if (mLauncherCallbacks != null) {
997 mLauncherCallbacks.preOnResume();
998 }
999
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001000 super.onResume();
Hyunyoung Songaa953652016-04-19 18:30:24 -07001001 getUserEventDispatcher().resetElapsedSessionMillis();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001002
Winson Chung4a2afa32012-07-19 14:53:05 -07001003 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001004 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001005 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001006 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001007 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001008 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001009 // view after launching an app, as they may be depending on the UI to be static to
1010 // switch to another app, otherwise, if it was
Hyunyoung Songdd60ce42016-07-27 17:08:38 -07001011 showAppsView(false /* animated */, !launchedFromApp /* updatePredictedApps */,
1012 false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08001013 } else if (mOnResumeState == State.WIDGETS) {
1014 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001015 }
1016 mOnResumeState = State.NONE;
1017
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001018 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -07001019 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
1020 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001021
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001022 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001023 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001024 setWorkspaceLoading(true);
Sunny Goyal93f878c2016-03-30 17:31:24 -07001025 mModel.startLoader(getCurrentWorkspaceScreen());
Joe Onorato9c1289c2009-08-17 11:03:03 -04001026 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001027 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001029 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001030 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1031 // execute them here
1032 long startTimeCallbacks = 0;
1033 if (DEBUG_RESUME_TIME) {
1034 startTimeCallbacks = System.currentTimeMillis();
1035 }
1036
Michael Jurka1e2f4652013-07-08 18:03:46 -07001037 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1038 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001039 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001040 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001041 if (DEBUG_RESUME_TIME) {
1042 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1043 (System.currentTimeMillis() - startTimeCallbacks));
1044 }
Michael Jurka447bf842013-05-15 14:52:15 +02001045 }
Michael Jurka54554252013-08-01 12:52:23 +02001046 if (mOnResumeCallbacks.size() > 0) {
1047 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1048 mOnResumeCallbacks.get(i).run();
1049 }
1050 mOnResumeCallbacks.clear();
1051 }
Winson Chunge4e50662012-01-23 14:45:13 -08001052
1053 // Reset the pressed state of icons that were locked in the press state while activities
1054 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001055 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001056 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001057 mWaitingForResume.setStayPressed(false);
1058 }
Winson Chung82963d52013-10-09 11:20:57 -07001059
Adam Cohen06dff352012-06-01 17:17:08 -07001060 // It is possible that widgets can receive updates while launcher is not in the foreground.
1061 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1062 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1063 // orientation.
Sunny Goyal6bec75f2015-10-01 18:50:48 -07001064 if (!isWorkspaceLoading()) {
1065 getWorkspace().reinflateWidgetsIfNecessary();
1066 }
Adam Cohenf9426d52012-06-04 17:26:21 -07001067
Michael Jurka447bf842013-05-15 14:52:15 +02001068 if (DEBUG_RESUME_TIME) {
1069 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1070 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001071
Adam Cohen4b66bf32015-09-18 12:15:19 -07001072 // We want to suppress callbacks about CustomContent being shown if we have just received
1073 // onNewIntent while the user was present within launcher. In that case, we post a call
1074 // to move the user to the main screen (which will occur after onResume). We don't want to
1075 // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
1076 // suppress here.
1077 if (mWorkspace.getCustomContentCallbacks() != null
1078 && !mMoveToDefaultScreenFromNewIntent) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001079 // If we are resuming and the custom content is the current page, we call onShow().
Adam Cohen4b66bf32015-09-18 12:15:19 -07001080 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001081 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1082 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001083 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001084 }
1085 }
Adam Cohen4b66bf32015-09-18 12:15:19 -07001086 mMoveToDefaultScreenFromNewIntent = false;
Winson Chungcd99cd32015-04-29 11:03:24 -07001087 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001088 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001089
Sunny Goyal756adbc2015-04-16 15:20:51 -07001090 if (!isWorkspaceLoading()) {
1091 // Process any items that were added while Launcher was away.
1092 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Sunny Goyal95f3d6b2016-08-10 16:09:29 -07001093
1094 // Refresh shortcuts if the permission changed.
1095 mModel.refreshShortcutsIfRequired();
Sunny Goyal756adbc2015-04-16 15:20:51 -07001096 }
Adam Cohen9211d422014-10-07 18:14:53 -07001097
Hyunyoung Songc001cf52016-07-21 17:32:43 -07001098 if (shouldShowDiscoveryBounce()) {
1099 mAllAppsController.showDiscoveryBounce();
1100 }
1101 mIsResumeFromActionScreenOff = false;
Adam Cohen9211d422014-10-07 18:14:53 -07001102 if (mLauncherCallbacks != null) {
1103 mLauncherCallbacks.onResume();
1104 }
Adam Cohen06dff352012-06-01 17:17:08 -07001105 }
1106
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001108 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001109 // Ensure that items added to Launcher are queued until Launcher returns
1110 InstallShortcutReceiver.enableInstallQueue();
1111
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001112 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001113 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001114 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001115 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001116
1117 // We call onHide() aggressively. The custom content callbacks should be able to
1118 // debounce excess onHide calls.
1119 if (mWorkspace.getCustomContentCallbacks() != null) {
1120 mWorkspace.getCustomContentCallbacks().onHide();
1121 }
Romain Guycbb89e42009-06-08 15:52:54 -07001122
Adam Cohen9211d422014-10-07 18:14:53 -07001123 if (mLauncherCallbacks != null) {
1124 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001125 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001126 }
1127
1128 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001129 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1130 // by a onResume or by scrolling otherwise.
1131 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001132
1133 // Custom content is completely hidden
1134 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001135
1136 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1137 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001138
1139 // Indicates whether the user is allowed to scroll away from the custom content.
1140 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001141 }
1142
Adam Cohenc2d6e892014-10-16 09:49:24 -07001143 public interface LauncherOverlay {
1144
1145 /**
1146 * Touch interaction leading to overscroll has begun
1147 */
1148 public void onScrollInteractionBegin();
1149
1150 /**
1151 * Touch interaction related to overscroll has ended
1152 */
1153 public void onScrollInteractionEnd();
1154
1155 /**
1156 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1157 * screen (or in the case of RTL, the rightmost screen).
1158 */
Sunny Goyalc86df472016-02-25 09:19:38 -08001159 public void onScrollChange(float progress, boolean rtl);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001160
1161 /**
Sunny Goyal32554d12015-12-03 15:31:25 -08001162 * Called when the launcher is ready to use the overlay
1163 * @param callbacks A set of callbacks provided by Launcher in relation to the overlay
Adam Cohenc2d6e892014-10-16 09:49:24 -07001164 */
Sunny Goyal32554d12015-12-03 15:31:25 -08001165 public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001166 }
1167
Jun Mukai8af0cd82015-05-12 12:32:12 -07001168 public interface LauncherSearchCallbacks {
1169 /**
1170 * Called when the search overlay is shown.
1171 */
1172 public void onSearchOverlayOpened();
1173
1174 /**
1175 * Called when the search overlay is dismissed.
1176 */
1177 public void onSearchOverlayClosed();
1178 }
1179
Adam Cohenc2d6e892014-10-16 09:49:24 -07001180 public interface LauncherOverlayCallbacks {
Sunny Goyalc86df472016-02-25 09:19:38 -08001181 public void onScrollChanged(float progress);
Adam Cohenc2d6e892014-10-16 09:49:24 -07001182 }
1183
1184 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1185
Sunny Goyalc86df472016-02-25 09:19:38 -08001186 public void onScrollChanged(float progress) {
1187 if (mWorkspace != null) {
1188 mWorkspace.onOverlayScrollChanged(progress);
1189 }
1190 }
Adam Cohenc2d6e892014-10-16 09:49:24 -07001191 }
1192
Jorim Jaggid017f882014-01-14 17:08:48 -08001193 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001194 if (mLauncherCallbacks != null) {
1195 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001196 } else {
1197 // On devices with a locked orientation, we will at least have the allow rotation
1198 // setting.
Sunny Goyal8f3819b2016-02-23 14:49:22 -08001199 return !getResources().getBoolean(R.bool.allow_rotation);
Adam Cohen9211d422014-10-07 18:14:53 -07001200 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001201 }
1202
Adam Cohen9211d422014-10-07 18:14:53 -07001203 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001204 CustomContentCallbacks callbacks, String description) {
1205 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001206 }
1207
Adam Cohenedb40762013-07-18 16:45:45 -07001208 // The custom content needs to offset its content to account for the QSB
1209 public int getTopOffsetForCustomContent() {
1210 return mWorkspace.getPaddingTop();
1211 }
1212
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001213 @Override
1214 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001215 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001216 if (mModel.isCurrentCallbacks(this)) {
1217 mModel.stopLoader();
1218 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001219 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1220
Romain Guy13c2e7b2010-03-10 19:45:00 -08001221 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001222 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001223
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001224 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001225 @Override
1226 public void onWindowFocusChanged(boolean hasFocus) {
1227 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001228 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001229
1230 if (mLauncherCallbacks != null) {
1231 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1232 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001233 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001234
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 private boolean acceptFilter() {
1236 final InputMethodManager inputManager = (InputMethodManager)
1237 getSystemService(Context.INPUT_METHOD_SERVICE);
1238 return !inputManager.isFullscreenMode();
1239 }
1240
1241 @Override
1242 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001243 final int uniChar = event.getUnicodeChar();
1244 final boolean handled = super.onKeyDown(keyCode, event);
1245 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1246 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001247 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1248 keyCode, event);
1249 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001250 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001251 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001252 // showSearchDialog()
1253 // If there are multiple keystrokes before the search dialog takes focus,
1254 // onSearchRequested() will be called for every keystroke,
1255 // but it is idempotent, so it's fine.
1256 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 }
1258 }
1259
Joe Onorato8a9625e2010-01-28 15:55:35 -08001260 // Eat the long press event so the keyboard doesn't come up.
1261 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1262 return true;
1263 }
1264
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 return handled;
1266 }
1267
Winson46163472015-09-22 17:31:56 -07001268 @Override
1269 public boolean onKeyUp(int keyCode, KeyEvent event) {
1270 if (keyCode == KeyEvent.KEYCODE_MENU) {
1271 // Ignore the menu key if we are currently dragging or are on the custom content screen
1272 if (!isOnCustomContent() && !mDragController.isDragging()) {
1273 // Close any open folders
1274 closeFolder();
1275
Tony Wickham49c8d292016-07-01 11:44:34 -07001276 // Close any shortcuts containers
1277 closeShortcutsContainer();
1278
Winson46163472015-09-22 17:31:56 -07001279 // Stop resizing any widgets
1280 mWorkspace.exitWidgetResizeMode();
1281
1282 // Show the overview mode if we are on the workspace
1283 if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
1284 !mWorkspace.isSwitchingState()) {
1285 mOverviewPanel.requestFocus();
Winsone9f27272015-10-13 10:47:51 -07001286 showOverviewMode(true, true /* requestButtonFocus */);
Winson46163472015-09-22 17:31:56 -07001287 }
1288 }
1289 return true;
1290 }
1291 return super.onKeyUp(keyCode, event);
1292 }
1293
Karl Rosaen138a0412009-04-23 19:00:21 -07001294 private String getTypedText() {
1295 return mDefaultKeySsb.toString();
1296 }
1297
1298 private void clearTypedText() {
1299 mDefaultKeySsb.clear();
1300 mDefaultKeySsb.clearSpans();
1301 Selection.setSelection(mDefaultKeySsb, 0);
1302 }
1303
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001304 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001305 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1306 * State
1307 */
1308 private static State intToState(int stateOrdinal) {
1309 State state = State.WORKSPACE;
1310 final State[] stateValues = State.values();
1311 for (int i = 0; i < stateValues.length; i++) {
1312 if (stateValues[i].ordinal() == stateOrdinal) {
1313 state = stateValues[i];
1314 break;
1315 }
1316 }
1317 return state;
1318 }
1319
1320 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 * Restores the previous state, if it exists.
1322 *
1323 * @param savedState The previous state.
1324 */
1325 private void restoreState(Bundle savedState) {
1326 if (savedState == null) {
1327 return;
1328 }
1329
Michael Jurka883f55b2010-10-21 15:47:14 -07001330 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001331 if (state == State.APPS || state == State.WIDGETS) {
1332 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001333 }
1334
Adam Cohen21cd0022013-10-09 18:57:02 -07001335 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1336 PagedView.INVALID_RESTORE_PAGE);
1337 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001338 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 }
1340
Sunny Goyal756cd262015-08-20 12:33:21 -07001341 ContentValues itemValues = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_ITEM);
1342 if (itemValues != null) {
1343 mPendingAddInfo.readFromValues(itemValues);
Adam Cohenb823ae42015-03-27 18:07:52 -07001344 AppWidgetProviderInfo info = savedState.getParcelable(
1345 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001346 mPendingAddWidgetInfo = info == null ?
1347 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1348
Adam Cohen4637b5a2013-11-04 18:21:24 -08001349 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001350 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 mRestoring = true;
1352 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 }
1354
1355 /**
1356 * Finds all the views we need and configure them properly.
1357 */
1358 private void setupViews() {
Craig Mautner360310b2012-10-26 15:13:08 -07001359 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001360 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
Sunny Goyal3333b0c2016-05-09 20:43:21 -07001361 mFocusHandler = mDragLayer.getFocusIndicatorHelper();
Winson Chung4c98d922011-05-31 16:50:48 -07001362 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Sunny Goyal6178f132016-07-11 17:30:03 -07001363 mQsbContainer = mDragLayer.findViewById(mDeviceProfile.isVerticalBarLayout()
1364 ? R.id.workspace_blocked_row : R.id.qsb_container);
Sunny Goyald0a6ae72016-06-16 12:29:03 -07001365 mWorkspace.initParentViews(mDragLayer);
Craig Mautner360310b2012-10-26 15:13:08 -07001366
Sunny Goyal784f9c32016-03-23 16:56:54 -07001367 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1368 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1369 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
Craig Mautner360310b2012-10-26 15:13:08 -07001370 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371
Winson Chung4c98d922011-05-31 16:50:48 -07001372 // Setup the drag layer
Hyunyoung Song645764e2016-06-06 14:19:02 -07001373
1374 mDragLayer.setup(this, mDragController, mAllAppsController);
Winson Chung4c98d922011-05-31 16:50:48 -07001375
Winson Chung3d503fb2011-07-13 17:25:49 -07001376 // Setup the hotseat
1377 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1378 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001379 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001380 }
1381
Winsone9f27272015-10-13 10:47:51 -07001382 // Setup the overview panel
1383 setupOverviewPanel();
Adam Cohenf358a4b2013-07-23 16:47:31 -07001384
Winson Chung4c98d922011-05-31 16:50:48 -07001385 // Setup the workspace
1386 mWorkspace.setHapticFeedbackEnabled(false);
1387 mWorkspace.setOnLongClickListener(this);
Hyunyoung Song645764e2016-06-06 14:19:02 -07001388 mWorkspace.setup(mDragController);
Winsonc7d2e832016-07-28 12:24:55 -07001389 // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
1390 // default state, otherwise we will update to the wrong offsets in RTL
1391 mWorkspace.lockWallpaperToDefaultPage();
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07001392 mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
Hyunyoung Song645764e2016-06-06 14:19:02 -07001393 mDragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001394
Tony Wickham34d2c912015-09-11 09:27:58 -07001395 // Get the search/delete/uninstall bar
Sunny Goyal47328fd2016-05-25 18:56:41 -07001396 mDropTargetBar = (DropTargetBar) mDragLayer.findViewById(R.id.drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001397
Winson Chungef7f8742015-06-04 17:18:17 -07001398 // Setup Apps and Widgets
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001399 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Hyunyoung Song3f471442015-04-08 19:01:34 -07001400 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Sunny Goyalf51084c2016-02-18 00:40:49 +00001401 if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
1402 mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
1403 } else {
1404 mAppsView.setSearchBarController(new DefaultAppSearchController());
1405 }
Craig Mautner360310b2012-10-26 15:13:08 -07001406
Winson Chung3d503fb2011-07-13 17:25:49 -07001407 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Hyunyoung Song645764e2016-06-06 14:19:02 -07001408 mDragController.setDragScoller(mWorkspace);
1409 mDragController.setScrollView(mDragLayer);
1410 mDragController.setMoveTarget(mWorkspace);
1411 mDragController.addDropTarget(mWorkspace);
Sunny Goyal47328fd2016-05-25 18:56:41 -07001412 mDropTargetBar.setup(mDragController);
Daniel Sandler924b9932013-06-12 00:38:25 -04001413
Peter Schiller310a9882016-06-30 13:52:36 -07001414 if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
1415 mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace);
1416 }
Hyunyoung Songa0c56472016-06-20 13:54:42 -07001417
Sunny Goyal322d5562015-06-25 19:35:49 -07001418 if (TestingUtils.MEMORY_DUMP_ENABLED) {
1419 TestingUtils.addWeightWatcher(this);
Daniel Sandler924b9932013-06-12 00:38:25 -04001420 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001421 }
1422
Winsone9f27272015-10-13 10:47:51 -07001423 private void setupOverviewPanel() {
1424 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1425
1426 // Long-clicking buttons in the overview panel does the same thing as clicking them.
1427 OnLongClickListener performClickOnLongClick = new OnLongClickListener() {
1428 @Override
1429 public boolean onLongClick(View v) {
1430 return v.performClick();
1431 }
1432 };
1433
1434 // Bind wallpaper button actions
1435 View wallpaperButton = findViewById(R.id.wallpaper_button);
1436 wallpaperButton.setOnClickListener(new OnClickListener() {
1437 @Override
1438 public void onClick(View view) {
1439 if (!mWorkspace.isSwitchingState()) {
1440 onClickWallpaperPicker(view);
1441 }
1442 }
1443 });
1444 wallpaperButton.setOnLongClickListener(performClickOnLongClick);
1445 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1446
1447 // Bind widget button actions
1448 mWidgetsButton = findViewById(R.id.widget_button);
1449 mWidgetsButton.setOnClickListener(new OnClickListener() {
1450 @Override
1451 public void onClick(View view) {
1452 if (!mWorkspace.isSwitchingState()) {
1453 onClickAddWidgetButton(view);
1454 }
1455 }
1456 });
1457 mWidgetsButton.setOnLongClickListener(performClickOnLongClick);
1458 mWidgetsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1459
1460 // Bind settings actions
1461 View settingsButton = findViewById(R.id.settings_button);
1462 boolean hasSettings = hasSettings();
1463 if (hasSettings) {
1464 settingsButton.setOnClickListener(new OnClickListener() {
1465 @Override
1466 public void onClick(View view) {
1467 if (!mWorkspace.isSwitchingState()) {
1468 onClickSettingsButton(view);
1469 }
1470 }
1471 });
1472 settingsButton.setOnLongClickListener(performClickOnLongClick);
1473 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1474 } else {
1475 settingsButton.setVisibility(View.GONE);
1476 }
1477
1478 mOverviewPanel.setAlpha(0f);
1479 }
1480
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001482 * Sets the all apps button. This method is called from {@link Hotseat}.
Sunny Goyalbb011da2016-06-15 15:42:29 -07001483 * TODO: Get rid of this.
Anjali Koppal5ad44842014-03-10 20:34:39 -07001484 */
1485 public void setAllAppsButton(View allAppsButton) {
1486 mAllAppsButton = allAppsButton;
1487 }
1488
Sunny Goyalbb011da2016-06-15 15:42:29 -07001489 public View getStartViewForAllAppsRevealAnimation() {
Sunny Goyal2e084092016-06-22 14:37:34 -07001490 return FeatureFlags.NO_ALL_APPS_ICON ? mWorkspace.getPageIndicator() : mAllAppsButton;
Anjali Koppal5ad44842014-03-10 20:34:39 -07001491 }
1492
Hyunyoung Song98ff38a2015-07-10 17:50:13 -07001493 public View getWidgetsButton() {
1494 return mWidgetsButton;
1495 }
1496
Anjali Koppal5ad44842014-03-10 20:34:39 -07001497 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 * Creates a view representing a shortcut.
1499 *
1500 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001502 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001503 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 }
1505
1506 /**
1507 * Creates a view representing a shortcut inflated from the specified resource.
1508 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 * @param parent The group the shortcut belongs to.
1510 * @param info The data structure describing the shortcut.
1511 *
1512 * @return A View inflated from layoutResId.
1513 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001514 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001515 BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001516 parent, false);
1517 favorite.applyFromShortcutInfo(info, mIconCache);
1518 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001520 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 return favorite;
1522 }
1523
1524 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 * Add a shortcut to the workspace.
1526 *
1527 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001529 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001530 int cellY) {
1531 int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001532 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001533
Sunny Goyal5c97f512015-05-19 16:03:28 -07001534 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001535 if (info == null) {
1536 return;
1537 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001538 final View view = createShortcut(info);
1539
Sunny Goyal5c97f512015-05-19 16:03:28 -07001540 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001541 // First we check if we already know the exact location where we want to add this item.
1542 if (cellX >= 0 && cellY >= 0) {
1543 cellXY[0] = cellX;
1544 cellXY[1] = cellY;
1545 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001546
1547 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001548 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001549 true, null,null)) {
1550 return;
1551 }
1552 DragObject dragObject = new DragObject();
1553 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001554 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1555 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001556 return;
1557 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08001558 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001559 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001560 }
1561
1562 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001563 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001564 return;
1565 }
1566
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001567 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568
1569 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001570 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001571 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 }
1573 }
1574
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001575 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001576 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001578 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001579 */
Adam Cohen091440a2015-03-18 14:16:05 -07001580 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001581 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1582
1583 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001584 if (appWidgetInfo == null) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08001585 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -08001586 }
Romain Guycbb89e42009-06-08 15:52:54 -07001587
Adam Cohen59400422014-03-05 18:07:04 -08001588 if (appWidgetInfo.isCustomWidget) {
1589 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001590 }
1591
Adam Cohen59400422014-03-05 18:07:04 -08001592 LauncherAppWidgetInfo launcherInfo;
1593 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1594 launcherInfo.spanX = info.spanX;
1595 launcherInfo.spanY = info.spanY;
1596 launcherInfo.minSpanX = info.minSpanX;
1597 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001598 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001599
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001600 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001601 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602
1603 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001604 if (hostView == null) {
1605 // Perform actual inflation because we're live
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001606 hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001607 }
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001608 hostView.setVisibility(View.VISIBLE);
1609 addAppWidgetToWorkspace(hostView, launcherInfo, appWidgetInfo, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001610 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001611 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 }
Romain Guycbb89e42009-06-08 15:52:54 -07001613
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001614 private void addAppWidgetToWorkspace(
1615 AppWidgetHostView hostView, LauncherAppWidgetInfo item,
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001616 LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001617 hostView.setTag(item);
1618 item.onBindAppWidget(this, hostView);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001619
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001620 hostView.setFocusable(true);
1621 hostView.setOnFocusChangeListener(mFocusHandler);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001622
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001623 mWorkspace.addInScreen(hostView, item.container, item.screenId,
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001624 item.cellX, item.cellY, item.spanX, item.spanY, insert);
1625
1626 if (!item.isCustomWidget()) {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07001627 addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
Sunny Goyal25c2e3e2015-10-28 23:28:21 -07001628 }
1629 }
1630
Adam Cohended9f8d2010-11-03 13:25:16 -07001631 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1632 @Override
1633 public void onReceive(Context context, Intent intent) {
1634 final String action = intent.getAction();
1635 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1636 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001637 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001638 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001639
Winson Chungc100e8e2011-08-09 16:02:43 -07001640 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001641 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001642 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001643 mPendingAddInfo.container == ItemInfo.NO_ID) {
Winson5c6bdbb2015-09-03 11:36:19 -07001644 if (!showWorkspace(false)) {
1645 // If we are already on the workspace, then manually reset all apps
1646 mAppsView.reset();
1647 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001648 }
Hyunyoung Songc001cf52016-07-21 17:32:43 -07001649 mIsResumeFromActionScreenOff = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001650 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1651 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001652 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001653 }
1654 }
1655 };
1656
1657 @Override
1658 public void onAttachedToWindow() {
1659 super.onAttachedToWindow();
1660
1661 // Listen for broadcasts related to user-presence
1662 final IntentFilter filter = new IntentFilter();
1663 filter.addAction(Intent.ACTION_SCREEN_OFF);
1664 filter.addAction(Intent.ACTION_USER_PRESENT);
1665 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001666 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001667 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001668 mVisible = true;
Sunny Goyalc86df472016-02-25 09:19:38 -08001669
1670 if (mLauncherCallbacks != null) {
1671 mLauncherCallbacks.onAttachedToWindow();
1672 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001673 }
1674
1675 @Override
1676 public void onDetachedFromWindow() {
1677 super.onDetachedFromWindow();
1678 mVisible = false;
1679
Adam Cohend113e0c2010-11-11 10:48:05 -08001680 if (mAttached) {
1681 unregisterReceiver(mReceiver);
1682 mAttached = false;
1683 }
Winson Chungb745afb2015-03-02 11:51:23 -08001684 updateAutoAdvanceState();
Sunny Goyalc86df472016-02-25 09:19:38 -08001685
1686 if (mLauncherCallbacks != null) {
1687 mLauncherCallbacks.onDetachedFromWindow();
1688 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001689 }
1690
1691 public void onWindowVisibilityChanged(int visibility) {
1692 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001693 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001694 // The following code used to be in onResume, but it turns out onResume is called when
1695 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1696 // is a more appropriate event to handle
1697 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001698 if (!mWorkspaceLoading) {
1699 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001700 // We want to let Launcher draw itself at least once before we force it to build
1701 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001702 // apps is nice and speedy.
1703 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001704 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001705 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001706 if (mStarted) return;
1707 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001708 // We delay the layer building a bit in order to give
1709 // other message processing a time to run. In particular
1710 // this avoids a delay in hiding the IME if it was
1711 // currently shown, because doing that may involve
1712 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001713 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001714 final ViewTreeObserver.OnDrawListener listener = this;
1715 mWorkspace.post(new Runnable() {
Tony Wickhama0628cc2015-10-14 15:23:04 -07001716 public void run() {
1717 if (mWorkspace != null &&
1718 mWorkspace.getViewTreeObserver() != null) {
1719 mWorkspace.getViewTreeObserver().
1720 removeOnDrawListener(listener);
Michael Jurkadf96add2013-04-03 16:25:02 -07001721 }
Tony Wickhama0628cc2015-10-14 15:23:04 -07001722 }
1723 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001724 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001725 }
1726 });
1727 }
1728 clearTypedText();
1729 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001730 }
1731
Adam Cohen091440a2015-03-18 14:16:05 -07001732 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001733 mHandler.removeMessages(ADVANCE_MSG);
1734 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1735 mHandler.sendMessageDelayed(msg, delay);
1736 mAutoAdvanceSentTime = System.currentTimeMillis();
1737 }
1738
Adam Cohen091440a2015-03-18 14:16:05 -07001739 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001740 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1741 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1742 mAutoAdvanceRunning = autoAdvanceRunning;
1743 if (autoAdvanceRunning) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001744 long delay = mAutoAdvanceTimeLeft == -1 ? ADVANCE_INTERVAL : mAutoAdvanceTimeLeft;
Adam Cohended9f8d2010-11-03 13:25:16 -07001745 sendAdvanceMessage(delay);
1746 } else {
1747 if (!mWidgetsToAdvance.isEmpty()) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001748 mAutoAdvanceTimeLeft = Math.max(0, ADVANCE_INTERVAL -
Adam Cohended9f8d2010-11-03 13:25:16 -07001749 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1750 }
1751 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001752 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001753 }
1754 }
1755 }
1756
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001757 @Thunk final Handler mHandler = new Handler(new Handler.Callback() {
1758
Adam Cohended9f8d2010-11-03 13:25:16 -07001759 @Override
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001760 public boolean handleMessage(Message msg) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001761 if (msg.what == ADVANCE_MSG) {
1762 int i = 0;
1763 for (View key: mWidgetsToAdvance.keySet()) {
1764 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
Sunny Goyal756cd262015-08-20 12:33:21 -07001765 final int delay = ADVANCE_STAGGER * i;
Adam Cohended9f8d2010-11-03 13:25:16 -07001766 if (v instanceof Advanceable) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001767 mHandler.postDelayed(new Runnable() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001768 public void run() {
1769 ((Advanceable) v).advance();
1770 }
1771 }, delay);
1772 }
1773 i++;
1774 }
Sunny Goyal756cd262015-08-20 12:33:21 -07001775 sendAdvanceMessage(ADVANCE_INTERVAL);
Adam Cohended9f8d2010-11-03 13:25:16 -07001776 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001777 return true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001778 }
Sunny Goyal4f3e9382015-06-05 00:13:25 -07001779 });
Adam Cohended9f8d2010-11-03 13:25:16 -07001780
Winsonc0b52fe2015-09-09 16:38:15 -07001781 private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001782 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001783 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1784 if (v instanceof Advanceable) {
1785 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001786 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001787 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001788 }
1789 }
1790
Winsonc0b52fe2015-09-09 16:38:15 -07001791 private void removeWidgetToAutoAdvance(View hostView) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001792 if (mWidgetsToAdvance.containsKey(hostView)) {
1793 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001794 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001795 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001796 }
1797
Hyunyoung Song3f471442015-04-08 19:01:34 -07001798 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001799 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1800 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001801 }
1802
Winson Chunga6945242014-01-08 14:04:34 -08001803 public DragLayer getDragLayer() {
1804 return mDragLayer;
1805 }
1806
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001807 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001808 return mAppsView;
1809 }
1810
Hyunyoung Song3f471442015-04-08 19:01:34 -07001811 public WidgetsContainerView getWidgetsView() {
1812 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001813 }
1814
Winson Chunga6945242014-01-08 14:04:34 -08001815 public Workspace getWorkspace() {
1816 return mWorkspace;
1817 }
1818
Sunny Goyal6178f132016-07-11 17:30:03 -07001819 public View getQsbContainer() {
1820 return mQsbContainer;
1821 }
1822
Winson Chunga6945242014-01-08 14:04:34 -08001823 public Hotseat getHotseat() {
1824 return mHotseat;
1825 }
1826
Jorim Jaggid017f882014-01-14 17:08:48 -08001827 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001828 return mOverviewPanel;
1829 }
1830
Sunny Goyal47328fd2016-05-25 18:56:41 -07001831 public DropTargetBar getDropTargetBar() {
1832 return mDropTargetBar;
Tony Wickham34d2c912015-09-11 09:27:58 -07001833 }
1834
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001835 public LauncherAppWidgetHost getAppWidgetHost() {
1836 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 }
Romain Guycbb89e42009-06-08 15:52:54 -07001838
Winson Chunga9abd0e2010-10-27 17:18:37 -07001839 public LauncherModel getModel() {
1840 return mModel;
1841 }
1842
Adam Cohen79d90c52016-04-22 13:29:20 -07001843 public SharedPreferences getSharedPrefs() {
Winson Chunga6945242014-01-08 14:04:34 -08001844 return mSharedPrefs;
1845 }
1846
Adam Cohen2e6da152015-05-06 11:42:25 -07001847 public DeviceProfile getDeviceProfile() {
1848 return mDeviceProfile;
1849 }
1850
Bjorn Bringertc459e522013-06-07 19:36:01 +01001851 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001852 getWindow().closeAllPanels();
1853
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001854 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001855 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001856 }
1857
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001858 @Override
1859 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001860 long startTime = 0;
1861 if (DEBUG_RESUME_TIME) {
1862 startTime = System.currentTimeMillis();
1863 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001864 super.onNewIntent(intent);
1865
1866 // Close the menu
Winson15f8b172015-08-19 11:02:39 -07001867 Folder openFolder = mWorkspace.getOpenFolder();
1868 boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1869 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1870 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1871 boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
1872 if (isActionMain) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001873 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001874 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001875
Adam Cohen6fecd412013-10-02 17:41:50 -07001876 if (mWorkspace == null) {
1877 // Can be cases where mWorkspace is null, this prevents a NPE
1878 return;
1879 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001880 // In all these cases, only animate if we're already on home
1881 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001882
Sunny Goyal935fca12015-10-13 10:19:01 -07001883 closeFolder(alreadyOnHome);
Sunny Goyala2454ad2016-07-22 10:50:11 -07001884 closeShortcutsContainer(alreadyOnHome);
Adam Cohen6fecd412013-10-02 17:41:50 -07001885 exitSpringLoadedDragMode();
1886
1887 // If we are already on home, then just animate back to the workspace,
1888 // otherwise, just wait until onResume to set the state back to Workspace
1889 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001890 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001891 } else {
1892 mOnResumeState = State.WORKSPACE;
1893 }
1894
1895 final View v = getWindow().peekDecorView();
1896 if (v != null && v.getWindowToken() != null) {
Tonyc17390962015-10-25 17:39:37 -07001897 InputMethodManager imm = (InputMethodManager) getSystemService(
Adam Cohen6fecd412013-10-02 17:41:50 -07001898 INPUT_METHOD_SERVICE);
1899 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1900 }
1901
Winson Chungb745afb2015-03-02 11:51:23 -08001902 // Reset the apps view
1903 if (!alreadyOnHome && mAppsView != null) {
1904 mAppsView.scrollToTop();
1905 }
1906
Hyunyoung Song3f471442015-04-08 19:01:34 -07001907 // Reset the widgets view
1908 if (!alreadyOnHome && mWidgetsView != null) {
1909 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001910 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001911
Adam Cohen9211d422014-10-07 18:14:53 -07001912 if (mLauncherCallbacks != null) {
1913 mLauncherCallbacks.onHomeIntent();
1914 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 }
Adam Cohened307df2013-10-02 09:37:31 -07001916
Adam Cohen9211d422014-10-07 18:14:53 -07001917 if (mLauncherCallbacks != null) {
1918 mLauncherCallbacks.onNewIntent(intent);
1919 }
Winson15f8b172015-08-19 11:02:39 -07001920
1921 // Defer moving to the default screen until after we callback to the LauncherCallbacks
1922 // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
1923 // animation.
1924 if (isActionMain) {
Ivan Lee667d6882015-09-03 10:16:07 -06001925 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1926 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Winson15f8b172015-08-19 11:02:39 -07001927 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1928 openFolder == null && moveToDefaultScreen) {
Adam Cohen4b66bf32015-09-18 12:15:19 -07001929
1930 // We use this flag to suppress noisy callbacks above custom content state
1931 // from onResume.
1932 mMoveToDefaultScreenFromNewIntent = true;
Winson15f8b172015-08-19 11:02:39 -07001933 mWorkspace.post(new Runnable() {
1934 @Override
1935 public void run() {
Tonyc17390962015-10-25 17:39:37 -07001936 if (mWorkspace != null) {
1937 mWorkspace.moveToDefaultScreen(true);
1938 }
Winson15f8b172015-08-19 11:02:39 -07001939 }
1940 });
1941 }
1942 }
1943
1944 if (DEBUG_RESUME_TIME) {
1945 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1946 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001947 }
1948
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001950 public void onRestoreInstanceState(Bundle state) {
1951 super.onRestoreInstanceState(state);
1952 for (int page: mSynchronouslyBoundPages) {
1953 mWorkspace.restoreInstanceStateForChild(page);
1954 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001955 }
1956
1957 @Override
1958 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001959 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001960 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1961 mWorkspace.getCurrentPageOffsetFromCustomContent());
Hyunyoung Song645764e2016-06-06 14:19:02 -07001962
Adam Cohen21cd0022013-10-09 18:57:02 -07001963 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001964 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001965
Michael Jurka883f55b2010-10-21 15:47:14 -07001966 outState.putInt(RUNTIME_STATE, mState.ordinal());
Sunny Goyal44d0b532016-03-14 14:08:12 -07001967 // We close any open folder since it will not be re-opened, and we need to make sure
1968 // this state is reflected.
1969 // TODO: Move folderInfo.isOpened out of the model and make it a UI state.
1970 closeFolder(false);
Sunny Goyala2454ad2016-07-22 10:50:11 -07001971 closeShortcutsContainer(false);
Tony Wickham49c8d292016-07-01 11:44:34 -07001972
Adam Cohendcd297f2013-06-18 13:13:40 -07001973 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001974 mWaitingForResult) {
Sunny Goyal756cd262015-08-20 12:33:21 -07001975 ContentValues itemValues = new ContentValues();
1976 mPendingAddInfo.writeToValues(itemValues);
1977 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_ITEM, itemValues);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001978 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001979 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 }
1981
Adam Cohen9211d422014-10-07 18:14:53 -07001982 if (mLauncherCallbacks != null) {
1983 mLauncherCallbacks.onSaveInstanceState(outState);
1984 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001985 }
1986
1987 @Override
1988 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001990
Winson Chunge7a03942011-08-05 15:05:12 -07001991 // Remove all pending runnables
1992 mHandler.removeMessages(ADVANCE_MSG);
1993 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001994 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07001995 mWorkspace.removeFolderListeners();
Winson Chunge7a03942011-08-05 15:05:12 -07001996
Winson Chungcd2b0142011-06-08 16:02:26 -07001997 // Stop callbacks from LauncherModel
Adam Cohen1a85c582014-09-30 09:48:49 -07001998 // It's possible to receive onDestroy after a new Launcher activity has
1999 // been created. In this case, don't interfere with the new Launcher.
2000 if (mModel.isCurrentCallbacks(this)) {
2001 mModel.stopLoader();
Sunny Goyald365ed62016-02-12 09:44:03 -08002002 LauncherAppState.getInstance().setLauncher(null);
Adam Cohen1a85c582014-09-30 09:48:49 -07002003 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002004
Sunny Goyal745bad92016-05-02 10:54:12 -07002005 if (mRotationPrefChangeHandler != null) {
2006 mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
2007 }
2008
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002010 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002012 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002013 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002014 mAppWidgetHost = null;
2015
2016 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017
2018 TextKeyListener.getInstance().release();
2019
Tony Wickhame2217252016-03-22 16:34:23 -07002020 ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
2021 .removeAccessibilityStateChangeListener(this);
2022
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002023 unregisterReceiver(mUiBroadcastReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002024
Michael Jurka2ecf9952012-06-18 12:52:28 -07002025 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002026
2027 if (mLauncherCallbacks != null) {
2028 mLauncherCallbacks.onDestroy();
2029 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 }
2031
Sunny Goyalae502842016-06-17 08:43:56 -07002032 public LauncherAccessibilityDelegate getAccessibilityDelegate() {
2033 return mAccessibilityDelegate;
2034 }
2035
Adam Cohena9cf38f2011-05-02 15:36:58 -07002036 public DragController getDragController() {
2037 return mDragController;
2038 }
2039
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 @Override
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002041 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Adam Cohen173f7112015-03-27 15:14:00 -07002042 onStartForResult(requestCode);
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002043 super.startActivityForResult(intent, requestCode, options);
Adam Cohen173f7112015-03-27 15:14:00 -07002044 }
2045
2046 @Override
2047 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2048 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2049 onStartForResult(requestCode);
2050 try {
2051 super.startIntentSenderForResult(intent, requestCode,
2052 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2053 } catch (IntentSender.SendIntentException e) {
2054 throw new ActivityNotFoundException();
2055 }
2056 }
2057
2058 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002059 if (requestCode >= 0) {
2060 setWaitingForResult(true);
2061 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 }
2063
Winson Chung70d72102011-08-12 11:24:35 -07002064 /**
2065 * Indicates that we want global search for this activity by setting the globalSearch
2066 * argument for {@link #startSearch} to true.
2067 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002069 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002071
Karl Rosaen138a0412009-04-23 19:00:21 -07002072 if (initialQuery == null) {
2073 // Use any text typed in the launcher as the initial query
2074 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002075 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 if (appSearchData == null) {
2077 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002078 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07002080
2081 // TODO send proper bounds.
2082 Rect sourceBounds = null;
Romain Guycbb89e42009-06-08 15:52:54 -07002083
Ian Parkinson047036e2014-09-01 15:40:53 +01002084 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002085 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002086 if (clearTextImmediately) {
2087 clearTypedText();
2088 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002089
2090 // We need to show the workspace after starting the search
2091 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002092 }
2093
Ian Parkinson047036e2014-09-01 15:40:53 +01002094 /**
2095 * Start a text search.
2096 *
2097 * @return {@code true} if the search will start immediately, so any further keypresses
2098 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2099 * to buffer keypresses.
2100 */
2101 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002102 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002103 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2104 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2105 sourceBounds);
2106 }
2107
Michael Jurkaa33411c2012-06-14 16:18:21 -07002108 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002109 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002110 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002111 }
2112
2113 /**
2114 * Starts the global search activity. This code is a copied from SearchManager
2115 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002116 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002117 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002118 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002119 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2120 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2121 if (globalSearchActivity == null) {
2122 Log.w(TAG, "No global search activity found.");
2123 return;
2124 }
2125 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2127 intent.setComponent(globalSearchActivity);
2128 // Make sure that we have a Bundle to put source in
2129 if (appSearchData == null) {
2130 appSearchData = new Bundle();
2131 } else {
2132 appSearchData = new Bundle(appSearchData);
2133 }
Adam Cohen9211d422014-10-07 18:14:53 -07002134 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002135 if (!appSearchData.containsKey("source")) {
2136 appSearchData.putString("source", getPackageName());
2137 }
2138 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2139 if (!TextUtils.isEmpty(initialQuery)) {
2140 intent.putExtra(SearchManager.QUERY, initialQuery);
2141 }
2142 if (selectInitialQuery) {
2143 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2144 }
2145 intent.setSourceBounds(sourceBounds);
2146 try {
2147 startActivity(intent);
2148 } catch (ActivityNotFoundException ex) {
2149 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2150 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002151 }
2152
Yura4f93ec62014-02-04 14:15:21 +00002153 public boolean isOnCustomContent() {
2154 return mWorkspace.isOnOrMovingToCustomContent();
2155 }
2156
Winson Chung70d72102011-08-12 11:24:35 -07002157 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002158 public boolean onPrepareOptionsMenu(Menu menu) {
2159 super.onPrepareOptionsMenu(menu);
Adam Cohen9211d422014-10-07 18:14:53 -07002160 if (mLauncherCallbacks != null) {
2161 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2162 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002163 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002164 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002165
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002166 @Override
2167 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002168 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002169 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002170 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002171 }
2172
Joe Onorato9c1289c2009-08-17 11:03:03 -04002173 public boolean isWorkspaceLocked() {
2174 return mWorkspaceLoading || mWaitingForResult;
2175 }
2176
Adam Cohen517a7f52014-03-01 12:12:59 -08002177 public boolean isWorkspaceLoading() {
2178 return mWorkspaceLoading;
2179 }
2180
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002181 private void setWorkspaceLoading(boolean value) {
2182 boolean isLocked = isWorkspaceLocked();
2183 mWorkspaceLoading = value;
2184 if (isLocked != isWorkspaceLocked()) {
2185 onWorkspaceLockedChanged();
2186 }
2187 }
2188
2189 private void setWaitingForResult(boolean value) {
2190 boolean isLocked = isWorkspaceLocked();
2191 mWaitingForResult = value;
2192 if (isLocked != isWorkspaceLocked()) {
2193 onWorkspaceLockedChanged();
2194 }
2195 }
2196
Adam Cohen9211d422014-10-07 18:14:53 -07002197 protected void onWorkspaceLockedChanged() {
2198 if (mLauncherCallbacks != null) {
2199 mLauncherCallbacks.onWorkspaceLockedChanged();
2200 }
2201 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002202
Michael Jurka0280c3b2010-09-17 15:00:07 -07002203 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002204 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002205 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002206 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2207 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Sunny Goyal233ee962015-08-03 13:05:01 -07002208 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002209 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002210
Tony Wickhama0628cc2015-10-14 15:23:04 -07002211 void addAppWidgetFromDropImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002212 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002213 if (LOGD) {
2214 Log.d(TAG, "Adding widget from drop");
2215 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07002216 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2217 }
2218
Sunny Goyale6b63a32015-01-16 16:14:29 -08002219 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002220 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2221 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002222 if (appWidgetInfo.configure != null) {
2223 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002224 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002225
Bjorn Bringert7984c942009-12-09 15:38:25 +00002226 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002227 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2228 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2229
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002230 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002231 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002232 Runnable onComplete = new Runnable() {
2233 @Override
2234 public void run() {
2235 // Exit spring loaded mode if necessary after adding the widget
2236 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2237 null);
2238 }
2239 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002240 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002241 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002242 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002243 }
2244 }
Romain Guycbb89e42009-06-08 15:52:54 -07002245
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002246 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002247 // Close any folders that may be open.
2248 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002249 mWorkspace.moveToCustomContentScreen(animate);
2250 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002251
2252 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2253 int[] cell, int spanX, int spanY) {
2254 switch (info.itemType) {
2255 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2256 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2257 int span[] = new int[2];
2258 span[0] = spanX;
2259 span[1] = spanY;
2260 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2261 container, screenId, cell, span);
2262 break;
2263 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2264 processShortcutFromDrop(info.componentName, container, screenId, cell);
2265 break;
2266 default:
2267 throw new IllegalStateException("Unknown item type: " + info.itemType);
2268 }
2269 }
2270
Adam Cohenfbba09b2011-07-18 21:43:05 -07002271 /**
2272 * Process a shortcut drop.
2273 *
2274 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002275 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002276 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002277 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002278 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2279 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002280 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002281 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002282 mPendingAddInfo.screenId = screenId;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002283
2284 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002285 mPendingAddInfo.cellX = cell[0];
2286 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002287 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002288
2289 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2290 createShortcutIntent.setComponent(componentName);
Sunny Goyal4f3e9382015-06-05 00:13:25 -07002291 Utilities.startActivityForResultSafely(this, createShortcutIntent, REQUEST_CREATE_SHORTCUT);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002292 }
2293
Adam Cohenfbba09b2011-07-18 21:43:05 -07002294 /**
2295 * Process a widget drop.
2296 *
2297 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002298 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002299 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002300 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002301 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2302 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002303 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002305 mPendingAddInfo.screenId = info.screenId = screenId;
Adam Cohend41fbf52012-02-16 23:53:59 -08002306 mPendingAddInfo.minSpanX = info.minSpanX;
2307 mPendingAddInfo.minSpanY = info.minSpanY;
2308
Adam Cohenfbba09b2011-07-18 21:43:05 -07002309 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 mPendingAddInfo.cellX = cell[0];
2311 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002312 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002313 if (span != null) {
2314 mPendingAddInfo.spanX = span[0];
2315 mPendingAddInfo.spanY = span[1];
2316 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002317
Adam Cohened66b2b2012-01-23 17:28:51 -08002318 AppWidgetHostView hostView = info.boundWidget;
2319 int appWidgetId;
2320 if (hostView != null) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002321 // In the case where we've prebound the widget, we remove it from the DragLayer
2322 if (LOGD) {
2323 Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
2324 }
2325 getDragLayer().removeView(hostView);
2326
Adam Cohened66b2b2012-01-23 17:28:51 -08002327 appWidgetId = hostView.getAppWidgetId();
Tony Wickhama0628cc2015-10-14 15:23:04 -07002328 addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
Sunny Goyal5b9ebca2015-06-01 18:37:32 -07002329
2330 // Clear the boundWidget so that it doesn't get destroyed.
2331 info.boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -08002332 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002333 // In this case, we either need to start an activity to get permission to bind
2334 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002335 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002336 Bundle options = info.bindOptions;
2337
Sunny Goyalffe83f12014-08-14 17:39:34 -07002338 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2339 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002340 if (success) {
Tony Wickhama0628cc2015-10-14 15:23:04 -07002341 addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002342 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002343 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002344 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2345 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2346 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002347 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2348 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002349 // TODO: we need to make sure that this accounts for the options bundle.
2350 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002351 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2352 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002353 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002354 }
2355
Adam Cohendcd297f2013-06-18 13:13:40 -07002356 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002357 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002358 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002359 folderInfo.title = getText(R.string.folder_name);
2360
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002361 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002362 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2363 cellX, cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002364
2365 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002366 FolderIcon newFolder =
2367 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002368 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002369 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002370 // Force measure the new folder icon
2371 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2372 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002373 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 }
Romain Guycbb89e42009-06-08 15:52:54 -07002375
Winsonc0b52fe2015-09-09 16:38:15 -07002376 /**
Winsonfa56b3f2015-09-14 12:01:13 -07002377 * Unbinds the view for the specified item, and removes the item and all its children.
2378 *
2379 * @param v the view being removed.
Winsonfa56b3f2015-09-14 12:01:13 -07002380 * @param itemInfo the {@link ItemInfo} for this view.
2381 * @param deleteFromDb whether or not to delete this item from the db.
Winsonc0b52fe2015-09-09 16:38:15 -07002382 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002383 public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
Winsonc0b52fe2015-09-09 16:38:15 -07002384 if (itemInfo instanceof ShortcutInfo) {
Winsonfa56b3f2015-09-14 12:01:13 -07002385 // Remove the shortcut from the folder before removing it from launcher
Sunny Goyal44c06432016-04-02 10:56:02 -07002386 View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
2387 if (folderIcon instanceof FolderIcon) {
Sunny Goyalc52ba712016-04-05 15:59:05 -07002388 ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo, true);
Winsonfa56b3f2015-09-14 12:01:13 -07002389 } else {
2390 mWorkspace.removeWorkspaceItem(v);
2391 }
Winsonc0b52fe2015-09-09 16:38:15 -07002392 if (deleteFromDb) {
2393 LauncherModel.deleteItemFromDatabase(this, itemInfo);
2394 }
2395 } else if (itemInfo instanceof FolderInfo) {
2396 final FolderInfo folderInfo = (FolderInfo) itemInfo;
Sunny Goyalaaf7d1d2016-05-17 13:38:54 -07002397 if (v instanceof FolderIcon) {
2398 ((FolderIcon) v).removeListeners();
2399 }
Winsonc0b52fe2015-09-09 16:38:15 -07002400 mWorkspace.removeWorkspaceItem(v);
2401 if (deleteFromDb) {
2402 LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
2403 }
2404 } else if (itemInfo instanceof LauncherAppWidgetInfo) {
2405 final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
Winson44818e02015-10-02 11:25:46 -07002406 mWorkspace.removeWorkspaceItem(v);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07002407 removeWidgetToAutoAdvance(v);
Winsonc0b52fe2015-09-09 16:38:15 -07002408 if (deleteFromDb) {
Sunny Goyal56c73602015-09-25 12:55:01 -07002409 deleteWidgetInfo(widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002410 }
2411 } else {
2412 return false;
2413 }
2414 return true;
2415 }
2416
2417 /**
Sunny Goyal56c73602015-09-25 12:55:01 -07002418 * Deletes the widget info and the widget id.
Winsonc0b52fe2015-09-09 16:38:15 -07002419 */
Sunny Goyal56c73602015-09-25 12:55:01 -07002420 private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
Winsonc0b52fe2015-09-09 16:38:15 -07002421 final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
Sunny Goyald478c832016-04-01 12:04:16 -07002422 if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdAllocated()) {
Winsonc0b52fe2015-09-09 16:38:15 -07002423 // Deleting an app widget ID is a void call but writes to disk before returning
2424 // to the caller...
2425 new AsyncTask<Void, Void, Void>() {
2426 public Void doInBackground(Void ... args) {
2427 appWidgetHost.deleteAppWidgetId(widgetInfo.appWidgetId);
2428 return null;
2429 }
Sunny Goyalf27cb0e2015-09-23 16:12:02 -07002430 }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
Winsonc0b52fe2015-09-09 16:38:15 -07002431 }
Sunny Goyal56c73602015-09-25 12:55:01 -07002432 LauncherModel.deleteItemFromDatabase(this, widgetInfo);
Winsonc0b52fe2015-09-09 16:38:15 -07002433 }
2434
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002435 @Override
2436 public boolean dispatchKeyEvent(KeyEvent event) {
2437 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2438 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002439 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002440 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002441 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002442 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002443 dumpState();
2444 return true;
2445 }
2446 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002447 }
2448 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2449 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002450 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002451 return true;
2452 }
2453 }
2454
2455 return super.dispatchKeyEvent(event);
2456 }
2457
Joe Onorato88ec0992009-11-19 13:16:06 -08002458 @Override
2459 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002460 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2461 return;
2462 }
2463
Sunny Goyal45478022015-06-08 16:52:41 -07002464 if (mDragController.isDragging()) {
2465 mDragController.cancelDrag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08002466 return;
2467 }
2468
Tony Wickham49c8d292016-07-01 11:44:34 -07002469 if (getOpenShortcutsContainer() != null) {
2470 closeShortcutsContainer();
2471 } else if (isAppsViewVisible()) {
Winson Chungb745afb2015-03-02 11:51:23 -08002472 showWorkspace(true);
2473 } else if (isWidgetsViewVisible()) {
2474 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002475 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002476 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002477 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002478 Folder openFolder = mWorkspace.getOpenFolder();
2479 if (openFolder.isEditingName()) {
2480 openFolder.dismissEditingName();
2481 } else {
2482 closeFolder();
2483 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002484 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002485 mWorkspace.exitWidgetResizeMode();
2486
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002487 // Back button is a no-op here, but give at least some feedback for the button press
2488 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002489 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002490 }
2491
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002492 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002493 * Launches the intent referred by the clicked shortcut.
2494 *
2495 * @param v The view representing the clicked shortcut.
2496 */
2497 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002498 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2499 // view has detached (it's possible for this to happen if the view is removed mid touch).
2500 if (v.getWindowToken() == null) {
2501 return;
2502 }
2503
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002504 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002505 return;
2506 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002507
Adam Cohen1697b792013-09-17 19:08:21 -07002508 if (v instanceof Workspace) {
2509 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002510 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002511 }
2512 return;
2513 }
2514
2515 if (v instanceof CellLayout) {
2516 if (mWorkspace.isInOverviewMode()) {
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002517 mWorkspace.snapToPageFromOverView(mWorkspace.indexOfChild(v));
2518 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002519 }
Sunny Goyalce5a7e52015-07-08 15:44:27 -07002520 return;
Adam Cohenf358a4b2013-07-23 16:47:31 -07002521 }
2522
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002523 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002524 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002525 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002526 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002527 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002528 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002529 }
Hyunyoung Song68f98ac2016-07-22 14:22:49 -07002530 } else if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator) ||
2531 (v == mAllAppsButton && mAllAppsButton != null)) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002532 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002533 } else if (tag instanceof AppInfo) {
2534 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002535 } else if (tag instanceof LauncherAppWidgetInfo) {
2536 if (v instanceof PendingAppWidgetHostView) {
2537 onClickPendingWidget((PendingAppWidgetHostView) v);
2538 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002539 }
2540 }
2541
Sunny Goyal70660032015-05-14 00:07:08 -07002542 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002543 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002544 return false;
2545 }
2546
Michael Jurkaaf442092010-06-10 17:01:57 -07002547 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002548 * Event handler for the app widget view which has not fully restored.
2549 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002550 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002551 if (mIsSafeModeEnabled) {
2552 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2553 return;
2554 }
2555
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002556 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002557 if (v.isReadyForClickSetup()) {
Sunny Goyald478c832016-04-01 12:04:16 -07002558 if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
2559 if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
2560 // This should not happen, as we make sure that an Id is allocated during bind.
2561 return;
2562 }
2563 LauncherAppWidgetProviderInfo appWidgetInfo =
2564 mAppWidgetManager.findProvider(info.providerName, info.user);
2565 if (appWidgetInfo != null) {
2566 mPendingAddWidgetId = info.appWidgetId;
2567 mPendingAddInfo.copyFrom(info);
2568 mPendingAddWidgetInfo = appWidgetInfo;
Sunny Goyalff572272014-07-23 13:58:07 -07002569
Sunny Goyald478c832016-04-01 12:04:16 -07002570 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2571 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mPendingAddWidgetId);
2572 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, appWidgetInfo.provider);
2573 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2574 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
2575 startActivityForResult(intent, REQUEST_BIND_PENDING_APPWIDGET);
2576 }
2577 } else {
2578 LauncherAppWidgetProviderInfo appWidgetInfo =
2579 mAppWidgetManager.getLauncherAppWidgetInfo(info.appWidgetId);
2580 if (appWidgetInfo != null) {
2581 startRestoredWidgetReconfigActivity(appWidgetInfo, info);
2582 }
Sunny Goyalff572272014-07-23 13:58:07 -07002583 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002584 } else if (info.installProgress < 0) {
2585 // The install has not been queued
2586 final String packageName = info.providerName.getPackageName();
2587 showBrokenAppInstallDialog(packageName,
2588 new DialogInterface.OnClickListener() {
2589 public void onClick(DialogInterface dialog, int id) {
2590 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2591 }
2592 });
2593 } else {
2594 // Download has started.
2595 final String packageName = info.providerName.getPackageName();
2596 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002597 }
2598 }
2599
Sunny Goyald478c832016-04-01 12:04:16 -07002600 private void startRestoredWidgetReconfigActivity(
2601 LauncherAppWidgetProviderInfo provider, LauncherAppWidgetInfo info) {
2602 mPendingAddWidgetInfo = provider;
2603 mPendingAddInfo.copyFrom(info);
2604 mPendingAddWidgetId = info.appWidgetId;
2605 mAppWidgetManager.startConfigActivity(provider,
2606 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
2607 }
2608
Sunny Goyalff572272014-07-23 13:58:07 -07002609 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002610 * Event handler for the "grid" button that appears on the home screen, which
2611 * enters all apps mode.
2612 *
2613 * @param v The view that was clicked.
2614 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002615 protected void onClickAllAppsButton(View v) {
2616 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chung76648c52015-07-10 14:33:23 -07002617 if (!isAppsViewVisible()) {
Hyunyoung Song1ce0e302016-07-21 12:47:28 -07002618 getUserEventDispatcher().logActionOnControl(LauncherLogProto.Action.TAP,
Hyunyoung Song5aa27142016-07-21 11:48:37 -07002619 LauncherLogProto.ALL_APPS_BUTTON);
Hyunyoung Songdd60ce42016-07-27 17:08:38 -07002620 showAppsView(true /* animated */, true /* updatePredictedApps */,
2621 false /* focusSearchBar */);
Winson Chung76648c52015-07-10 14:33:23 -07002622 }
2623 }
2624
2625 protected void onLongClickAllAppsButton(View v) {
2626 if (LOGD) Log.d(TAG, "onLongClickAllAppsButton");
2627 if (!isAppsViewVisible()) {
Hyunyoung Song1ce0e302016-07-21 12:47:28 -07002628 getUserEventDispatcher().logActionOnControl(LauncherLogProto.Action.LONGPRESS,
Hyunyoung Song5aa27142016-07-21 11:48:37 -07002629 LauncherLogProto.ALL_APPS_BUTTON);
Hyunyoung Songdd60ce42016-07-27 17:08:38 -07002630 showAppsView(true /* animated */,
Winson Chung76648c52015-07-10 14:33:23 -07002631 true /* updatePredictedApps */, true /* focusSearchBar */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002632 }
2633 }
2634
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002635 private void showBrokenAppInstallDialog(final String packageName,
2636 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002637 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002638 .setTitle(R.string.abandoned_promises_title)
2639 .setMessage(R.string.abandoned_promise_explanation)
2640 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2641 .setNeutralButton(R.string.abandoned_clean_this,
2642 new DialogInterface.OnClickListener() {
2643 public void onClick(DialogInterface dialog, int id) {
2644 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2645 mWorkspace.removeAbandonedPromise(packageName, user);
2646 }
2647 })
2648 .create().show();
2649 return;
2650 }
2651
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002652 /**
2653 * Event handler for an app shortcut click.
2654 *
2655 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2656 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002657 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002658 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2659 Object tag = v.getTag();
2660 if (!(tag instanceof ShortcutInfo)) {
2661 throw new IllegalArgumentException("Input must be a Shortcut");
2662 }
2663
2664 // Open shortcut
2665 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002666
2667 if (shortcut.isDisabled != 0) {
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002668 if ((shortcut.isDisabled &
2669 ~ShortcutInfo.FLAG_DISABLED_SUSPENDED &
2670 ~ShortcutInfo.FLAG_DISABLED_QUIET_USER) == 0) {
2671 // If the app is only disabled because of the above flags, launch activity anyway.
2672 // Framework will tell the user why the app is suspended.
Kenny Guy44cba692016-01-21 19:50:02 +00002673 } else {
Tony Wickham4efffc52016-08-04 16:34:49 -07002674 if (!TextUtils.isEmpty(shortcut.disabledMessage)) {
2675 // Use a message specific to this shortcut, if it has one.
2676 Toast.makeText(this, shortcut.disabledMessage, Toast.LENGTH_SHORT).show();
2677 return;
2678 }
2679 // Otherwise just use a generic error message.
Kenny Guy44cba692016-01-21 19:50:02 +00002680 int error = R.string.activity_not_available;
2681 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2682 error = R.string.safemode_shortcut_error;
Sunny Goyald3b87ef2016-07-28 12:11:54 -07002683 } else if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_BY_PUBLISHER) != 0 ||
2684 (shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_LOCKED_USER) != 0) {
Sunny Goyal70a7c9b2016-07-28 10:07:32 -07002685 error = R.string.shortcut_not_available;
Kenny Guy44cba692016-01-21 19:50:02 +00002686 }
2687 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2688 return;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002689 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07002690 }
2691
Chris Wren40c5ed32014-06-24 18:24:23 -04002692 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002693 if ((v instanceof BubbleTextView)
2694 && shortcut.isPromise()
2695 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002696 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002697 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002698 new DialogInterface.OnClickListener() {
2699 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002700 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002701 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002702 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002703 return;
2704 }
2705
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002706 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002707 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002708 }
2709
Sunny Goyala7ce1662016-05-31 15:01:35 -07002710 private void startAppShortcutOrInfoActivity(View v) {
2711 ItemInfo item = (ItemInfo) v.getTag();
2712 Intent intent = item.getIntent();
2713 if (intent == null) {
2714 throw new IllegalArgumentException("Input must have a valid intent");
Sunny Goyal508da152014-08-14 10:53:27 -07002715 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07002716 boolean success = startActivitySafely(v, intent, item);
Hyunyoung Songaa953652016-04-19 18:30:24 -07002717 getUserEventDispatcher().logAppLaunch(v, intent);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002718
2719 if (success && v instanceof BubbleTextView) {
2720 mWaitingForResume = (BubbleTextView) v;
2721 mWaitingForResume.setStayPressed(true);
2722 }
2723 }
2724
2725 /**
2726 * Event handler for a folder icon click.
2727 *
2728 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2729 */
2730 protected void onClickFolderIcon(View v) {
2731 if (LOGD) Log.d(TAG, "onClickFolder");
2732 if (!(v instanceof FolderIcon)){
2733 throw new IllegalArgumentException("Input must be a FolderIcon");
2734 }
2735
2736 FolderIcon folderIcon = (FolderIcon) v;
Sunny Goyal08442b82015-10-21 17:15:08 -07002737 if (!folderIcon.getFolderInfo().opened && !folderIcon.getFolder().isDestroyed()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002738 // Open the requested folder
Adam Cohen37b2a492016-04-06 18:36:06 -07002739 openFolder(folderIcon);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002740 }
Michael Jurka5130e402011-10-13 04:55:35 -07002741 }
2742
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002743 /**
2744 * Event handler for the (Add) Widgets button that appears after a long press
2745 * on the home screen.
2746 */
Sunny Goyald0a6ae72016-06-16 12:29:03 -07002747 public void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002748 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002749 if (mIsSafeModeEnabled) {
2750 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2751 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002752 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Adam Cohen9211d422014-10-07 18:14:53 -07002753 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002754 }
2755
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002756 /**
2757 * Event handler for the wallpaper picker button that appears after a long press
2758 * on the home screen.
2759 */
Sunny Goyald0a6ae72016-06-16 12:29:03 -07002760 public void onClickWallpaperPicker(View v) {
Sunny Goyal1ed6c4a2016-04-21 15:16:11 -07002761 if (!Utilities.isWallapaperAllowed(this)) {
2762 Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show();
2763 return;
2764 }
2765
Sunny Goyal04cc3a72016-05-17 10:32:43 -07002766 String pickerPackage = getString(R.string.wallpaper_picker_package);
2767 if (TextUtils.isEmpty(pickerPackage)) {
2768 pickerPackage = PackageManagerHelper.getWallpaperPickerPackage(getPackageManager());
2769 }
2770
Tony Wickham785f7a52015-08-31 17:28:32 -07002771 int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
2772 float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002773
2774 Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER)
Sunny Goyal04cc3a72016-05-17 10:32:43 -07002775 .setPackage(pickerPackage)
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002776 .putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset);
2777 intent.setSourceBounds(getViewBounds(v));
2778 startActivityForResult(intent, REQUEST_PICK_WALLPAPER, getActivityLaunchOptions(v));
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002779 }
2780
2781 /**
2782 * Event handler for a click on the settings button that appears after a long press
2783 * on the home screen.
2784 */
Sunny Goyald0a6ae72016-06-16 12:29:03 -07002785 public void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002786 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Sunny Goyal745bad92016-05-02 10:54:12 -07002787 startActivity(new Intent(Utilities.ACTION_APPLICATION_PREFERENCES)
2788 .setPackage(getPackageName()));
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002789 }
2790
Adam Cohen61f560d2013-09-30 15:58:20 -07002791 public View.OnTouchListener getHapticFeedbackTouchListener() {
2792 if (mHapticFeedbackTouchListener == null) {
2793 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002794 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002795 @Override
2796 public boolean onTouch(View v, MotionEvent event) {
2797 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2798 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2799 }
2800 return false;
2801 }
2802 };
2803 }
2804 return mHapticFeedbackTouchListener;
2805 }
2806
Tony Wickhame2217252016-03-22 16:34:23 -07002807 @Override
2808 public void onAccessibilityStateChanged(boolean enabled) {
2809 mDragLayer.onAccessibilityStateChanged(enabled);
2810 }
2811
Adam Cohen9211d422014-10-07 18:14:53 -07002812 public void onDragStarted(View view) {
2813 if (isOnCustomContent()) {
2814 // Custom content screen doesn't participate in drag and drop. If on custom
2815 // content screen, move to default.
2816 moveWorkspaceToDefaultScreen();
2817 }
Adam Cohen9211d422014-10-07 18:14:53 -07002818 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002819
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002820 /**
2821 * Called when the user stops interacting with the launcher.
2822 * This implies that the user is now on the homescreen and is not doing housekeeping.
2823 */
Adam Cohen9211d422014-10-07 18:14:53 -07002824 protected void onInteractionEnd() {
2825 if (mLauncherCallbacks != null) {
2826 mLauncherCallbacks.onInteractionEnd();
2827 }
2828 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002829
2830 /**
2831 * Called when the user starts interacting with the launcher.
2832 * The possible interactions are:
2833 * - open all apps
2834 * - reorder an app shortcut, or a widget
2835 * - open the overview mode.
2836 * This is a good time to stop doing things that only make sense
2837 * when the user is on the homescreen and not doing housekeeping.
2838 */
Adam Cohen9211d422014-10-07 18:14:53 -07002839 protected void onInteractionBegin() {
2840 if (mLauncherCallbacks != null) {
2841 mLauncherCallbacks.onInteractionBegin();
2842 }
2843 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002844
Winson Chungcd99cd32015-04-29 11:03:24 -07002845 /** Updates the interaction state. */
2846 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002847 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002848 // overlay
Winson Chungef7f8742015-06-04 17:18:17 -07002849 boolean fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2850 boolean toStateWithOverlay = toState != Workspace.State.NORMAL;
Winson Chung83f59ab2015-05-05 17:21:58 -07002851 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002852 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002853 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002854 onInteractionEnd();
2855 }
2856 }
2857
Sunny Goyala7ce1662016-05-31 15:01:35 -07002858 private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002859 try {
Sunny Goyala7ce1662016-05-31 15:01:35 -07002860 StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
2861 try {
2862 // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
2863 // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure
2864 // is enabled by default on NYC.
2865 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
2866 .penaltyLog().build());
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002867
2868 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
2869 String id = ((ShortcutInfo) info).getDeepShortcutId();
2870 String packageName = intent.getPackage();
Sunny Goyal9994b2b2016-06-23 14:17:24 -07002871 LauncherAppState.getInstance().getShortcutManager().startShortcut(
2872 packageName, id, intent.getSourceBounds(), optsBundle, info.user);
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002873 } else {
2874 // Could be launching some bookkeeping activity
2875 startActivity(intent, optsBundle);
2876 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07002877 } finally {
2878 StrictMode.setVmPolicy(oldPolicy);
Kenny Guy1317e2d2014-05-08 18:52:50 +01002879 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002880 } catch (SecurityException e) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07002881 // Due to legacy reasons, direct call shortcuts require Launchers to have the
2882 // corresponding permission. Show the appropriate permission prompt if that
2883 // is the case.
2884 if (intent.getComponent() == null
2885 && Intent.ACTION_CALL.equals(intent.getAction())
2886 && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
2887 PackageManager.PERMISSION_GRANTED) {
2888 // TODO: Rename sPendingAddItem to a generic name.
2889 sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent,
2890 0, info);
2891 requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
2892 REQUEST_PERMISSION_CALL_PHONE);
2893 } else {
2894 // No idea why this was thrown.
2895 throw e;
Sunny Goyal28c6b962015-10-12 11:42:05 -07002896 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002897 }
2898 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002899
Sunny Goyala7ce1662016-05-31 15:01:35 -07002900 private Bundle getActivityLaunchOptions(View v) {
2901 if (Utilities.ATLEAST_MARSHMALLOW) {
2902 int left = 0, top = 0;
2903 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2904 if (v instanceof TextView) {
2905 // Launch from center of icon, not entire view
2906 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2907 if (icon != null) {
2908 Rect bounds = icon.getBounds();
2909 left = (width - bounds.width()) / 2;
2910 top = v.getPaddingTop();
2911 width = bounds.width();
2912 height = bounds.height();
2913 }
2914 }
2915 return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height).toBundle();
2916 } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
2917 // On L devices, we use the device default slide-up transition.
2918 // On L MR1 devices, we use a custom version of the slide-up transition which
2919 // doesn't have the delay present in the device default.
2920 return ActivityOptions.makeCustomAnimation(
2921 this, R.anim.task_open_enter, R.anim.no_anim).toBundle();
2922 }
2923 return null;
2924 }
2925
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002926 private Rect getViewBounds(View v) {
2927 int[] pos = new int[2];
2928 v.getLocationOnScreen(pos);
2929 return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight());
2930 }
2931
Sunny Goyala7ce1662016-05-31 15:01:35 -07002932 public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002933 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2934 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2935 return false;
2936 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07002937 // Only launch using the new animation if the shortcut has not opted out (this is a
2938 // private contract between launcher and may be ignored in the future).
2939 boolean useLaunchAnimation = (v != null) &&
2940 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2941 Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null;
2942
2943 UserHandleCompat user = null;
2944 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2945 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2946 user = UserManagerCompat.getInstance(this).getUserForSerialNumber(serialNumber);
Michael Jurka86a720e2012-05-09 11:23:23 -07002947 }
Sunny Goyala7ce1662016-05-31 15:01:35 -07002948
2949 // Prepare intent
2950 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2951 if (v != null) {
Sunny Goyal0eca4e22016-07-20 11:43:06 -07002952 intent.setSourceBounds(getViewBounds(v));
Sunny Goyala7ce1662016-05-31 15:01:35 -07002953 }
2954 try {
Tony Wickhambfbf7f92016-05-19 11:19:39 -07002955 if (Utilities.ATLEAST_MARSHMALLOW && item != null
2956 && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT
Tony Wickhamdef6e472016-08-29 15:17:48 -07002957 || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT)
2958 && ((ShortcutInfo) item).promisedIntent == null) {
Sunny Goyala7ce1662016-05-31 15:01:35 -07002959 // Shortcuts need some special checks due to legacy reasons.
2960 startShortcutIntentSafely(intent, optsBundle, item);
2961 } else if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2962 // Could be launching some bookkeeping activity
2963 startActivity(intent, optsBundle);
2964 } else {
2965 LauncherAppsCompat.getInstance(this).startActivityForProfile(
2966 intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
2967 }
2968 return true;
2969 } catch (ActivityNotFoundException|SecurityException e) {
2970 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2971 Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e);
2972 }
2973 return false;
Michael Jurka86a720e2012-05-09 11:23:23 -07002974 }
2975
Adam Cohen268c4752012-06-06 17:47:33 -07002976 /**
2977 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2978 * in the DragLayer in the exact absolute location of the original FolderIcon.
2979 */
2980 private void copyFolderIconToImage(FolderIcon fi) {
2981 final int width = fi.getMeasuredWidth();
2982 final int height = fi.getMeasuredHeight();
2983
2984 // Lazy load ImageView, Bitmap and Canvas
2985 if (mFolderIconImageView == null) {
2986 mFolderIconImageView = new ImageView(this);
2987 }
2988 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2989 mFolderIconBitmap.getHeight() != height) {
2990 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2991 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2992 }
2993
2994 DragLayer.LayoutParams lp;
2995 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2996 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2997 } else {
2998 lp = new DragLayer.LayoutParams(width, height);
2999 }
3000
Adam Cohen307fe232012-08-16 17:55:58 -07003001 // The layout from which the folder is being opened may be scaled, adjust the starting
3002 // view size by this scale factor.
3003 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003004 lp.customPosition = true;
3005 lp.x = mRectForFolderAnimation.left;
3006 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003007 lp.width = (int) (scale * width);
3008 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003009
3010 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3011 fi.draw(mFolderIconCanvas);
3012 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003013 if (fi.getFolder() != null) {
3014 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3015 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003016 }
Adam Cohen268c4752012-06-06 17:47:33 -07003017 // Just in case this image view is still in the drag layer from a previous animation,
3018 // we remove it and re-add it.
3019 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3020 mDragLayer.removeView(mFolderIconImageView);
3021 }
3022 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003023 if (fi.getFolder() != null) {
3024 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003025 }
Adam Cohen268c4752012-06-06 17:47:33 -07003026 }
3027
Adam Cohen37b2a492016-04-06 18:36:06 -07003028 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003029 if (fi == null) return;
Adam Cohenc51934b2011-07-26 21:07:43 -07003030 FolderInfo info = (FolderInfo) fi.getTag();
3031 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3032 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003033 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3034 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003035 }
3036
Adam Cohen268c4752012-06-06 17:47:33 -07003037 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3038 copyFolderIconToImage(fi);
3039 fi.setVisibility(View.INVISIBLE);
3040
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003041 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
3042 mFolderIconImageView, 0, 1.5f, 1.5f);
Sunny Goyal9fc953b2015-08-17 12:24:25 -07003043 if (Utilities.ATLEAST_LOLLIPOP) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003044 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3045 }
3046 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003047 oa.start();
3048 }
3049
Sunny Goyal935fca12015-10-13 10:19:01 -07003050 private void shrinkAndFadeInFolderIcon(final FolderIcon fi, boolean animate) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003051 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07003052 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003053
Adam Cohen268c4752012-06-06 17:47:33 -07003054 // We remove and re-draw the FolderIcon in-case it has changed
3055 mDragLayer.removeView(mFolderIconImageView);
3056 copyFolderIconToImage(fi);
Adam Cohenefca0272016-02-24 19:19:06 -08003057
3058 if (cl != null) {
3059 cl.clearFolderLeaveBehind();
3060 }
3061
Sunny Goyal5d2fc322015-07-06 22:52:49 -07003062 ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003063 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003064 oa.addListener(new AnimatorListenerAdapter() {
3065 @Override
3066 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003067 if (cl != null) {
Adam Cohen268c4752012-06-06 17:47:33 -07003068 // Remove the ImageView copy of the FolderIcon and make the original visible.
3069 mDragLayer.removeView(mFolderIconImageView);
3070 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003071 }
3072 }
3073 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003074 oa.start();
Sunny Goyal935fca12015-10-13 10:19:01 -07003075 if (!animate) {
3076 oa.end();
3077 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003078 }
3079
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003080 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003081 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003082 * is animated relative to the specified View. If the View is null, no animation
3083 * is played.
3084 *
Sunny Goyal08442b82015-10-21 17:15:08 -07003085 * @param folderIcon The FolderIcon describing the folder to open.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003086 */
Adam Cohen37b2a492016-04-06 18:36:06 -07003087 public void openFolder(FolderIcon folderIcon) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003088
Adam Cohenfb91f302012-06-11 15:45:18 -07003089 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003090 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3091 if (openFolder != null && openFolder != folder) {
3092 // Close any open folder before opening a folder.
3093 closeFolder();
3094 }
3095
Adam Cohena9cf38f2011-05-02 15:36:58 -07003096 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003097
Adam Cohena9cf38f2011-05-02 15:36:58 -07003098 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003099
Sunny Goyalf4066152015-04-15 09:42:19 -07003100 // While the folder is open, the position of the icon cannot change.
3101 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3102
Adam Cohen4554ee12011-08-03 16:13:21 -07003103 // Just verify that the folder hasn't already been added to the DragLayer.
3104 // There was a one-off crash where the folder had a parent already.
3105 if (folder.getParent() == null) {
3106 mDragLayer.addView(folder);
Sunny Goyal08442b82015-10-21 17:15:08 -07003107 mDragController.addDropTarget(folder);
Adam Cohen4554ee12011-08-03 16:13:21 -07003108 } else {
3109 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3110 folder.getParent() + ").");
3111 }
Adam Cohen37b2a492016-04-06 18:36:06 -07003112 folder.animateOpen();
3113
3114 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003115
3116 // Notify the accessibility manager that this folder "window" has appeared and occluded
3117 // the workspace items
3118 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3119 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003120 }
3121
3122 public void closeFolder() {
Sunny Goyal935fca12015-10-13 10:19:01 -07003123 closeFolder(true);
3124 }
3125
3126 public void closeFolder(boolean animate) {
Adam Cohen37c717f2013-11-26 11:50:15 -08003127 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003128 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003129 if (folder.isEditingName()) {
3130 folder.dismissEditingName();
3131 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003132 closeFolder(folder, animate);
Adam Cohen4554ee12011-08-03 16:13:21 -07003133 }
3134 }
3135
Sunny Goyal935fca12015-10-13 10:19:01 -07003136 public void closeFolder(Folder folder, boolean animate) {
Sunny Goyal08442b82015-10-21 17:15:08 -07003137 animate &= !Utilities.isPowerSaverOn(this);
3138
Adam Cohen4554ee12011-08-03 16:13:21 -07003139 folder.getInfo().opened = false;
3140
3141 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3142 if (parent != null) {
3143 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
Sunny Goyal935fca12015-10-13 10:19:01 -07003144 shrinkAndFadeInFolderIcon(fi, animate);
Sunny Goyalf4066152015-04-15 09:42:19 -07003145 if (fi != null) {
3146 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3147 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003148 }
Sunny Goyal935fca12015-10-13 10:19:01 -07003149 if (animate) {
3150 folder.animateClosed();
3151 } else {
Tony Wickham30bdd6e2015-11-17 17:59:26 -08003152 folder.close(false);
Sunny Goyal935fca12015-10-13 10:19:01 -07003153 }
Winson Chung83ca4802013-04-12 15:10:52 -07003154
Sunny Goyal935fca12015-10-13 10:19:01 -07003155 // Notify the accessibility manager that this folder "window" has disappeared and no
3156 // longer occludes the workspace items
Winson Chung83ca4802013-04-12 15:10:52 -07003157 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003158 }
3159
Tony Wickham49c8d292016-07-01 11:44:34 -07003160 public void closeShortcutsContainer() {
Sunny Goyala2454ad2016-07-22 10:50:11 -07003161 closeShortcutsContainer(true);
3162 }
3163
3164 public void closeShortcutsContainer(boolean animate) {
Tony Wickham49c8d292016-07-01 11:44:34 -07003165 DeepShortcutsContainer deepShortcutsContainer = getOpenShortcutsContainer();
3166 if (deepShortcutsContainer != null) {
Sunny Goyala2454ad2016-07-22 10:50:11 -07003167 if (animate) {
3168 deepShortcutsContainer.animateClose();
3169 } else {
3170 deepShortcutsContainer.close();
3171 }
Tony Wickham49c8d292016-07-01 11:44:34 -07003172 }
3173 }
3174
3175 /**
3176 * @return The open shortcuts container, or null if there is none
3177 */
3178 public DeepShortcutsContainer getOpenShortcutsContainer() {
Sunny Goyal71b3d1c2016-07-20 17:42:05 -07003179 // Iterate in reverse order. Shortcuts container is added later to the dragLayer,
3180 // and will be one of the last views.
3181 for (int i = mDragLayer.getChildCount() - 1; i >= 0; i--) {
3182 View child = mDragLayer.getChildAt(i);
Sunny Goyala2454ad2016-07-22 10:50:11 -07003183 if (child instanceof DeepShortcutsContainer
3184 && ((DeepShortcutsContainer) child).isOpen()) {
Sunny Goyal71b3d1c2016-07-20 17:42:05 -07003185 return (DeepShortcutsContainer) child;
3186 }
3187 }
3188 return null;
Tony Wickham49c8d292016-07-01 11:44:34 -07003189 }
3190
Tony Wickhamdadb3042016-02-24 11:07:00 -08003191 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003192 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003193 if (!isDraggingEnabled()) return false;
3194 if (isWorkspaceLocked()) return false;
3195 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003196
Hyunyoung Song68f98ac2016-07-22 14:22:49 -07003197 if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator) ||
3198 (v == mAllAppsButton && mAllAppsButton != null)) {
Winson Chung76648c52015-07-10 14:33:23 -07003199 onLongClickAllAppsButton(v);
3200 return true;
3201 }
3202
Adam Cohen1697b792013-09-17 19:08:21 -07003203 if (v instanceof Workspace) {
3204 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003205 if (!mWorkspace.isTouchActive()) {
3206 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003207 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3208 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3209 return true;
3210 } else {
3211 return false;
3212 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003213 } else {
3214 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003215 }
Adam Cohen1697b792013-09-17 19:08:21 -07003216 }
3217
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003218 CellLayout.CellInfo longClickCellInfo = null;
3219 View itemUnderLongClick = null;
3220 if (v.getTag() instanceof ItemInfo) {
3221 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003222 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003223 itemUnderLongClick = longClickCellInfo.cell;
3224 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003225 }
3226
Winson Chung3d503fb2011-07-13 17:25:49 -07003227 // The hotseat touch handling does not go through Workspace, and we always allow long press
3228 // on hotseat items.
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003229 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003230 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003231 // User long pressed on empty space
3232 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3233 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003234 if (mWorkspace.isInOverviewMode()) {
3235 mWorkspace.startReordering(v);
3236 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003237 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003238 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003239 } else {
Sunny Goyalbb011da2016-06-15 15:42:29 -07003240 final boolean isAllAppsButton =
3241 !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v) &&
3242 mDeviceProfile.inv.isAllAppsButtonRank(mHotseat.getOrderInHotseat(
3243 longClickCellInfo.cellX, longClickCellInfo.cellY));
Dan Sandlere26d0942014-01-13 14:30:14 -05003244 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003245 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003246 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003247 }
3248 }
3249 }
3250 return true;
3251 }
3252
Winson Chung3d503fb2011-07-13 17:25:49 -07003253 boolean isHotseatLayout(View layout) {
3254 return mHotseat != null && layout != null &&
3255 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3256 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003257
Winson Chung3d503fb2011-07-13 17:25:49 -07003258 /**
3259 * Returns the CellLayout of the specified container at the specified screen.
3260 */
Sunny Goyal92820592015-03-02 11:31:35 -08003261 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003262 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3263 if (mHotseat != null) {
3264 return mHotseat.getLayout();
3265 } else {
3266 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003267 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003268 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003269 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003270 }
3271 }
3272
Winson Chungb745afb2015-03-02 11:51:23 -08003273 /**
3274 * For overridden classes.
3275 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003276 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003277 return isAppsViewVisible();
3278 }
3279
3280 public boolean isAppsViewVisible() {
3281 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3282 }
3283
3284 public boolean isWidgetsViewVisible() {
3285 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003286 }
3287
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003288 private void setWorkspaceBackground(int background) {
3289 switch (background) {
3290 case WORKSPACE_BACKGROUND_TRANSPARENT:
3291 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3292 break;
3293 case WORKSPACE_BACKGROUND_BLACK:
3294 getWindow().setBackgroundDrawable(null);
3295 break;
3296 default:
3297 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3298 }
Craig Mautner360310b2012-10-26 15:13:08 -07003299 }
3300
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003301 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003302 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3303 int curflags = getWindow().getAttributes().flags
3304 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3305 if (wpflags != curflags) {
3306 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3307 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003308 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003309 }
3310
Michael Jurkae326f182011-11-21 14:05:46 -08003311 @Override
3312 public void onTrimMemory(int level) {
3313 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003314 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3315 // The widget preview db can result in holding onto over
3316 // 3MB of memory for caching which isn't necessary.
3317 SQLiteDatabase.releaseMemory();
3318
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003319 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003320 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003321 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003322 if (mLauncherCallbacks != null) {
3323 mLauncherCallbacks.onTrimMemory(level);
3324 }
Michael Jurkae326f182011-11-21 14:05:46 -08003325 }
3326
Winson5c6bdbb2015-09-03 11:36:19 -07003327 public boolean showWorkspace(boolean animated) {
Winson10612a72015-09-09 17:06:09 -07003328 return showWorkspace(animated, null);
Adam Cohened307df2013-10-02 09:37:31 -07003329 }
3330
Winson5c6bdbb2015-09-03 11:36:19 -07003331 public boolean showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chung0f785722015-04-08 10:27:49 -07003332 boolean changed = mState != State.WORKSPACE ||
3333 mWorkspace.getState() != Workspace.State.NORMAL;
Hyunyoung Song9dcf0a32016-07-27 10:55:51 -07003334 if (changed || mAllAppsController.isTransitioning()) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003335 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003336 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003337 Workspace.State.NORMAL, animated, onCompleteRunnable);
Winson Chungc7d2b602012-05-16 17:02:20 -07003338
Michael Jurkab3e22d92011-10-31 15:58:33 -07003339 // Set focus to the AppsCustomize button
3340 if (mAllAppsButton != null) {
3341 mAllAppsButton.requestFocus();
3342 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003343 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003344
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003345 // Change the state *after* we've called all the transition code
3346 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003347
Winson Chung5fb63472011-02-02 17:03:37 -08003348 // Resume the auto-advance of widgets
3349 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003350 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003351
Winson Chung0f785722015-04-08 10:27:49 -07003352 if (changed) {
3353 // Send an accessibility event to announce the context change
3354 getWindow().getDecorView()
3355 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chung0f785722015-04-08 10:27:49 -07003356 }
Winson5c6bdbb2015-09-03 11:36:19 -07003357 return changed;
Bjorn Bringertc459e522013-06-07 19:36:01 +01003358 }
3359
Winsone9f27272015-10-13 10:47:51 -07003360 /**
3361 * Shows the overview button.
3362 */
Sunny Goyald0a6ae72016-06-16 12:29:03 -07003363 public void showOverviewMode(boolean animated) {
Winsone9f27272015-10-13 10:47:51 -07003364 showOverviewMode(animated, false);
3365 }
3366
3367 /**
3368 * Shows the overview button, and if {@param requestButtonFocus} is set, will force the focus
3369 * onto one of the overview panel buttons.
3370 */
3371 void showOverviewMode(boolean animated, boolean requestButtonFocus) {
3372 Runnable postAnimRunnable = null;
3373 if (requestButtonFocus) {
3374 postAnimRunnable = new Runnable() {
3375 @Override
3376 public void run() {
3377 // Hitting the menu button when in touch mode does not trigger touch mode to
3378 // be disabled, so if requested, force focus on one of the overview panel
3379 // buttons.
3380 mOverviewPanel.requestFocusFromTouch();
3381 }
3382 };
3383 }
Adam Cohened307df2013-10-02 09:37:31 -07003384 mWorkspace.setVisibility(View.VISIBLE);
Winson Chung006ee262015-08-03 14:40:11 -07003385 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson6e6a9b42015-10-13 17:52:17 -07003386 Workspace.State.OVERVIEW, animated, postAnimRunnable);
Adam Cohened307df2013-10-02 09:37:31 -07003387 mState = State.WORKSPACE;
Hyunyoung Song0a9c0922016-09-20 22:50:06 -07003388 // If animated from long press, then don't allow any of the controller in the drag
3389 // layer to intercept any remaining touch.
3390 mWorkspace.requestDisallowInterceptTouchEvent(animated);
Joe Onorato00acb122009-08-04 16:04:30 -04003391 }
3392
Winson Chungb745afb2015-03-02 11:51:23 -08003393 /**
3394 * Shows the apps view.
3395 */
Hyunyoung Songdd60ce42016-07-27 17:08:38 -07003396 public void showAppsView(boolean animated, boolean updatePredictedApps,
Winson Chung76648c52015-07-10 14:33:23 -07003397 boolean focusSearchBar) {
Hyunyoung Songc001cf52016-07-21 17:32:43 -07003398 markAppsViewShown();
Winson Chung4ac30062015-05-08 17:34:17 -07003399 if (updatePredictedApps) {
3400 tryAndUpdatePredictedApps();
3401 }
Winson Chung76648c52015-07-10 14:33:23 -07003402 showAppsOrWidgets(State.APPS, animated, focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003403 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003404
Winson Chungb745afb2015-03-02 11:51:23 -08003405 /**
3406 * Shows the widgets view.
3407 */
3408 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003409 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003410 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003411 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003412 }
Winson Chung76648c52015-07-10 14:33:23 -07003413 showAppsOrWidgets(State.WIDGETS, animated, false);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003414
3415 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003416 @Override
3417 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003418 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003419 }
3420 });
Winson Chungb745afb2015-03-02 11:51:23 -08003421 }
3422
3423 /**
3424 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003425 *
3426 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003427 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003428 // TODO: calling method should use the return value so that when {@code false} is returned
3429 // the workspace transition doesn't fall into invalid state.
Winson Chung76648c52015-07-10 14:33:23 -07003430 private boolean showAppsOrWidgets(State toState, boolean animated, boolean focusSearchBar) {
Hyunyoung Song9dcf0a32016-07-27 10:55:51 -07003431 if (!(mState == State.WORKSPACE ||
3432 mState == State.APPS_SPRING_LOADED ||
3433 mState == State.WIDGETS_SPRING_LOADED ||
3434 (mState == State.APPS && mAllAppsController.isTransitioning()))) {
Hyunyoung Songb7900832015-05-15 16:29:45 -07003435 return false;
3436 }
3437 if (toState != State.APPS && toState != State.WIDGETS) {
3438 return false;
3439 }
Winson Chungb745afb2015-03-02 11:51:23 -08003440
Hyunyoung Song06ca7562016-07-29 13:03:54 -07003441 // This is a safe and supported transition to bypass spring_loaded mode.
3442 if (mExitSpringLoadedModeRunnable != null) {
3443 mHandler.removeCallbacks(mExitSpringLoadedModeRunnable);
3444 mExitSpringLoadedModeRunnable = null;
3445 }
3446
Winson Chungb745afb2015-03-02 11:51:23 -08003447 if (toState == State.APPS) {
Winson Chung006ee262015-08-03 14:40:11 -07003448 mStateTransitionAnimation.startAnimationToAllApps(mWorkspace.getState(), animated,
3449 focusSearchBar);
Winson Chungb745afb2015-03-02 11:51:23 -08003450 } else {
Winson Chung006ee262015-08-03 14:40:11 -07003451 mStateTransitionAnimation.startAnimationToWidgets(mWorkspace.getState(), animated);
Winson Chungb745afb2015-03-02 11:51:23 -08003452 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003453
Michael Jurkab3e22d92011-10-31 15:58:33 -07003454 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003455 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003456
3457 // Pause the auto-advance of widgets until we are out of AllApps
3458 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003459 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003460 closeFolder();
Tony Wickham49c8d292016-07-01 11:44:34 -07003461 closeShortcutsContainer();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003462
3463 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003464 getWindow().getDecorView()
3465 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003466 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003467 }
3468
Winson Chungcd99cd32015-04-29 11:03:24 -07003469 /**
3470 * Updates the workspace and interaction state on state change, and return the animation to this
3471 * new state.
3472 */
Sunny Goyalce5a7e52015-07-08 15:44:27 -07003473 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState,
Winson Chung006ee262015-08-03 14:40:11 -07003474 boolean animated, HashMap<View, Integer> layerViews) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003475 Workspace.State fromState = mWorkspace.getState();
Winson2a87fe82015-08-07 10:37:21 -07003476 Animator anim = mWorkspace.setStateWithAnimation(toState, animated, layerViews);
Winson Chungcd99cd32015-04-29 11:03:24 -07003477 updateInteraction(fromState, toState);
3478 return anim;
3479 }
3480
Hyunyoung Song3f471442015-04-08 19:01:34 -07003481 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003482 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Tony Wickham94e0d372015-09-11 12:17:48 -07003483 if (isStateSpringLoaded()) {
Winson Chungb745afb2015-03-02 11:51:23 -08003484 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003485 }
Winson Chungb745afb2015-03-02 11:51:23 -08003486
Winson Chung006ee262015-08-03 14:40:11 -07003487 mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(),
Winson2a87fe82015-08-07 10:37:21 -07003488 Workspace.State.SPRING_LOADED, true /* animated */,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003489 null /* onCompleteRunnable */);
Tony Wickham94e0d372015-09-11 12:17:48 -07003490
3491 if (isAppsViewVisible()) {
3492 mState = State.APPS_SPRING_LOADED;
3493 } else if (isWidgetsViewVisible()) {
3494 mState = State.WIDGETS_SPRING_LOADED;
Tony Wickhame0c33232016-02-08 11:37:04 -08003495 } else if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003496 mState = State.WORKSPACE_SPRING_LOADED;
Tony Wickham0f97b782015-12-02 17:55:07 -08003497 } else {
3498 mState = State.WORKSPACE;
Tony Wickham94e0d372015-09-11 12:17:48 -07003499 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003500 }
Adam Cohen7777d962011-08-18 18:58:38 -07003501
Hyunyoung Song3f471442015-04-08 19:01:34 -07003502 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003503 final Runnable onCompleteRunnable) {
Tony Wickham94e0d372015-09-11 12:17:48 -07003504 if (!isStateSpringLoaded()) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003505
Hyunyoung Song06ca7562016-07-29 13:03:54 -07003506 if (mExitSpringLoadedModeRunnable != null) {
3507 mHandler.removeCallbacks(mExitSpringLoadedModeRunnable);
3508 }
3509 mExitSpringLoadedModeRunnable = new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003510 @Override
3511 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003512 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003513 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3514 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003515 // Before we show workspace, hide all apps again because
3516 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3517 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003518 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003519 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003520 } else {
3521 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003522 }
Hyunyoung Song06ca7562016-07-29 13:03:54 -07003523 mExitSpringLoadedModeRunnable = null;
Winson Chung557d6ed2011-07-08 15:34:52 -07003524 }
Hyunyoung Song06ca7562016-07-29 13:03:54 -07003525 };
3526 mHandler.postDelayed(mExitSpringLoadedModeRunnable, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003527 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003528
Tony Wickhame0c33232016-02-08 11:37:04 -08003529 boolean isStateSpringLoaded() {
Tony Wickham94e0d372015-09-11 12:17:48 -07003530 return mState == State.WORKSPACE_SPRING_LOADED || mState == State.APPS_SPRING_LOADED
3531 || mState == State.WIDGETS_SPRING_LOADED;
3532 }
3533
Michael Jurkad3ef3062010-11-23 16:23:58 -08003534 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003535 if (mState == State.APPS_SPRING_LOADED) {
Hyunyoung Songdd60ce42016-07-27 17:08:38 -07003536 showAppsView(true /* animated */,
Winson Chung76648c52015-07-10 14:33:23 -07003537 false /* updatePredictedApps */, false /* focusSearchBar */);
Winson Chungb745afb2015-03-02 11:51:23 -08003538 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003539 showWidgetsView(true, false);
Tony Wickham94e0d372015-09-11 12:17:48 -07003540 } else if (mState == State.WORKSPACE_SPRING_LOADED) {
3541 showWorkspace(true);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003542 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003543 }
3544
Winson Chung4ac30062015-05-08 17:34:17 -07003545 /**
3546 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3547 * resumed.
3548 */
Hyunyoung Songa9a8a422016-06-15 16:45:48 -07003549 public void tryAndUpdatePredictedApps() {
Winson Chung4ac30062015-05-08 17:34:17 -07003550 if (mLauncherCallbacks != null) {
Winson Chung6b1c73f2015-06-18 11:38:42 -07003551 List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
Winson Chung91c05952015-06-25 12:17:30 -07003552 if (apps != null) {
Winson Chung4ac30062015-05-08 17:34:17 -07003553 mAppsView.setPredictedApps(apps);
Hyunyoung Songaa953652016-04-19 18:30:24 -07003554 getUserEventDispatcher().setPredictedApps(apps);
Winson Chung4ac30062015-05-08 17:34:17 -07003555 }
3556 }
3557 }
3558
Michael Jurkab3e22d92011-10-31 15:58:33 -07003559 void lockAllApps() {
3560 // TODO
3561 }
3562
3563 void unlockAllApps() {
3564 // TODO
3565 }
3566
Winsonf768d932015-09-25 16:12:35 -07003567 public boolean launcherCallbacksProvidesSearch() {
3568 return (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch());
3569 }
3570
Michael Jurkad7c28052012-04-27 15:43:36 -07003571 @Override
3572 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003573 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003574 final List<CharSequence> text = event.getText();
3575 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003576 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003577 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003578 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003579 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003580 text.add(getString(R.string.widget_button_text));
Hyunyoung Song166e6482015-06-25 21:06:07 -07003581 } else if (mWorkspace != null) {
3582 text.add(mWorkspace.getCurrentPageDescription());
alanv1d4fde62012-10-17 13:15:47 -07003583 } else {
3584 text.add(getString(R.string.all_apps_home_button_label));
3585 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003586 return result;
3587 }
3588
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003589 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003590 * If the activity is currently paused, signal that we need to run the passed Runnable
3591 * in onResume.
3592 *
3593 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003594 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3595 * wrong when we're not running, and if the activity comes back to what the configuration was
3596 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003597 *
3598 * Implementation of the method from LauncherModel.Callbacks.
3599 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003600 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003601 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003602 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003603 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003604 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003605 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003606 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003607 }
3608 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003609 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003610 return true;
3611 } else {
3612 return false;
3613 }
3614 }
3615
Michael Jurkac402cd92013-05-20 15:49:32 +02003616 private boolean waitUntilResume(Runnable run) {
3617 return waitUntilResume(run, false);
3618 }
3619
Michael Jurka1e2f4652013-07-08 18:03:46 -07003620 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003621 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003622 }
3623
Michael Jurka7607c2f2013-04-03 14:33:19 -07003624 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003625 * If the activity is currently paused, signal that we need to re-run the loader
3626 * in onResume.
3627 *
3628 * This needs to be called from incoming places where resources might have been loaded
3629 * while we are paused. That is becaues the Configuration might be wrong
3630 * when we're not running, and if it comes back to what it was when we
3631 * were paused, we are not restarted.
3632 *
3633 * Implementation of the method from LauncherModel.Callbacks.
3634 *
3635 * @return true if we are currently paused. The caller might be able to
3636 * skip some work in that case since we will come back again.
3637 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003638 @Override
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003639 public boolean setLoadOnResume() {
3640 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003641 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003642 mOnResumeNeedsLoad = true;
3643 return true;
3644 } else {
3645 return false;
3646 }
3647 }
3648
3649 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003650 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003651 */
Sunny Goyal93f878c2016-03-30 17:31:24 -07003652 @Override
Joe Onorato9c1289c2009-08-17 11:03:03 -04003653 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003654 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003655 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003656 } else {
Winson Chung882a52e2015-07-08 14:32:26 -07003657 return 0;
Joe Onoratod0afc872010-06-11 00:03:15 -07003658 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003659 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003660
Joe Onorato9c1289c2009-08-17 11:03:03 -04003661 /**
Sunny Goyal527c7d32015-08-28 15:19:36 -07003662 * Clear any pending bind callbacks. This is called when is loader is planning to
3663 * perform a full rebind from scratch.
3664 */
3665 @Override
3666 public void clearPendingBinds() {
3667 mBindOnResumeCallbacks.clear();
3668 if (mPendingExecutor != null) {
3669 mPendingExecutor.markCompleted();
3670 mPendingExecutor = null;
3671 }
3672 }
3673
3674 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003675 * Refreshes the shortcuts shown on the workspace.
3676 *
3677 * Implementation of the method from LauncherModel.Callbacks.
3678 */
3679 public void startBinding() {
Sunny Goyale26d1002016-06-20 14:52:14 -07003680 if (LauncherAppState.PROFILE_STARTUP) {
3681 Trace.beginSection("Starting page bind");
3682 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003683 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003684
Winson Chungd64d1762013-08-20 14:37:16 -07003685 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003686 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003687 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003688
Michael Jurka05bf644e2011-11-30 20:28:53 -08003689 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003690 if (mHotseat != null) {
3691 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003692 }
Sunny Goyale26d1002016-06-20 14:52:14 -07003693 if (LauncherAppState.PROFILE_STARTUP) {
3694 Trace.endSection();
3695 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003696 }
3697
Adam Cohendcd297f2013-06-18 13:13:40 -07003698 @Override
3699 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003700 // Make sure the first screen is always at the start.
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07003701 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
3702 orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003703 orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID);
3704 orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
3705 mModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07003706 } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
3707 // If there are no screens, we need to have an empty screen
3708 mWorkspace.addExtraEmptyScreen();
Adam Cohen5084cba2013-09-03 12:01:16 -07003709 }
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003710 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003711
3712 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003713 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003714 if (hasCustomContentToLeft()) {
3715 mWorkspace.createCustomContentContainer();
3716 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003717 }
Winsonc7d2e832016-07-28 12:24:55 -07003718
3719 // After we have added all the screens, if the wallpaper was locked to the default state,
3720 // then notify to indicate that it can be released and a proper wallpaper offset can be
3721 // computed before the next layout
3722 mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
Winson Chung64359a52013-07-08 17:17:08 -07003723 }
3724
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003725 private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003726 int count = orderedScreenIds.size();
3727 for (int i = 0; i < count; i++) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003728 long screenId = orderedScreenIds.get(i);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -07003729 if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003730 // No need to bind the first screen, as its always bound.
3731 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
3732 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003733 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003734 }
3735
Winson Chungd64d1762013-08-20 14:37:16 -07003736 public void bindAppsAdded(final ArrayList<Long> newScreens,
3737 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003738 final ArrayList<ItemInfo> addAnimated,
3739 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003740 Runnable r = new Runnable() {
3741 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003742 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003743 }
3744 };
3745 if (waitUntilResume(r)) {
3746 return;
3747 }
3748
Winson Chungd64d1762013-08-20 14:37:16 -07003749 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003750 if (newScreens != null) {
3751 bindAddScreens(newScreens);
3752 }
Winson Chungd64d1762013-08-20 14:37:16 -07003753
3754 // We add the items without animation on non-visible pages, and with
3755 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003756 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003757 bindItems(addNotAnimated, 0,
3758 addNotAnimated.size(), false);
3759 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003760 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003761 bindItems(addAnimated, 0,
3762 addAnimated.size(), true);
3763 }
Winson Chungc58497e2013-09-03 17:48:37 -07003764
Winson Chung87412982013-10-03 18:34:14 -07003765 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003766 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003767
Winson Chungb745afb2015-03-02 11:51:23 -08003768 if (addedApps != null && mAppsView != null) {
3769 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003770 }
Winson Chungd64d1762013-08-20 14:37:16 -07003771 }
3772
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003773 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003774 * Bind the items start-end from the list.
3775 *
3776 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003777 */
Tony Wickham0bb211a2015-10-02 16:22:08 -07003778 @Override
Winson Chung64359a52013-07-08 17:17:08 -07003779 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3780 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003781 Runnable r = new Runnable() {
3782 public void run() {
3783 bindItems(shortcuts, start, end, forceAnimateIcons);
3784 }
3785 };
3786 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003787 return;
3788 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003789
Winson Chungf0c6ae02012-03-21 16:10:31 -07003790 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003791 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3792 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003793 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003794 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003795 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003796 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003798
3799 // Short circuit if we are loading dock items for a configuration which has no dock
3800 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3801 mHotseat == null) {
3802 continue;
3803 }
3804
Sunny Goyal639e9062015-08-19 19:17:06 -07003805 final View view;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003806 switch (item.itemType) {
3807 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3808 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Tony Wickhambfbf7f92016-05-19 11:19:39 -07003809 case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003810 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyal639e9062015-08-19 19:17:06 -07003811 view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003812 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003813 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Sunny Goyal639e9062015-08-19 19:17:06 -07003814 view = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003815 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003816 (FolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003818 default:
3819 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003820 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003821
Sunny Goyalda4fe1a2016-05-26 16:05:17 -07003822 /*
3823 * Remove colliding items.
3824 */
3825 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3826 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3827 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3828 View v = cl.getChildAt(item.cellX, item.cellY);
3829 Object tag = v.getTag();
3830 String desc = "Collision while binding workspace item: " + item
3831 + ". Collides with " + tag;
3832 if (ProviderConfig.IS_DOGFOOD_BUILD) {
3833 throw (new RuntimeException(desc));
3834 } else {
3835 Log.d(TAG, desc);
3836 LauncherModel.deleteItemFromDatabase(this, item);
3837 continue;
3838 }
3839 }
3840 }
Sunny Goyal639e9062015-08-19 19:17:06 -07003841 workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX,
3842 item.cellY, 1, 1);
3843 if (animateIcons) {
3844 // Animate all the applications up now
3845 view.setAlpha(0f);
3846 view.setScaleX(0f);
3847 view.setScaleY(0f);
3848 bounceAnims.add(createNewAppBounceAnimation(view, i));
3849 newShortcutsScreenId = item.screenId;
3850 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003851 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003852
Winson Chung997a9232013-07-24 15:33:46 -07003853 if (animateIcons) {
3854 // Animate to the correct page
3855 if (newShortcutsScreenId > -1) {
3856 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003857 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003858 final Runnable startBounceAnimRunnable = new Runnable() {
3859 public void run() {
3860 anim.playTogether(bounceAnims);
3861 anim.start();
3862 }
3863 };
Winson Chung997a9232013-07-24 15:33:46 -07003864 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003865 // We post the animation slightly delayed to prevent slowdowns
3866 // when we are loading right after we return to launcher.
3867 mWorkspace.postDelayed(new Runnable() {
3868 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003869 if (mWorkspace != null) {
3870 mWorkspace.snapToPage(newScreenIndex);
3871 mWorkspace.postDelayed(startBounceAnimRunnable,
3872 NEW_APPS_ANIMATION_DELAY);
3873 }
Winson Chung94d67682013-09-25 16:29:40 -07003874 }
3875 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003876 } else {
3877 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003878 }
3879 }
Winson Chung64359a52013-07-08 17:17:08 -07003880 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003881 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003882 }
3883
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003884 private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
3885 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
3886 view.updateIcon(mIconCache);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003887 view.updateAppWidget(null);
3888 view.setOnClickListener(this);
3889 addAppWidgetToWorkspace(view, item, null, false);
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003890 mWorkspace.requestLayout();
3891 }
3892
Joe Onorato9c1289c2009-08-17 11:03:03 -04003893 /**
3894 * Add the views for a widget to the workspace.
3895 *
3896 * Implementation of the method from LauncherModel.Callbacks.
3897 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003898 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003899 Runnable r = new Runnable() {
3900 public void run() {
3901 bindAppWidget(item);
3902 }
3903 };
3904 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003905 return;
3906 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003907
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003908 if (mIsSafeModeEnabled) {
3909 bindSafeModeWidget(item);
3910 return;
3911 }
3912
Daniel Sandler843e8602010-06-07 14:59:01 -04003913 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3914 if (DEBUG_WIDGETS) {
3915 Log.d(TAG, "bindAppWidget: " + item);
3916 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003917
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003918 final LauncherAppWidgetProviderInfo appWidgetInfo;
Adam Cohen59400422014-03-05 18:07:04 -08003919
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003920 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
3921 // If the provider is not ready, bind as a pending widget.
3922 appWidgetInfo = null;
3923 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
3924 // The widget id is not valid. Try to find the widget based on the provider info.
3925 appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
3926 } else {
3927 appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
3928 }
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003929
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003930 // If the provider is ready, but the width is not yet restored, try to restore it.
3931 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
3932 (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
Sunny Goyalff572272014-07-23 13:58:07 -07003933 if (appWidgetInfo == null) {
3934 if (DEBUG_WIDGETS) {
3935 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
3936 + " belongs to component " + item.providerName
3937 + ", as the povider is null");
3938 }
3939 LauncherModel.deleteItemFromDatabase(this, item);
3940 return;
3941 }
Sunny Goyalff572272014-07-23 13:58:07 -07003942
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003943 // If we do not have a valid id, try to bind an id.
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003944 if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
Sunny Goyald478c832016-04-01 12:04:16 -07003945 if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
3946 // Id has not been allocated yet. Allocate a new id.
3947 item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
3948 item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
Sunny Goyalff572272014-07-23 13:58:07 -07003949
Sunny Goyald478c832016-04-01 12:04:16 -07003950 // Also try to bind the widget. If the bind fails, the user will be shown
3951 // a click to setup UI, which will ask for the bind permission.
3952 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo);
3953 pendingInfo.spanX = item.spanX;
3954 pendingInfo.spanY = item.spanY;
3955 pendingInfo.minSpanX = item.minSpanX;
3956 pendingInfo.minSpanY = item.minSpanY;
3957 Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
3958 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
3959 item.appWidgetId, appWidgetInfo, options);
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003960
Sunny Goyald478c832016-04-01 12:04:16 -07003961 // Bind succeeded
3962 if (success) {
3963 // If the widget has a configure activity, it is still needs to set it up,
3964 // otherwise the widget is ready to go.
3965 item.restoreStatus = (appWidgetInfo.configure == null)
3966 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
3967 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003968 }
Sunny Goyald478c832016-04-01 12:04:16 -07003969
3970 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07003971 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003972 } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003973 && (appWidgetInfo.configure == null)) {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003974 // The widget was marked as UI not ready, but there is no configure activity to
3975 // update the UI.
Sunny Goyal84b4adc2015-08-12 15:12:16 -07003976 item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
3977 LauncherModel.updateItemInDatabase(this, item);
Sunny Goyalff572272014-07-23 13:58:07 -07003978 }
Sunny Goyalff572272014-07-23 13:58:07 -07003979 }
3980
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003981 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07003982 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08003983 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
3984 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07003985 }
Daniel Sandler843e8602010-06-07 14:59:01 -04003986
Sunny Goyal56c73602015-09-25 12:55:01 -07003987 // Verify that we own the widget
Sunny Goyal2e1efb42016-03-03 16:58:55 -08003988 if (appWidgetInfo == null) {
Sunny Goyal713edfc2016-05-06 09:58:34 -07003989 FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
Sunny Goyal56c73602015-09-25 12:55:01 -07003990 deleteWidgetInfo(item);
3991 return;
3992 }
3993
Sunny Goyal233ee962015-08-03 13:05:01 -07003994 item.minSpanX = appWidgetInfo.minSpanX;
3995 item.minSpanY = appWidgetInfo.minSpanY;
Sunny Goyal87af0fd2016-05-16 14:56:02 -07003996 addAppWidgetToWorkspace(
3997 mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo),
3998 item, appWidgetInfo, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07003999 } else {
Sunny Goyal87af0fd2016-05-16 14:56:02 -07004000 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, false);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004001 view.updateIcon(mIconCache);
Sunny Goyal87af0fd2016-05-16 14:56:02 -07004002 view.updateAppWidget(null);
4003 view.setOnClickListener(this);
4004 addAppWidgetToWorkspace(view, item, null, false);
Sunny Goyal651077b2014-06-30 14:15:31 -07004005 }
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004006 mWorkspace.requestLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004007
Daniel Sandler843e8602010-06-07 14:59:01 -04004008 if (DEBUG_WIDGETS) {
4009 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4010 + (SystemClock.uptimeMillis()-start) + "ms");
4011 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004012 }
4013
Sunny Goyalff572272014-07-23 13:58:07 -07004014 /**
4015 * Restores a pending widget.
4016 *
4017 * @param appWidgetId The app widget id
Sunny Goyalff572272014-07-23 13:58:07 -07004018 */
Sunny Goyald478c832016-04-01 12:04:16 -07004019 private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
Sunny Goyalff572272014-07-23 13:58:07 -07004020 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4021 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4022 Log.e(TAG, "Widget update called, when the widget no longer exists.");
Sunny Goyald478c832016-04-01 12:04:16 -07004023 return null;
Sunny Goyalff572272014-07-23 13:58:07 -07004024 }
4025
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004026 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyald478c832016-04-01 12:04:16 -07004027 info.restoreStatus = finalRestoreFlag;
Sunny Goyalff572272014-07-23 13:58:07 -07004028
4029 mWorkspace.reinflateWidgetsIfNecessary();
4030 LauncherModel.updateItemInDatabase(this, info);
Sunny Goyald478c832016-04-01 12:04:16 -07004031 return info;
Sunny Goyalff572272014-07-23 13:58:07 -07004032 }
4033
Adam Cohen1462de32012-07-24 22:34:36 -07004034 public void onPageBoundSynchronously(int page) {
4035 mSynchronouslyBoundPages.add(page);
4036 }
4037
Sunny Goyal527c7d32015-08-28 15:19:36 -07004038 @Override
4039 public void executeOnNextDraw(ViewOnDrawExecutor executor) {
4040 if (mPendingExecutor != null) {
4041 mPendingExecutor.markCompleted();
4042 }
4043 mPendingExecutor = executor;
4044 executor.attachTo(this);
4045 }
4046
4047 public void clearPendingExecutor(ViewOnDrawExecutor executor) {
4048 if (mPendingExecutor == executor) {
4049 mPendingExecutor = null;
4050 }
4051 }
4052
Sunny Goyalb5b9ad62016-04-02 11:23:39 -07004053 @Override
4054 public void finishFirstPageBind(final ViewOnDrawExecutor executor) {
4055 Runnable r = new Runnable() {
4056 public void run() {
4057 finishFirstPageBind(executor);
4058 }
4059 };
4060 if (waitUntilResume(r)) {
4061 return;
4062 }
4063
4064 Runnable onComplete = new Runnable() {
4065 @Override
4066 public void run() {
4067 if (executor != null) {
4068 executor.onLoadAnimationCompleted();
4069 }
4070 }
4071 };
4072 if (mDragLayer.getAlpha() < 1) {
4073 mDragLayer.animate().alpha(1).withEndAction(onComplete).start();
4074 } else {
4075 onComplete.run();
4076 }
4077 }
4078
Joe Onorato9c1289c2009-08-17 11:03:03 -04004079 /**
4080 * Callback saying that there aren't any more items to bind.
4081 *
4082 * Implementation of the method from LauncherModel.Callbacks.
4083 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004084 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004085 Runnable r = new Runnable() {
4086 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004087 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004088 }
4089 };
4090 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004091 return;
4092 }
Sunny Goyale26d1002016-06-20 14:52:14 -07004093 if (LauncherAppState.PROFILE_STARTUP) {
4094 Trace.beginSection("Page bind completed");
4095 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004096 if (mSavedState != null) {
4097 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004098 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004099 }
Sunny Goyal08442b82015-10-21 17:15:08 -07004100
Joe Onorato9c1289c2009-08-17 11:03:03 -04004101 mSavedState = null;
4102 }
4103
Adam Cohen1462de32012-07-24 22:34:36 -07004104 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004105
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004106 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07004107
4108 // If we received the result of any pending adds while the loader was running (e.g. the
4109 // widget configuration forced an orientation change), process them now.
4110 if (sPendingAddItem != null) {
4111 final long screenId = completeAdd(sPendingAddItem);
4112
4113 // TODO: this moves the user to the page where the pending item was added. Ideally,
4114 // the screen would be guaranteed to exist after bind, and the page would be set through
4115 // the workspace restore process.
4116 mWorkspace.post(new Runnable() {
4117 @Override
4118 public void run() {
4119 mWorkspace.snapToScreenId(screenId);
4120 }
4121 });
4122 sPendingAddItem = null;
4123 }
4124
Sunny Goyal756adbc2015-04-16 15:20:51 -07004125 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004126
4127 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004128 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004129 }
Sunny Goyale26d1002016-06-20 14:52:14 -07004130 if (LauncherAppState.PROFILE_STARTUP) {
4131 Trace.endSection();
4132 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004133 }
4134
Winson Chunga2413752012-04-03 14:22:34 -07004135 private boolean canRunNewAppsAnimation() {
4136 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
Andrew Sapperstein932eb832016-06-30 18:10:09 -07004137 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
Winson Chunga2413752012-04-03 14:22:34 -07004138 }
4139
Winson Chungc9168342013-06-26 14:54:55 -07004140 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
Sunny Goyal5d2fc322015-07-06 22:52:49 -07004141 ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
Winson Chungc9168342013-06-26 14:54:55 -07004142 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4143 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004144 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004145 return bounceAnim;
4146 }
4147
Adam Cohen27772732013-11-11 14:00:56 +00004148 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004149 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004150 }
4151
Tony Wickham55616cd2015-09-23 14:55:17 -07004152 public int getSearchBarHeight() {
4153 if (mLauncherCallbacks != null) {
4154 return mLauncherCallbacks.getSearchBarHeight();
4155 }
4156 return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
4157 }
4158
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004159 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004160 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4161 * multiple calls to bind the same list.)
4162 */
4163 @Thunk ArrayList<AppInfo> mTmpAppsList;
4164 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4165 public void run() {
4166 bindAllApplications(mTmpAppsList);
4167 mTmpAppsList = null;
4168 }
4169 };
4170
4171 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004172 * Add the icons for all apps.
4173 *
4174 * Implementation of the method from LauncherModel.Callbacks.
4175 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004176 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004177 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4178 mTmpAppsList = apps;
4179 return;
4180 }
4181
Winson Chungb745afb2015-03-02 11:51:23 -08004182 if (mAppsView != null) {
4183 mAppsView.setApps(apps);
4184 }
Adam Cohen9211d422014-10-07 18:14:53 -07004185 if (mLauncherCallbacks != null) {
4186 mLauncherCallbacks.bindAllApplications(apps);
4187 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004188 }
4189
4190 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -07004191 * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary
4192 * because LauncherModel's map is updated in the background, while Launcher runs on the UI.
4193 */
4194 @Override
4195 public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) {
4196 mDeepShortcutMap = deepShortcutMapCopy;
4197 if (LOGD) Log.d(TAG, "bindDeepShortcutMap: " + mDeepShortcutMap);
4198 }
4199
Tony Wickham1bce7fd2016-04-28 17:39:03 -07004200 public List<String> getShortcutIdsForItem(ItemInfo info) {
4201 if (!DeepShortcutManager.supportsShortcuts(info)) {
4202 return Collections.EMPTY_LIST;
4203 }
4204 ComponentName component = info.getTargetComponent();
4205 List<String> ids = mDeepShortcutMap.get(new ComponentKey(component, info.user));
4206 return ids == null ? Collections.EMPTY_LIST : ids;
4207 }
4208
Tony Wickhambfbf7f92016-05-19 11:19:39 -07004209 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004210 * A package was updated.
4211 *
4212 * Implementation of the method from LauncherModel.Callbacks.
4213 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004214 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004215 Runnable r = new Runnable() {
4216 public void run() {
4217 bindAppsUpdated(apps);
4218 }
4219 };
4220 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004221 return;
4222 }
4223
Winson Chungb745afb2015-03-02 11:51:23 -08004224 if (mAppsView != null) {
4225 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004226 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004227 }
4228
Sunny Goyal4390ace2014-10-13 11:33:11 -07004229 @Override
4230 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4231 Runnable r = new Runnable() {
4232 public void run() {
4233 bindWidgetsRestored(widgets);
4234 }
4235 };
4236 if (waitUntilResume(r)) {
4237 return;
4238 }
4239 mWorkspace.widgetsRestored(widgets);
4240 }
4241
Joe Onorato9c1289c2009-08-17 11:03:03 -04004242 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004243 * Some shortcuts were updated in the background.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004244 * Implementation of the method from LauncherModel.Callbacks.
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004245 *
4246 * @param updated list of shortcuts which have changed.
4247 * @param removed list of shortcuts which were deleted in the background. This can happen when
4248 * an app gets removed from the system or some of its components are no longer
4249 * available.
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004250 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004251 @Override
4252 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4253 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004254 Runnable r = new Runnable() {
4255 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004256 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004257 }
4258 };
4259 if (waitUntilResume(r)) {
4260 return;
4261 }
4262
Sunny Goyal4390ace2014-10-13 11:33:11 -07004263 if (!updated.isEmpty()) {
4264 mWorkspace.updateShortcuts(updated);
4265 }
4266
4267 if (!removed.isEmpty()) {
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004268 HashSet<ComponentName> removedComponents = new HashSet<>();
4269 HashSet<ShortcutKey> removedDeepShortcuts = new HashSet<>();
4270
Sunny Goyal4390ace2014-10-13 11:33:11 -07004271 for (ShortcutInfo si : removed) {
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004272 if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
Tony Wickhamdef6e472016-08-29 15:17:48 -07004273 removedDeepShortcuts.add(ShortcutKey.fromShortcutInfo(si));
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004274 } else {
4275 removedComponents.add(si.getTargetComponent());
4276 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004277 }
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004278
4279 if (!removedComponents.isEmpty()) {
4280 ItemInfoMatcher matcher = ItemInfoMatcher.ofComponents(removedComponents, user);
4281 mWorkspace.removeItemsByMatcher(matcher);
4282 mDragController.onAppsRemoved(matcher);
4283 }
4284
4285 if (!removedDeepShortcuts.isEmpty()) {
4286 ItemInfoMatcher matcher = ItemInfoMatcher.ofShortcutKeys(removedDeepShortcuts);
4287 mWorkspace.removeItemsByMatcher(matcher);
4288 mDragController.onAppsRemoved(matcher);
4289 }
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004290 }
4291 }
4292
4293 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004294 * Update the state of a package, typically related to install state.
4295 *
4296 * Implementation of the method from LauncherModel.Callbacks.
4297 */
Sunny Goyale755d462014-07-22 13:48:29 -07004298 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004299 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4300 Runnable r = new Runnable() {
4301 public void run() {
4302 bindRestoreItemsChange(updates);
4303 }
4304 };
4305 if (waitUntilResume(r)) {
4306 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004307 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004308
Sunny Goyal756adbc2015-04-16 15:20:51 -07004309 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004310 }
4311
4312 /**
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004313 * A package was uninstalled/updated. We take both the super set of packageNames
Winson Chung83892cc2013-05-01 16:53:33 -07004314 * in addition to specific applications to remove, the reason being that
4315 * this can be called when a package is updated as well. In that scenario,
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004316 * we only remove specific components from the workspace and hotseat, where as
Winson Chung83892cc2013-05-01 16:53:33 -07004317 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004318 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004319 @Override
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004320 public void bindWorkspaceComponentsRemoved(
4321 final HashSet<String> packageNames, final HashSet<ComponentName> components,
4322 final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004323 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004324 public void run() {
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004325 bindWorkspaceComponentsRemoved(packageNames, components, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004326 }
Winson Chungd64d1762013-08-20 14:37:16 -07004327 };
4328 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004329 return;
4330 }
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004331 if (!packageNames.isEmpty()) {
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004332 ItemInfoMatcher matcher = ItemInfoMatcher.ofPackages(packageNames, user);
4333 mWorkspace.removeItemsByMatcher(matcher);
4334 mDragController.onAppsRemoved(matcher);
4335
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004336 }
4337 if (!components.isEmpty()) {
Sunny Goyald3b87ef2016-07-28 12:11:54 -07004338 ItemInfoMatcher matcher = ItemInfoMatcher.ofComponents(components, user);
4339 mWorkspace.removeItemsByMatcher(matcher);
4340 mDragController.onAppsRemoved(matcher);
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004341 }
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004342 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004343
Sunny Goyal3bbbabc2016-03-15 09:16:30 -07004344 @Override
4345 public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) {
4346 Runnable r = new Runnable() {
4347 public void run() {
4348 bindAppInfosRemoved(appInfos);
4349 }
4350 };
4351 if (waitUntilResume(r)) {
4352 return;
Joe Onorato36115782010-06-17 13:28:48 -04004353 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004354
Winson Chungdf95eb12013-10-16 14:57:07 -07004355 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004356 if (mAppsView != null) {
4357 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004358 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004359 }
Joe Onoratobe386092009-11-17 17:32:16 -08004360
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004361 private Runnable mBindWidgetModelRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004362 public void run() {
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004363 bindWidgetsModel(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004364 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004365 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004366
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004367 @Override
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004368 public void bindWidgetsModel(WidgetsModel model) {
4369 if (waitUntilResume(mBindWidgetModelRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004370 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004371 return;
4372 }
4373
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004374 if (mWidgetsView != null && model != null) {
4375 mWidgetsView.addWidgets(model);
4376 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004377 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004378 }
4379
Sunny Goyal2e1efb42016-03-03 16:58:55 -08004380 @Override
4381 public void notifyWidgetProvidersChanged() {
4382 if (mWorkspace.getState().shouldUpdateWidget) {
4383 mModel.refreshAndBindWidgetsAndShortcuts(this, mWidgetsView.isEmpty());
4384 }
4385 }
4386
Winson Chung400438b2011-01-16 17:53:48 -08004387 private int mapConfigurationOriActivityInfoOri(int configOri) {
4388 final Display d = getWindowManager().getDefaultDisplay();
4389 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4390 switch (d.getRotation()) {
4391 case Surface.ROTATION_0:
4392 case Surface.ROTATION_180:
4393 // We are currently in the same basic orientation as the natural orientation
4394 naturalOri = configOri;
4395 break;
4396 case Surface.ROTATION_90:
4397 case Surface.ROTATION_270:
4398 // We are currently in the other basic orientation to the natural orientation
4399 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4400 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4401 break;
4402 }
4403
4404 int[] oriMap = {
4405 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4406 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4407 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4408 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4409 };
4410 // Since the map starts at portrait, we need to offset if this device's natural orientation
4411 // is landscape.
4412 int indexOffset = 0;
4413 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4414 indexOffset = 1;
4415 }
4416 return oriMap[(d.getRotation() + indexOffset) % 4];
4417 }
Adam Cohen446e9402011-09-15 18:21:21 -07004418
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004419 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Winson Chung4b919f82012-05-01 10:44:08 -07004420 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004421 if (mRotationEnabled) {
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004422 if (Utilities.ATLEAST_JB_MR2) {
4423 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4424 } else {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004425 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4426 .getConfiguration().orientation));
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004427 }
Winson Chung4b919f82012-05-01 10:44:08 -07004428 }
4429 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004430
Winson Chung4b919f82012-05-01 10:44:08 -07004431 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004432 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004433 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004434 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004435 } else {
4436 mHandler.postDelayed(new Runnable() {
4437 public void run() {
4438 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4439 }
Sunny Goyal756cd262015-08-20 12:33:21 -07004440 }, RESTORE_SCREEN_ORIENTATION_DELAY);
Winson Chung641d71d2012-04-26 15:58:01 -07004441 }
Winson Chung4b919f82012-05-01 10:44:08 -07004442 }
Winson Chung400438b2011-01-16 17:53:48 -08004443 }
4444
Adam Cohenea90f832014-05-21 15:03:34 -07004445 /**
Adam Cohen432609a2014-03-13 17:03:22 -07004446 * To be overridden by subclasses to indicate that there is an activity to launch
4447 * before showing the standard launcher experience.
4448 */
4449 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004450 if (mLauncherCallbacks != null) {
4451 return mLauncherCallbacks.hasFirstRunActivity();
4452 }
Adam Cohen432609a2014-03-13 17:03:22 -07004453 return false;
4454 }
4455
4456 /**
4457 * To be overridden by subclasses to launch any first run activity
4458 */
4459 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004460 if (mLauncherCallbacks != null) {
4461 return mLauncherCallbacks.getFirstRunActivity();
4462 }
Adam Cohen432609a2014-03-13 17:03:22 -07004463 return null;
4464 }
4465
Winson Chunga6945242014-01-08 14:04:34 -08004466 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004467 return !ActivityManager.isRunningInTestHarness() &&
4468 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004469 }
4470
Adam Cohen432609a2014-03-13 17:03:22 -07004471 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004472 if (shouldRunFirstRunActivity() &&
4473 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004474 Intent firstRunIntent = getFirstRunActivity();
4475 if (firstRunIntent != null) {
4476 startActivity(firstRunIntent);
4477 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004478 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004479 }
4480 }
Adam Cohen432609a2014-03-13 17:03:22 -07004481 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004482 }
4483
4484 private void markFirstRunActivityShown() {
4485 SharedPreferences.Editor editor = mSharedPrefs.edit();
4486 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4487 editor.apply();
4488 }
4489
Hyunyoung Songc001cf52016-07-21 17:32:43 -07004490 private void markAppsViewShown() {
4491 if (mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false)) {
4492 return;
4493 }
4494 mSharedPrefs.edit().putBoolean(APPS_VIEW_SHOWN, true).apply();
4495 }
4496
4497 private boolean shouldShowDiscoveryBounce() {
4498 if (mState != mState.WORKSPACE) {
4499 return false;
4500 }
4501 if (mLauncherCallbacks != null && mLauncherCallbacks.shouldShowDiscoveryBounce()) {
4502 return true;
4503 }
4504 if (!mIsResumeFromActionScreenOff) {
4505 return false;
4506 }
4507 if (mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false)) {
4508 return false;
4509 }
4510 return true;
4511 }
4512
Adam Cohen432609a2014-03-13 17:03:22 -07004513 /**
4514 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4515 * screen that must be displayed and dismissed.
4516 */
4517 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004518 if (mLauncherCallbacks != null) {
4519 return mLauncherCallbacks.hasDismissableIntroScreen();
4520 }
Adam Cohen432609a2014-03-13 17:03:22 -07004521 return false;
4522 }
4523
4524 /**
4525 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4526 */
4527 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004528 if (mLauncherCallbacks != null) {
4529 return mLauncherCallbacks.getIntroScreen();
4530 }
Adam Cohen432609a2014-03-13 17:03:22 -07004531 return null;
4532 }
4533
4534 /**
4535 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4536 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4537 */
4538 private boolean shouldShowIntroScreen() {
4539 return hasDismissableIntroScreen() &&
4540 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4541 }
4542
4543 protected void showIntroScreen() {
4544 View introScreen = getIntroScreen();
4545 changeWallpaperVisiblity(false);
4546 if (introScreen != null) {
4547 mDragLayer.showOverlayView(introScreen);
4548 }
4549 }
4550
Winson Chung5ffd51d2015-06-25 11:36:50 -07004551 // TODO: These method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004552 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Mathew Inwood72fbec12013-11-19 15:45:07 +00004553 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004554 // Called from search suggestion
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004555 UserHandleCompat user = null;
Sunny Goyal9fc953b2015-08-17 12:24:25 -07004556 if (Utilities.ATLEAST_LOLLIPOP) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004557 UserHandle userHandle = appLaunchIntent.getParcelableExtra(Intent.EXTRA_USER);
4558 if (userHandle != null) {
4559 user = UserHandleCompat.fromUser(userHandle);
4560 }
4561 }
4562 return createAppDragInfo(appLaunchIntent, user);
Winson Chung5ffd51d2015-06-25 11:36:50 -07004563 }
4564
4565 // TODO: This method should be a part of LauncherSearchCallback
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004566 public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
Winson Chung5ffd51d2015-06-25 11:36:50 -07004567 if (user == null) {
4568 user = UserHandleCompat.myUserHandle();
4569 }
4570
4571 // Called from search suggestion, add the profile extra to the intent to ensure that we
4572 // can launch it correctly
Kenny Guyed131872014-04-30 03:02:21 +01004573 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004574 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
Kenny Guyed131872014-04-30 03:02:21 +01004575 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004576 return null;
4577 }
Winson Chung5ffd51d2015-06-25 11:36:50 -07004578 return new AppInfo(this, activityInfo, user, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004579 }
4580
Winson Chung5ffd51d2015-06-25 11:36:50 -07004581 // TODO: This method should be a part of LauncherSearchCallback
Mathew Inwood72fbec12013-11-19 15:45:07 +00004582 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4583 Bitmap icon) {
Sunny Goyala1d1bf32015-06-26 13:24:53 -07004584 return new ShortcutInfo(shortcutIntent, caption, caption, icon,
Kenny Guyed131872014-04-30 03:02:21 +01004585 UserHandleCompat.myUserHandle());
4586 }
4587
Winson Chung5ffd51d2015-06-25 11:36:50 -07004588 protected void moveWorkspaceToDefaultScreen() {
4589 mWorkspace.moveToDefaultScreen(false);
4590 }
4591
Winson Chung80baf5a2010-08-09 16:03:15 -07004592 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004593 * Returns a FastBitmapDrawable with the icon, accurately sized.
4594 */
4595 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4596 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4597 d.setFilterBitmap(true);
4598 resizeIconDrawable(d);
4599 return d;
4600 }
4601
4602 /**
4603 * Resizes an icon drawable to the correct icon size.
4604 */
Winson5fbe0742015-09-30 15:33:00 -07004605 public Drawable resizeIconDrawable(Drawable icon) {
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004606 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
Winson5fbe0742015-09-30 15:33:00 -07004607 return icon;
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004608 }
4609
4610 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004611 * Prints out out state for debugging.
4612 */
4613 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004614 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004615 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004616 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4617 Log.d(TAG, "mRestoring=" + mRestoring);
4618 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Joe Onoratobe386092009-11-17 17:32:16 -08004619 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004620 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004621
Daniel Sandler325dc232013-06-05 22:57:57 -04004622 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004623 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004624
4625 @Override
4626 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4627 super.dump(prefix, fd, writer, args);
Sunny Goyala1365452015-10-01 15:46:24 -07004628 // Dump workspace
4629 writer.println(prefix + "Workspace Items");
4630 for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
4631 writer.println(prefix + " Homescreen " + i);
4632
4633 ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
4634 for (int j = 0; j < layout.getChildCount(); j++) {
4635 Object tag = layout.getChildAt(j).getTag();
4636 if (tag != null) {
4637 writer.println(prefix + " " + tag.toString());
4638 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004639 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004640 }
Sunny Goyala1365452015-10-01 15:46:24 -07004641
4642 writer.println(prefix + " Hotseat");
4643 ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets();
4644 for (int j = 0; j < layout.getChildCount(); j++) {
4645 Object tag = layout.getChildAt(j).getTag();
4646 if (tag != null) {
4647 writer.println(prefix + " " + tag.toString());
4648 }
4649 }
4650
Sunny Goyal713edfc2016-05-06 09:58:34 -07004651 try {
4652 FileLog.flushAll(writer);
4653 } catch (Exception e) {
4654 // Ignore
Sunny Goyala1365452015-10-01 15:46:24 -07004655 }
4656
Adam Cohen9211d422014-10-07 18:14:53 -07004657 if (mLauncherCallbacks != null) {
4658 mLauncherCallbacks.dump(prefix, fd, writer, args);
4659 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004660 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004661
Adam Cohen59400422014-03-05 18:07:04 -08004662 public static CustomAppWidget getCustomAppWidget(String name) {
4663 return sCustomAppWidgets.get(name);
4664 }
4665
4666 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4667 return sCustomAppWidgets;
4668 }
4669
Sunny Goyal29538332016-02-18 09:10:19 -08004670 public static List<View> getFolderContents(View icon) {
4671 if (icon instanceof FolderIcon) {
4672 return ((FolderIcon) icon).getFolder().getItemsInReadingOrder();
4673 } else {
4674 return Collections.EMPTY_LIST;
4675 }
4676 }
Sunny Goyal745bad92016-05-02 10:54:12 -07004677
Andrew Sappersteinabef55a2016-06-19 12:49:00 -07004678 public static Launcher getLauncher(Context context) {
4679 if (context instanceof Launcher) {
4680 return (Launcher) context;
4681 }
4682 return ((Launcher) ((ContextWrapper) context).getBaseContext());
4683 }
4684
Sunny Goyal745bad92016-05-02 10:54:12 -07004685 private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener, Runnable {
4686
4687 @Override
4688 public void onSharedPreferenceChanged(
4689 SharedPreferences sharedPreferences, String key) {
4690 if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) {
4691 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
4692 if (!waitUntilResume(this, true)) {
4693 run();
4694 }
4695 }
4696 }
4697
4698 @Override
4699 public void run() {
4700 setOrientation();
4701 }
4702 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004703}