blob: c923c958265388ec18327de3f337396e8e2dc0f4 [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070019import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080020import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070021import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070022import android.animation.ObjectAnimator;
23import android.animation.PropertyValuesHolder;
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;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070044import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen3f9c9712014-10-31 11:48:25 -070052import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070053import android.graphics.Bitmap;
54import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070055import android.graphics.Color;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020064import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080065import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070066import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070067import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040068import android.os.SystemClock;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
Adam Cohenc2d6e892014-10-16 09:49:24 -070086import android.view.ViewStub;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.ViewTreeObserver;
Sunny Goyal651077b2014-06-30 14:15:31 -070088import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080090import android.view.accessibility.AccessibilityEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
93import android.widget.FrameLayout;
94import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080095import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070096import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -070097
Sunny Goyal651077b2014-06-30 14:15:31 -070098import com.android.launcher3.DropTarget.DragObject;
99import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyal83a8f042015-05-19 12:52:12 -0700100import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700101import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100102import com.android.launcher3.compat.LauncherActivityInfoCompat;
103import com.android.launcher3.compat.LauncherAppsCompat;
104import com.android.launcher3.compat.UserHandleCompat;
105import com.android.launcher3.compat.UserManagerCompat;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700106import com.android.launcher3.model.WidgetsModel;
Sunny Goyale2df0622015-04-24 11:27:00 -0700107import com.android.launcher3.util.LongArrayMap;
Adam Cohen091440a2015-03-18 14:16:05 -0700108import com.android.launcher3.util.Thunk;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700109import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700110import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700111import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700112
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.io.DataInputStream;
114import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700115import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700116import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700118import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700120import java.io.PrintWriter;
Chet Haasea8f996d2015-02-17 12:56:04 -0800121import java.lang.reflect.InvocationTargetException;
122import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700123import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700124import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700125import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700126import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700127import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700128import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700129import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000130import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132/**
133 * Default launcher application.
134 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100135public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700136 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungb745afb2015-03-02 11:51:23 -0800137 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener,
138 LauncherStateTransitionAnimation.Callbacks {
Hyunyoung Song4e8fb912015-04-11 15:44:32 -0700139 static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700140 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Winson Chung83f59ab2015-05-05 17:21:58 -0700142 // Temporary flag
143 static final boolean DISABLE_ALL_APPS_SEARCH_INTEGRATION = true;
144
Daniel Sandlerf061f822013-06-27 13:59:36 -0400145 static final boolean PROFILE_STARTUP = false;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700146 static final boolean DEBUG_WIDGETS = true;
Winson Chunga2413752012-04-03 14:22:34 -0700147 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400148 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700149 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700150
Dan Sandlerd5024042014-01-09 15:01:33 -0500151 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
152
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700154 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700155 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700156 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157
Michael Jurka8b805b12012-04-18 14:23:14 -0700158 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700159 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700160
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700161 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
162 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
163 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
164
Mathew Inwood876a8462013-06-14 14:12:41 +0100165 /**
166 * IntentStarter uses request codes starting with this. This must be greater than all activity
167 * request codes used internally.
168 */
169 protected static final int REQUEST_LAST = 100;
170
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
172
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800173 static final int SCREEN_COUNT = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
Michael Jurka0a457bf2012-11-19 14:05:05 -0800175 // To turn on these properties, type
176 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800177 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178
Winson Chung2672ff92012-05-04 16:22:30 -0700179 // The Intent extra that defines whether to ignore the launch animation
180 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400181 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 // Type: int
184 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700185 // Type: int
186 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700188 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
189 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
191 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700192 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700194 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700195 // Type: int
196 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
197 // Type: int
198 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
199 // Type: parcelable
200 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000201 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800202 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000203 // Type: int[]
204 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205
Adam Cohen432609a2014-03-13 17:03:22 -0700206 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800207 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
208
Adam Cohen3ed316a2014-07-23 18:21:20 -0700209 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
210 static final String ACTION_FIRST_LOAD_COMPLETE =
211 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
212
Adam Cohen39a06042013-07-19 14:30:12 -0700213 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700214 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700215
Sunny Goyal594d76d2014-11-06 10:12:54 -0800216 private static final String QSB_WIDGET_ID = "qsb_widget_id";
217 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
218
Winson Chunga6945242014-01-08 14:04:34 -0800219 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
220
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700221 /** The different states that Launcher can be in. */
Winson Chungb745afb2015-03-02 11:51:23 -0800222 enum State { NONE, WORKSPACE, APPS, APPS_SPRING_LOADED, WIDGETS, WIDGETS_SPRING_LOADED };
Adam Cohen091440a2015-03-18 14:16:05 -0700223 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700224 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700225
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700226 private boolean mIsSafeModeEnabled;
227
Adam Cohenc2d6e892014-10-16 09:49:24 -0700228 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
229 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700230 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700231
Joe Onorato9c1289c2009-08-17 11:03:03 -0400232 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700233 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
234 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700235 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000237 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
238 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
239
Winson Chunga2413752012-04-03 14:22:34 -0700240 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700241 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
242 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700243 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700244
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800245 private final BroadcastReceiver mCloseSystemDialogsReceiver
246 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800247 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private LayoutInflater mInflater;
250
Adam Cohen091440a2015-03-18 14:16:05 -0700251 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700252 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800253 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700254 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800255 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700256 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700257
Sunny Goyalffe83f12014-08-14 17:39:34 -0700258 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
Adam Cohen091440a2015-03-18 14:16:05 -0700261 @Thunk ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800262 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800263 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700264
Michael Jurka0280c3b2010-09-17 15:00:07 -0700265 private int[] mTmpAddItemCellCoordinates = new int[2];
266
Winson Chung3d503fb2011-07-13 17:25:49 -0700267 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800268 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700269
Michael Jurka838a4ca2011-02-07 13:33:06 -0800270 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700271
Winson Chungc51db6a2011-10-05 11:44:49 -0700272 private SearchDropTargetBar mSearchDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700273
274 // Main container view for the all apps screen.
Adam Cohen091440a2015-03-18 14:16:05 -0700275 @Thunk AppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700276
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700277 // Main container view and the model for the widget tray screen.
278 @Thunk WidgetsContainerView mWidgetsView;
279 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700280
Winson Chungf0ea4d32011-06-06 14:27:16 -0700281 private boolean mAutoAdvanceRunning = false;
Sunny Goyal594d76d2014-11-06 10:12:54 -0800282 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700285 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
286 // scroll issues (because the workspace may not have been measured yet) and extra work.
287 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
288 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289
290 private SpannableStringBuilder mDefaultKeySsb = null;
291
Adam Cohen091440a2015-03-18 14:16:05 -0700292 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400293
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800294 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 private boolean mRestoring;
296 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700297 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298
Michael Jurka1e2f4652013-07-08 18:03:46 -0700299 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700300 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
301
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302 private Bundle mSavedInstanceState;
303
Joe Onorato9c1289c2009-08-17 11:03:03 -0400304 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800305 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700306 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800307 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700308 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800309 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400310
Adam Cohen091440a2015-03-18 14:16:05 -0700311 @Thunk static LocaleConfiguration sLocaleConfiguration = null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700312
Sunny Goyale2df0622015-04-24 11:27:00 -0700313 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700314
Adam Cohen61f560d2013-09-30 15:58:20 -0700315 private View.OnTouchListener mHapticFeedbackTouchListener;
316
Adam Cohended9f8d2010-11-03 13:25:16 -0700317 // Related to the auto-advancing of widgets
318 private final int ADVANCE_MSG = 1;
319 private final int mAdvanceInterval = 20000;
320 private final int mAdvanceStagger = 250;
321 private long mAutoAdvanceSentTime;
322 private long mAutoAdvanceTimeLeft = -1;
Adam Cohen091440a2015-03-18 14:16:05 -0700323 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
Adam Cohended9f8d2010-11-03 13:25:16 -0700324 new HashMap<View, AppWidgetProviderInfo>();
325
Winson Chung400438b2011-01-16 17:53:48 -0800326 // Determines how long to wait after a rotation before restoring the screen orientation to
327 // match the sensor state.
328 private final int mRestoreScreenOrientationDelay = 500;
329
Adam Cohen091440a2015-03-18 14:16:05 -0700330 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700331
Adam Cohen1462de32012-07-24 22:34:36 -0700332 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700333 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700334
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700335 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700336 static Date sDateStamp = new Date();
337 static DateFormat sDateFormat =
338 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
339 static long sRunStart = System.currentTimeMillis();
340 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700341
Winson Chung46353de2012-02-16 14:05:10 -0800342 // We only want to get the SharedPreferences once since it does an FS stat each time we get
343 // it from the context.
344 private SharedPreferences mSharedPrefs;
345
Winson Chungf0c6ae02012-03-21 16:10:31 -0700346 // Holds the page that we need to animate to, and the icon views that we need to animate up
347 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700348 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700349 private Bitmap mFolderIconBitmap;
350 private Canvas mFolderIconCanvas;
351 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700352
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700353 private DeviceProfile mDeviceProfile;
354
Winson Chung13eb5272015-05-11 16:30:13 -0700355 // This is set to the view that launched the activity that navigated the user away from
356 // launcher. Since there is no callback for when the activity has finished launching, enable
357 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800358 private BubbleTextView mWaitingForResume;
359
Adam Cohen59400422014-03-05 18:07:04 -0800360 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
361 new HashMap<String, CustomAppWidget>();
362
363 private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
364 static {
365 if (ENABLE_CUSTOM_WIDGET_TEST) {
366 sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
367 }
368 }
369
Chet Haasea8f996d2015-02-17 12:56:04 -0800370 // TODO: remove this field and call method directly when Launcher3 can depend on M APIs
371 private static Method sClipRevealMethod = null;
372 static {
373 Class<?> activityOptionsClass = ActivityOptions.class;
374 try {
375 sClipRevealMethod = activityOptionsClass.getDeclaredMethod("makeClipRevealAnimation",
376 View.class, int.class, int.class, int.class, int.class);
377 } catch (Exception e) {
378 // Earlier version
379 }
380 }
381
Adam Cohen091440a2015-03-18 14:16:05 -0700382 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700383 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700384 if (mWorkspace != null) {
385 mWorkspace.buildPageHardwareLayers();
386 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700387 }
388 };
389
Adam Cohendb364c32014-05-20 14:23:40 -0700390 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800391
Adam Cohen091440a2015-03-18 14:16:05 -0700392 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800393 int requestCode;
394 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700395 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700396 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800397 int cellX;
398 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700399 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800400 }
401
Daniel Sandlerff02d492013-08-05 02:12:05 -0400402 private Stats mStats;
403
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700404 FocusIndicatorView mFocusHandler;
405
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 @Override
407 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700408 if (DEBUG_STRICT_MODE) {
409 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
410 .detectDiskReads()
411 .detectDiskWrites()
412 .detectNetwork() // or .detectAll() for all detectable problems
413 .penaltyLog()
414 .build());
415 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
416 .detectLeakedSqlLiteObjects()
417 .detectLeakedClosableObjects()
418 .penaltyLog()
419 .penaltyDeath()
420 .build());
421 }
422
Adam Cohen9211d422014-10-07 18:14:53 -0700423 if (mLauncherCallbacks != null) {
424 mLauncherCallbacks.preOnCreate();
425 }
426
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400428
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400429 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400430 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700431 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700432
Adam Cohen2e6da152015-05-06 11:42:25 -0700433 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700434 mDeviceProfile = getResources().getConfiguration().orientation
435 == Configuration.ORIENTATION_LANDSCAPE ?
436 app.getInvariantDeviceProfile().landscapeProfile
437 : app.getInvariantDeviceProfile().portraitProfile;
438
439 // TODO: Move this to icon cache.
440 Utilities.setIconSize(mDeviceProfile.iconSizePx);
Winson Chung5f8afe62013-08-12 16:19:28 -0700441
442 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400443 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700444 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700445 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800446 mModel = app.setLauncher(this);
447 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700448
Joe Onorato41a12d22009-10-31 18:30:00 -0400449 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 mInflater = getLayoutInflater();
Winson Chungb745afb2015-03-02 11:51:23 -0800451 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);
Romain Guycbb89e42009-06-08 15:52:54 -0700452
Daniel Sandlerff02d492013-08-05 02:12:05 -0400453 mStats = new Stats(this);
454
Sunny Goyalffe83f12014-08-14 17:39:34 -0700455 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700456
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700457 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
458 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700459
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700460 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
461 // this also ensures that any synchronous binding below doesn't re-trigger another
462 // LauncherModel load.
463 mPaused = false;
464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200466 android.os.Debug.startMethodTracing(
467 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800468 }
469
470 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700472
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800473 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700474 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800475
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800476 registerContentObservers();
477
Joe Onorato7c312c12009-08-13 21:36:53 -0700478 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700479
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800480 mSavedState = savedInstanceState;
481 restoreState(mSavedState);
482
483 if (PROFILE_STARTUP) {
484 android.os.Debug.stopMethodTracing();
485 }
486
487 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700488 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700489 // If the user leaves launcher, then we should just load items asynchronously when
490 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700491 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700492 } else {
493 // We only load the page synchronously if the user rotates (or triggers a
494 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700495 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700496 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800497 }
498
499 // For handling default keys
500 mDefaultKeySsb = new SpannableStringBuilder();
501 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800502
503 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
504 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800505
Adam Cohenf9426d52012-06-04 17:26:21 -0700506 // On large interfaces, we want the screen to auto-rotate based on the current orientation
507 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700508
Adam Cohen9211d422014-10-07 18:14:53 -0700509 if (mLauncherCallbacks != null) {
510 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700511 if (mLauncherCallbacks.hasLauncherOverlay()) {
512 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700513 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
514 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
515 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700516 mWorkspace.setLauncherOverlay(mLauncherOverlay);
517 }
Adam Cohen9211d422014-10-07 18:14:53 -0700518 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700519
520 if (shouldShowIntroScreen()) {
521 showIntroScreen();
522 } else {
523 showFirstRunActivity();
524 showFirstRunClings();
525 }
Adam Cohen9211d422014-10-07 18:14:53 -0700526 }
527
528 private LauncherCallbacks mLauncherCallbacks;
529
530 public void onPostCreate(Bundle savedInstanceState) {
531 super.onPostCreate(savedInstanceState);
532 if (mLauncherCallbacks != null) {
533 mLauncherCallbacks.onPostCreate(savedInstanceState);
534 }
535 }
536
537 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
538 mLauncherCallbacks = callbacks;
Winson Chung0f785722015-04-08 10:27:49 -0700539 mLauncherCallbacks.setLauncherAppsCallback(new Launcher.LauncherAppsCallbacks() {
540 @Override
541 public void onAllAppsBoundsChanged(Rect bounds) {
Winson Chungcd99cd32015-04-29 11:03:24 -0700542 if (LOGD) {
543 Log.d(TAG, "onAllAppsBoundsChanged(Rect): " + bounds);
544 }
Winson Chung94804152015-05-08 13:06:44 -0700545 mAppsView.setFixedBounds(bounds);
546 mWidgetsView.setFixedBounds(bounds);
Winson Chung0f785722015-04-08 10:27:49 -0700547 }
548
549 @Override
550 public void dismissAllApps() {
Winson Chung83f59ab2015-05-05 17:21:58 -0700551 if (!DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
552 // Dismiss All Apps if we aren't already paused/invisible
553 if (!mPaused) {
554 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true,
555 null /* onCompleteRunnable */, false /* notifyLauncherCallbacks */);
556 }
Winson Chungcd99cd32015-04-29 11:03:24 -0700557 }
Winson Chung0f785722015-04-08 10:27:49 -0700558 }
559 });
Adam Cohen9211d422014-10-07 18:14:53 -0700560 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700561 }
562
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700563 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700564 public void onLauncherProviderChange() {
565 if (mLauncherCallbacks != null) {
566 mLauncherCallbacks.onLauncherProviderChange();
567 }
568 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700569
Adam Cohen9211d422014-10-07 18:14:53 -0700570 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700571 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700572 if (mLauncherCallbacks != null) {
573 return mLauncherCallbacks.hasCustomContentToLeft();
574 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700575 return false;
576 }
577
Dave Hawkeya8881582013-09-17 15:55:33 -0600578 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500579 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600580 * {@link #addToCustomContentPage}. This will only be invoked if
581 * {@link #hasCustomContentToLeft()} is {@code true}.
582 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500583 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700584 if (mLauncherCallbacks != null) {
585 mLauncherCallbacks.populateCustomContentContainer();
586 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600587 }
588
589 /**
590 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
591 * ensure the custom content page is added or removed if necessary.
592 */
593 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600594 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600595 // Not bound yet, wait for bindScreens to be called.
596 return;
597 }
598
599 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
600 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500601 mWorkspace.createCustomContentContainer();
602 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600603 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
604 mWorkspace.removeCustomContentPage();
605 }
606 }
607
Adam Cohen091440a2015-03-18 14:16:05 -0700608 @Thunk void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700609 if (sLocaleConfiguration == null) {
610 new AsyncTask<Void, Void, LocaleConfiguration>() {
611 @Override
612 protected LocaleConfiguration doInBackground(Void... unused) {
613 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
614 readConfiguration(Launcher.this, localeConfiguration);
615 return localeConfiguration;
616 }
617
618 @Override
619 protected void onPostExecute(LocaleConfiguration result) {
620 sLocaleConfiguration = result;
621 checkForLocaleChange(); // recursive, but now with a locale configuration
622 }
623 }.execute();
624 return;
625 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700626
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800627 final Configuration configuration = getResources().getConfiguration();
628
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700629 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 final String locale = configuration.locale.toString();
631
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700632 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633 final int mcc = configuration.mcc;
634
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700635 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800636 final int mnc = configuration.mnc;
637
Romain Guy84f296c2009-11-04 15:00:44 -0800638 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800639
Romain Guy84f296c2009-11-04 15:00:44 -0800640 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700641 sLocaleConfiguration.locale = locale;
642 sLocaleConfiguration.mcc = mcc;
643 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700644
Joe Onorato0589f0f2010-02-08 13:44:00 -0800645 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700646
647 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100648 new AsyncTask<Void, Void, Void>() {
649 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700650 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100651 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700652 }
Michael Jurka43467462013-11-14 12:03:58 +0100653 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700654 }
655 }
656
Adam Cohen091440a2015-03-18 14:16:05 -0700657 @Thunk static class LocaleConfiguration {
Romain Guy98d01652009-06-30 16:21:04 -0700658 public String locale;
659 public int mcc = -1;
660 public int mnc = -1;
661 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700662
Adam Cohen091440a2015-03-18 14:16:05 -0700663 @Thunk static void readConfiguration(Context context, LocaleConfiguration configuration) {
Romain Guy98d01652009-06-30 16:21:04 -0700664 DataInputStream in = null;
665 try {
Helena Josol28db2802014-10-09 17:04:09 +0100666 in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
Romain Guy98d01652009-06-30 16:21:04 -0700667 configuration.locale = in.readUTF();
668 configuration.mcc = in.readInt();
669 configuration.mnc = in.readInt();
670 } catch (FileNotFoundException e) {
671 // Ignore
672 } catch (IOException e) {
673 // Ignore
674 } finally {
675 if (in != null) {
676 try {
677 in.close();
678 } catch (IOException e) {
679 // Ignore
680 }
681 }
682 }
683 }
684
Adam Cohen091440a2015-03-18 14:16:05 -0700685 @Thunk static void writeConfiguration(Context context, LocaleConfiguration configuration) {
Romain Guy98d01652009-06-30 16:21:04 -0700686 DataOutputStream out = null;
687 try {
Helena Josol4fbbb3e2014-10-06 16:06:46 +0100688 out = new DataOutputStream(context.openFileOutput(
Helena Josol28db2802014-10-09 17:04:09 +0100689 LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE));
Romain Guy98d01652009-06-30 16:21:04 -0700690 out.writeUTF(configuration.locale);
691 out.writeInt(configuration.mcc);
692 out.writeInt(configuration.mnc);
693 out.flush();
694 } catch (FileNotFoundException e) {
695 // Ignore
696 } catch (IOException e) {
697 //noinspection ResultOfMethodCallIgnored
Helena Josol28db2802014-10-09 17:04:09 +0100698 context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete();
Romain Guy98d01652009-06-30 16:21:04 -0700699 } finally {
700 if (out != null) {
701 try {
702 out.close();
703 } catch (IOException e) {
704 // Ignore
705 }
706 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 }
708 }
709
Anton Hanssona2f665f2013-09-26 12:18:32 +0100710 public Stats getStats() {
711 return mStats;
712 }
713
Bjorn Bringertc459e522013-06-07 19:36:01 +0100714 public LayoutInflater getInflater() {
715 return mInflater;
716 }
717
Hyunyoung Song3f471442015-04-08 19:01:34 -0700718 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700719 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
720 // that is subsequently removed from the workspace in startBinding().
721 return !mModel.isLoadingWorkspace();
722 }
723
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800724 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000725 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100726 if (Build.VERSION.SDK_INT >= 17) {
727 return View.generateViewId();
728 } else {
729 // View.generateViewId() is not available. The following fallback logic is a copy
730 // of its implementation.
731 for (;;) {
732 final int result = sNextGeneratedId.get();
733 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
734 int newValue = result + 1;
735 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
736 if (sNextGeneratedId.compareAndSet(result, newValue)) {
737 return result;
738 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000739 }
740 }
741 }
742
743 public int getViewIdForItem(ItemInfo info) {
744 // This cast is safe given the > 2B range for int.
745 int itemId = (int) info.id;
746 if (mItemIdToViewId.containsKey(itemId)) {
747 return mItemIdToViewId.get(itemId);
748 }
749 int viewId = generateViewId();
750 mItemIdToViewId.put(itemId, viewId);
751 return viewId;
752 }
753
754 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700755 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
756 * a configuration step, this allows the proper animations to run after other transitions.
757 */
Adam Cohendb364c32014-05-20 14:23:40 -0700758 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700759 long screenId = args.screenId;
760 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
761 // When the screen id represents an actual screen (as opposed to a rank) we make sure
762 // that the drop page actually exists.
763 screenId = ensurePendingDropLayoutExists(args.screenId);
764 }
Adam Cohendb364c32014-05-20 14:23:40 -0700765
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800766 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800767 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700768 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700769 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700770 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800771 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700772 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700773 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700774 case REQUEST_RECONFIGURE_APPWIDGET:
775 completeRestoreAppWidget(args.appWidgetId);
776 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800777 }
Michael Jurka27614d22012-04-02 06:40:22 -0700778 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
779 // if you turned the screen off and then back while in All Apps, Launcher would not
780 // return to the workspace. Clearing mAddInfo.container here fixes this issue
781 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700782 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800783 }
784
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800785 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700786 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700787 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700788 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700789 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800790 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700791
Adam Cohenad4e15c2013-10-17 16:21:35 -0700792 Runnable exitSpringLoaded = new Runnable() {
793 @Override
794 public void run() {
795 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
796 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
797 }
798 };
799
Michael Jurka8b805b12012-04-18 14:23:14 -0700800 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700801 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700802 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
803 if (resultCode == RESULT_CANCELED) {
804 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700805 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700806 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700807 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800808 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700809 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700810 }
811 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200812 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
813 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -0700814 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200815 }
816 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700817 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200818
Adam Cohened66b2b2012-01-23 17:28:51 -0800819 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700820 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700821
Adam Cohendb364c32014-05-20 14:23:40 -0700822 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800823 // We have special handling for widgets
824 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800825 final int appWidgetId;
826 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
827 : -1;
828 if (widgetId < 0) {
829 appWidgetId = pendingAddWidgetId;
830 } else {
831 appWidgetId = widgetId;
832 }
833
Adam Cohenad4e15c2013-10-17 16:21:35 -0700834 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800835 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700836 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
837 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700838 result = RESULT_CANCELED;
839 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700840 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700841 @Override
842 public void run() {
843 exitSpringLoadedDragModeDelayed(false, 0, null);
844 }
845 };
Adam Cohendb364c32014-05-20 14:23:40 -0700846 if (workspaceLocked) {
847 // No need to remove the empty screen if we're mid-binding, as the
848 // the bind will not add the empty screen.
849 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
850 } else {
851 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
852 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
853 }
Winson Chung5aaab772012-04-27 15:24:02 -0700854 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700855 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700856 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
857 // When the screen id represents an actual screen (as opposed to a rank)
858 // we make sure that the drop page actually exists.
859 mPendingAddInfo.screenId =
860 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
861 }
Adam Cohendb364c32014-05-20 14:23:40 -0700862 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
863
864 dropLayout.setDropPending(true);
865 final Runnable onComplete = new Runnable() {
866 @Override
867 public void run() {
868 completeTwoStageWidgetDrop(resultCode, appWidgetId);
869 dropLayout.setDropPending(false);
870 }
871 };
872 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
873 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
874 } else {
875 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
876 mPendingAddInfo);
877 sPendingAddItem = args;
878 }
Winson Chung5aaab772012-04-27 15:24:02 -0700879 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800880 return;
881 }
882
Sunny Goyalff572272014-07-23 13:58:07 -0700883 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
884 if (resultCode == RESULT_OK) {
885 // Update the widget view.
886 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
887 pendingAddWidgetId, mPendingAddInfo);
888 if (workspaceLocked) {
889 sPendingAddItem = args;
890 } else {
891 completeAdd(args);
892 }
893 }
894 // Leave the widget in the pending state if the user canceled the configure.
895 return;
896 }
897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 // The pattern used here is that a user PICKs a specific application,
899 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700900
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
902 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700903 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700904 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
905 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800906 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700907 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800908 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700909 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700910 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
911 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800912 }
Adam Cohen00074722013-10-11 17:46:09 -0700913 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700914 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700915 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800917 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800918
919 }
920
921 @Override
922 protected void onActivityResult(
923 final int requestCode, final int resultCode, final Intent data) {
924 handleActivityResult(requestCode, resultCode, data);
925 if (mLauncherCallbacks != null) {
926 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
927 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800928 }
929
Adam Cohendb364c32014-05-20 14:23:40 -0700930 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
931 appWidgetId, ItemInfo info) {
932 PendingAddArguments args = new PendingAddArguments();
933 args.requestCode = requestCode;
934 args.intent = data;
935 args.container = info.container;
936 args.screenId = info.screenId;
937 args.cellX = info.cellX;
938 args.cellY = info.cellY;
939 args.appWidgetId = appWidgetId;
940 return args;
941 }
942
943 /**
944 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
945 *
946 * @param screenId the screen id to check
947 * @return the new screen, or screenId if it exists
948 */
949 private long ensurePendingDropLayoutExists(long screenId) {
950 CellLayout dropLayout =
951 (CellLayout) mWorkspace.getScreenWithId(screenId);
952 if (dropLayout == null) {
953 // it's possible that the add screen was removed because it was
954 // empty and a re-bind occurred
955 mWorkspace.addExtraEmptyScreen();
956 return mWorkspace.commitExtraEmptyScreen();
957 } else {
958 return screenId;
959 }
960 }
961
Adam Cohen091440a2015-03-18 14:16:05 -0700962 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700963 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700964 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800965 Runnable onCompleteRunnable = null;
966 int animationType = 0;
967
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700968 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800969 if (resultCode == RESULT_OK) {
970 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
971 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700972 mPendingAddWidgetInfo);
973 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800974 onCompleteRunnable = new Runnable() {
975 @Override
976 public void run() {
977 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700978 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700979 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
980 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800981 }
982 };
983 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800984 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800985 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800986 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700987 if (mDragLayer.getAnimatedView() != null) {
988 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
989 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
990 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700991 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700992 // The animated view may be null in the case of a rotation during widget configuration
993 onCompleteRunnable.run();
994 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995 }
996
997 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700998 protected void onStop() {
999 super.onStop();
1000 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -07001001
1002 if (mLauncherCallbacks != null) {
1003 mLauncherCallbacks.onStop();
1004 }
Michael Jurkacd496d72013-04-11 11:32:45 -07001005 }
1006
1007 @Override
1008 protected void onStart() {
1009 super.onStart();
1010 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -07001011
1012 if (mLauncherCallbacks != null) {
1013 mLauncherCallbacks.onStart();
1014 }
Michael Jurkacd496d72013-04-11 11:32:45 -07001015 }
1016
1017 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001018 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +02001019 long startTime = 0;
1020 if (DEBUG_RESUME_TIME) {
1021 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -04001022 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +02001023 }
Adam Cohen9211d422014-10-07 18:14:53 -07001024
1025 if (mLauncherCallbacks != null) {
1026 mLauncherCallbacks.preOnResume();
1027 }
1028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001030
Winson Chung4a2afa32012-07-19 14:53:05 -07001031 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001032 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001033 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001034 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001035 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001036 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001037 // view after launching an app, as they may be depending on the UI to be static to
1038 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -07001039 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung13eb5272015-05-11 16:30:13 -07001040 !launchedFromApp /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08001041 } else if (mOnResumeState == State.WIDGETS) {
1042 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001043 }
1044 mOnResumeState = State.NONE;
1045
Winson Chungcd99cd32015-04-29 11:03:24 -07001046 // Restore the apps state if we are in all apps
Winson Chung4ac30062015-05-08 17:34:17 -07001047 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
1048 // Otherwise, notify the callbacks if we are in all apps mode
1049 if (mState == State.APPS) {
1050 if (mLauncherCallbacks != null) {
1051 mLauncherCallbacks.onAllAppsShown();
1052 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001053 }
1054 }
1055
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001056 // Background was set to gradient in onPause(), restore to transparent if in all apps.
1057 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_TRANSPARENT
1058 : WORKSPACE_BACKGROUND_GRADIENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001059
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001060 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001061 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001062 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001063 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001064 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001065 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001067 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001068 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1069 // execute them here
1070 long startTimeCallbacks = 0;
1071 if (DEBUG_RESUME_TIME) {
1072 startTimeCallbacks = System.currentTimeMillis();
1073 }
1074
Michael Jurka1e2f4652013-07-08 18:03:46 -07001075 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1076 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001077 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001078 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001079 if (DEBUG_RESUME_TIME) {
1080 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1081 (System.currentTimeMillis() - startTimeCallbacks));
1082 }
Michael Jurka447bf842013-05-15 14:52:15 +02001083 }
Michael Jurka54554252013-08-01 12:52:23 +02001084 if (mOnResumeCallbacks.size() > 0) {
1085 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1086 mOnResumeCallbacks.get(i).run();
1087 }
1088 mOnResumeCallbacks.clear();
1089 }
Winson Chunge4e50662012-01-23 14:45:13 -08001090
1091 // Reset the pressed state of icons that were locked in the press state while activities
1092 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001093 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001094 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001095 mWaitingForResume.setStayPressed(false);
1096 }
Winson Chung82963d52013-10-09 11:20:57 -07001097
Adam Cohen06dff352012-06-01 17:17:08 -07001098 // It is possible that widgets can receive updates while launcher is not in the foreground.
1099 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1100 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1101 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001102 getWorkspace().reinflateWidgetsIfNecessary();
Sunny Goyal22235bc2015-04-03 09:23:43 -07001103 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001104
Michael Jurka447bf842013-05-15 14:52:15 +02001105 if (DEBUG_RESUME_TIME) {
1106 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1107 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001108
1109 if (mWorkspace.getCustomContentCallbacks() != null) {
1110 // If we are resuming and the custom content is the current page, we call onShow().
1111 // It is also poassible that onShow will instead be called slightly after first layout
1112 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1113 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001114 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001115 }
1116 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001117 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001118 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001119
Sunny Goyal756adbc2015-04-16 15:20:51 -07001120 if (!isWorkspaceLoading()) {
1121 // Process any items that were added while Launcher was away.
1122 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1123 }
Adam Cohen9211d422014-10-07 18:14:53 -07001124
1125 if (mLauncherCallbacks != null) {
1126 mLauncherCallbacks.onResume();
1127 }
Adam Cohen06dff352012-06-01 17:17:08 -07001128 }
1129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001131 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001132 // Ensure that items added to Launcher are queued until Launcher returns
1133 InstallShortcutReceiver.enableInstallQueue();
1134
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001135 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001136 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001137 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001138 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001139
1140 // We call onHide() aggressively. The custom content callbacks should be able to
1141 // debounce excess onHide calls.
1142 if (mWorkspace.getCustomContentCallbacks() != null) {
1143 mWorkspace.getCustomContentCallbacks().onHide();
1144 }
Romain Guycbb89e42009-06-08 15:52:54 -07001145
Adam Cohen9211d422014-10-07 18:14:53 -07001146 if (mLauncherCallbacks != null) {
1147 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001148 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001149 }
1150
1151 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001152 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1153 // by a onResume or by scrolling otherwise.
1154 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001155
1156 // Custom content is completely hidden
1157 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001158
1159 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1160 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001161
1162 // Indicates whether the user is allowed to scroll away from the custom content.
1163 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001164 }
1165
Adam Cohenc2d6e892014-10-16 09:49:24 -07001166 public interface LauncherOverlay {
1167
1168 /**
1169 * Touch interaction leading to overscroll has begun
1170 */
1171 public void onScrollInteractionBegin();
1172
1173 /**
1174 * Touch interaction related to overscroll has ended
1175 */
1176 public void onScrollInteractionEnd();
1177
1178 /**
1179 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1180 * screen (or in the case of RTL, the rightmost screen).
1181 */
1182 public void onScrollChange(int progress, boolean rtl);
1183
1184 /**
1185 * Screen has stopped scrolling
1186 */
1187 public void onScrollSettled();
1188
1189 /**
1190 * This method can be called by the Launcher in order to force the LauncherOverlay
1191 * to exit fully immersive mode.
1192 */
1193 public void forceExitFullImmersion();
1194 }
1195
Winson Chung0f785722015-04-08 10:27:49 -07001196 public interface LauncherAppsCallbacks {
1197 /**
1198 * Updates launcher to the available space that AllApps can take so as not to overlap with
1199 * any other views.
1200 */
1201 public void onAllAppsBoundsChanged(Rect bounds);
1202
1203 /**
1204 * Called to dismiss all apps if it is showing.
1205 */
1206 public void dismissAllApps();
1207 }
1208
Adam Cohenc2d6e892014-10-16 09:49:24 -07001209 public interface LauncherOverlayCallbacks {
1210 /**
1211 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1212 * however it doesn't modify any state within the launcher.
1213 */
1214 public boolean canEnterFullImmersion();
1215
1216 /**
1217 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1218 * eg. by occupying the full screen and handling all touch events.
1219 *
1220 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1221 * case, Launcher will modify any necessary state and assumes the overlay is
1222 * handling all interaction. If false, the LauncherOverlay should cancel any
1223 *
1224 */
1225 public boolean enterFullImmersion();
1226
1227 /**
1228 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1229 * full control over UI and state.
1230 */
1231 public void exitFullImmersion();
1232 }
1233
1234 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1235
1236 @Override
1237 public boolean canEnterFullImmersion() {
1238 return mState == State.WORKSPACE;
1239 }
1240
1241 @Override
1242 public boolean enterFullImmersion() {
1243 if (mState == State.WORKSPACE) {
1244 // When fully immersed, disregard any touches which fall through.
1245 mDragLayer.setBlockTouch(true);
1246 return true;
1247 }
1248 return false;
1249 }
1250
1251 @Override
1252 public void exitFullImmersion() {
1253 mDragLayer.setBlockTouch(false);
1254 }
1255 }
1256
Jorim Jaggid017f882014-01-14 17:08:48 -08001257 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001258 if (mLauncherCallbacks != null) {
1259 return mLauncherCallbacks.hasSettings();
1260 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001261 return false;
1262 }
1263
Adam Cohen9211d422014-10-07 18:14:53 -07001264 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001265 CustomContentCallbacks callbacks, String description) {
1266 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001267 }
1268
Adam Cohenedb40762013-07-18 16:45:45 -07001269 // The custom content needs to offset its content to account for the QSB
1270 public int getTopOffsetForCustomContent() {
1271 return mWorkspace.getPaddingTop();
1272 }
1273
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001274 @Override
1275 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001276 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001277 if (mModel.isCurrentCallbacks(this)) {
1278 mModel.stopLoader();
1279 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001280 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1281
Romain Guy13c2e7b2010-03-10 19:45:00 -08001282 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001283 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001284
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001285 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001286 @Override
1287 public void onWindowFocusChanged(boolean hasFocus) {
1288 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001289 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001290
1291 if (mLauncherCallbacks != null) {
1292 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1293 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001294 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001295
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 private boolean acceptFilter() {
1297 final InputMethodManager inputManager = (InputMethodManager)
1298 getSystemService(Context.INPUT_METHOD_SERVICE);
1299 return !inputManager.isFullscreenMode();
1300 }
1301
1302 @Override
1303 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001304 final int uniChar = event.getUnicodeChar();
1305 final boolean handled = super.onKeyDown(keyCode, event);
1306 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1307 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1309 keyCode, event);
1310 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001311 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001312 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001313 // showSearchDialog()
1314 // If there are multiple keystrokes before the search dialog takes focus,
1315 // onSearchRequested() will be called for every keystroke,
1316 // but it is idempotent, so it's fine.
1317 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 }
1319 }
1320
Joe Onorato8a9625e2010-01-28 15:55:35 -08001321 // Eat the long press event so the keyboard doesn't come up.
1322 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1323 return true;
1324 }
1325
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 return handled;
1327 }
1328
Karl Rosaen138a0412009-04-23 19:00:21 -07001329 private String getTypedText() {
1330 return mDefaultKeySsb.toString();
1331 }
1332
1333 private void clearTypedText() {
1334 mDefaultKeySsb.clear();
1335 mDefaultKeySsb.clearSpans();
1336 Selection.setSelection(mDefaultKeySsb, 0);
1337 }
1338
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001340 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1341 * State
1342 */
1343 private static State intToState(int stateOrdinal) {
1344 State state = State.WORKSPACE;
1345 final State[] stateValues = State.values();
1346 for (int i = 0; i < stateValues.length; i++) {
1347 if (stateValues[i].ordinal() == stateOrdinal) {
1348 state = stateValues[i];
1349 break;
1350 }
1351 }
1352 return state;
1353 }
1354
1355 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 * Restores the previous state, if it exists.
1357 *
1358 * @param savedState The previous state.
1359 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001360 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 private void restoreState(Bundle savedState) {
1362 if (savedState == null) {
1363 return;
1364 }
1365
Michael Jurka883f55b2010-10-21 15:47:14 -07001366 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001367 if (state == State.APPS || state == State.WIDGETS) {
1368 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001369 }
1370
Adam Cohen21cd0022013-10-09 18:57:02 -07001371 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1372 PagedView.INVALID_RESTORE_PAGE);
1373 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001374 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 }
1376
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001378 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001379
Winson Chung3d503fb2011-07-13 17:25:49 -07001380 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1381 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001382 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001383 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1384 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001385 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1386 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Adam Cohenb823ae42015-03-27 18:07:52 -07001387 AppWidgetProviderInfo info = savedState.getParcelable(
1388 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001389 mPendingAddWidgetInfo = info == null ?
1390 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1391
Adam Cohen4637b5a2013-11-04 18:21:24 -08001392 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001393 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394 mRestoring = true;
1395 }
1396
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001397 mItemIdToViewId = (HashMap<Integer, Integer>)
1398 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 }
1400
1401 /**
1402 * Finds all the views we need and configure them properly.
1403 */
1404 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001405 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001406
Craig Mautner360310b2012-10-26 15:13:08 -07001407 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001408 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001409 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1410 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001411 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001412 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001413
John Spurlock77e1f472013-09-11 10:09:51 -04001414 mLauncherView.setSystemUiVisibility(
1415 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001416 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417
Winson Chung4c98d922011-05-31 16:50:48 -07001418 // Setup the drag layer
1419 mDragLayer.setup(this, dragController);
1420
Winson Chung3d503fb2011-07-13 17:25:49 -07001421 // Setup the hotseat
1422 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1423 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001424 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001425 }
1426
Jorim Jaggid017f882014-01-14 17:08:48 -08001427 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001428 View widgetButton = findViewById(R.id.widget_button);
1429 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001430 @Override
1431 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001432 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001433 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001434 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001435 }
1436 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001437 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1438
1439 View wallpaperButton = findViewById(R.id.wallpaper_button);
1440 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001441 @Override
1442 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001443 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001444 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001445 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001446 }
1447 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001448 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1449
1450 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001451 if (hasSettings()) {
1452 settingsButton.setOnClickListener(new OnClickListener() {
1453 @Override
1454 public void onClick(View arg0) {
1455 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001456 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001457 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001458 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001459 });
1460 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1461 } else {
1462 settingsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001463 }
1464
Adam Cohendbdff6b2013-09-18 19:09:15 -07001465 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001466
Winson Chung4c98d922011-05-31 16:50:48 -07001467 // Setup the workspace
1468 mWorkspace.setHapticFeedbackEnabled(false);
1469 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001470 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001471 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001472
Winson Chungf0ea4d32011-06-06 14:27:16 -07001473 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001474 mSearchDropTargetBar = (SearchDropTargetBar)
1475 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001476
Winson Chungb745afb2015-03-02 11:51:23 -08001477 // Setup Apps
1478 mAppsView = (AppsContainerView) findViewById(R.id.apps_view);
Winson Chung83f59ab2015-05-05 17:21:58 -07001479 if (isAllAppsSearchOverridden()) {
1480 mAppsView.hideHeaderBar();
Winson Chung0f785722015-04-08 10:27:49 -07001481 }
Winson Chungb745afb2015-03-02 11:51:23 -08001482
Winson Chungf0ea4d32011-06-06 14:27:16 -07001483 // Setup AppsCustomize
Hyunyoung Song3f471442015-04-08 19:01:34 -07001484 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001485
Winson Chung3d503fb2011-07-13 17:25:49 -07001486 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001487 dragController.setDragScoller(mWorkspace);
1488 dragController.setScrollView(mDragLayer);
1489 dragController.setMoveTarget(mWorkspace);
1490 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001491 if (mSearchDropTargetBar != null) {
1492 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001493 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001494 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001495
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001496 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001497 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001498 mWeightWatcher = new WeightWatcher(this);
1499 mWeightWatcher.setAlpha(0.5f);
1500 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001501 new FrameLayout.LayoutParams(
1502 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001503 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001504 Gravity.BOTTOM)
1505 );
Adam Cohen39a06042013-07-19 14:30:12 -07001506
1507 boolean show = shouldShowWeightWatcher();
1508 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001509 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510 }
1511
1512 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001513 * Sets the all apps button. This method is called from {@link Hotseat}.
1514 */
1515 public void setAllAppsButton(View allAppsButton) {
1516 mAllAppsButton = allAppsButton;
1517 }
1518
1519 public View getAllAppsButton() {
1520 return mAllAppsButton;
1521 }
1522
1523 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 * Creates a view representing a shortcut.
1525 *
1526 * @param info The data structure describing the shortcut.
1527 *
1528 * @return A View inflated from R.layout.application.
1529 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001530 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001531 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001532 }
1533
1534 /**
1535 * Creates a view representing a shortcut inflated from the specified resource.
1536 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 * @param parent The group the shortcut belongs to.
1538 * @param info The data structure describing the shortcut.
1539 *
1540 * @return A View inflated from layoutResId.
1541 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001542 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
1543 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(R.layout.application,
1544 parent, false);
1545 favorite.applyFromShortcutInfo(info, mIconCache);
1546 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001548 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549 return favorite;
1550 }
1551
1552 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 * Add a shortcut to the workspace.
1554 *
1555 * @param data The intent describing the shortcut.
1556 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001558 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001559 int cellY) {
1560 int[] cellXY = mTmpAddItemCellCoordinates;
1561 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001562 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001563
Sunny Goyal5c97f512015-05-19 16:03:28 -07001564 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001565 if (info == null) {
1566 return;
1567 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001568 final View view = createShortcut(info);
1569
Sunny Goyal5c97f512015-05-19 16:03:28 -07001570 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001571 // First we check if we already know the exact location where we want to add this item.
1572 if (cellX >= 0 && cellY >= 0) {
1573 cellXY[0] = cellX;
1574 cellXY[1] = cellY;
1575 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001576
1577 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001578 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001579 true, null,null)) {
1580 return;
1581 }
1582 DragObject dragObject = new DragObject();
1583 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001584 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1585 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001586 return;
1587 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001588 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001589 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001590 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001591 foundCellSpan = (result != null);
1592 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001593 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001594 }
1595
1596 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001597 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001598 return;
1599 }
1600
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001601 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602
1603 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001604 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001605 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
1607 }
1608
Adam Cohen2e6da152015-05-06 11:42:25 -07001609 private int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight) {
1610 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001611 // We want to account for the extra amount of padding that we are adding to the widget
1612 // to ensure that it gets the full amount of space that it has requested
1613 int requiredWidth = minWidth + padding.left + padding.right;
1614 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2e6da152015-05-06 11:42:25 -07001615 return CellLayout.rectToCell(this, requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001616 }
1617
Adam Cohen2e6da152015-05-06 11:42:25 -07001618 public int[] getSpanForWidget(AppWidgetProviderInfo info) {
1619 return getSpanForWidget(info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001620 }
1621
Adam Cohen2e6da152015-05-06 11:42:25 -07001622 public int[] getMinSpanForWidget(AppWidgetProviderInfo info) {
1623 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001624 }
1625
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001626 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001627 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001628 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001629 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001630 */
Adam Cohen091440a2015-03-18 14:16:05 -07001631 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001632 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1633
1634 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001635 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001636 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1637 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001638 }
Romain Guycbb89e42009-06-08 15:52:54 -07001639
Adam Cohen59400422014-03-05 18:07:04 -08001640 if (appWidgetInfo.isCustomWidget) {
1641 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001642 }
1643
Adam Cohen59400422014-03-05 18:07:04 -08001644 LauncherAppWidgetInfo launcherInfo;
1645 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1646 launcherInfo.spanX = info.spanX;
1647 launcherInfo.spanY = info.spanY;
1648 launcherInfo.minSpanX = info.minSpanX;
1649 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001650 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001651
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001652 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001653 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001654
1655 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001656 if (hostView == null) {
1657 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001658 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1659 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001660 } else {
1661 // The AppWidgetHostView has already been inflated and instantiated
1662 launcherInfo.hostView = hostView;
1663 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001664 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001665 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001666 launcherInfo.notifyWidgetSizeChanged(this);
1667
Adam Cohen59400422014-03-05 18:07:04 -08001668 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
1669 info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001670
1671 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001672 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001673 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001674 }
Romain Guycbb89e42009-06-08 15:52:54 -07001675
Adam Cohended9f8d2010-11-03 13:25:16 -07001676 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1677 @Override
1678 public void onReceive(Context context, Intent intent) {
1679 final String action = intent.getAction();
1680 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1681 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001682 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001683 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001684
Winson Chungc100e8e2011-08-09 16:02:43 -07001685 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001686 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001687 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001688 mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001689 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001690 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001691 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1692 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001693 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001694 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1695 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001696 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001697 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1698 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1699 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001700 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001701 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1702 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001703 }
1704 }
1705 };
1706
1707 @Override
1708 public void onAttachedToWindow() {
1709 super.onAttachedToWindow();
1710
1711 // Listen for broadcasts related to user-presence
1712 final IntentFilter filter = new IntentFilter();
1713 filter.addAction(Intent.ACTION_SCREEN_OFF);
1714 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001715 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001716 if (ENABLE_DEBUG_INTENTS) {
1717 filter.addAction(DebugIntents.DELETE_DATABASE);
1718 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1719 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001720 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001721 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001722 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001723 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001724 mVisible = true;
1725 }
1726
Adam Cohen0b395352014-06-09 22:54:36 +00001727 /**
1728 * Sets up transparent navigation and status bars in LMP.
1729 * This method is a no-op for other platform versions.
1730 */
Sunny Goyald0091012015-01-20 15:55:34 -08001731 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Adam Cohen0b395352014-06-09 22:54:36 +00001732 private void setupTransparentSystemBarsForLmp() {
Kenny Guyd794a3f2014-09-16 15:17:58 +01001733 if (Utilities.isLmpOrAbove()) {
Sunny Goyald0091012015-01-20 15:55:34 -08001734 Window window = getWindow();
1735 window.getAttributes().systemUiVisibility |=
1736 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1737 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1738 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1739 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1740 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1741 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
1742 window.setStatusBarColor(Color.TRANSPARENT);
1743 window.setNavigationBarColor(Color.TRANSPARENT);
Adam Cohen0b395352014-06-09 22:54:36 +00001744 }
1745 }
1746
Adam Cohended9f8d2010-11-03 13:25:16 -07001747 @Override
1748 public void onDetachedFromWindow() {
1749 super.onDetachedFromWindow();
1750 mVisible = false;
1751
Adam Cohend113e0c2010-11-11 10:48:05 -08001752 if (mAttached) {
1753 unregisterReceiver(mReceiver);
1754 mAttached = false;
1755 }
Winson Chungb745afb2015-03-02 11:51:23 -08001756 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001757 }
1758
1759 public void onWindowVisibilityChanged(int visibility) {
1760 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001761 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001762 // The following code used to be in onResume, but it turns out onResume is called when
1763 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1764 // is a more appropriate event to handle
1765 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001766 if (!mWorkspaceLoading) {
1767 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001768 // We want to let Launcher draw itself at least once before we force it to build
1769 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001770 // apps is nice and speedy.
1771 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001772 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001773 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001774 if (mStarted) return;
1775 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001776 // We delay the layer building a bit in order to give
1777 // other message processing a time to run. In particular
1778 // this avoids a delay in hiding the IME if it was
1779 // currently shown, because doing that may involve
1780 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001781 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001782 final ViewTreeObserver.OnDrawListener listener = this;
1783 mWorkspace.post(new Runnable() {
1784 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001785 if (mWorkspace != null &&
1786 mWorkspace.getViewTreeObserver() != null) {
1787 mWorkspace.getViewTreeObserver().
1788 removeOnDrawListener(listener);
1789 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001790 }
1791 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001792 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001793 }
1794 });
1795 }
1796 clearTypedText();
1797 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001798 }
1799
Adam Cohen091440a2015-03-18 14:16:05 -07001800 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001801 mHandler.removeMessages(ADVANCE_MSG);
1802 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1803 mHandler.sendMessageDelayed(msg, delay);
1804 mAutoAdvanceSentTime = System.currentTimeMillis();
1805 }
1806
Adam Cohen091440a2015-03-18 14:16:05 -07001807 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001808 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1809 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1810 mAutoAdvanceRunning = autoAdvanceRunning;
1811 if (autoAdvanceRunning) {
1812 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1813 sendAdvanceMessage(delay);
1814 } else {
1815 if (!mWidgetsToAdvance.isEmpty()) {
1816 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1817 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1818 }
1819 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001820 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001821 }
1822 }
1823 }
1824
1825 private final Handler mHandler = new Handler() {
1826 @Override
1827 public void handleMessage(Message msg) {
1828 if (msg.what == ADVANCE_MSG) {
1829 int i = 0;
1830 for (View key: mWidgetsToAdvance.keySet()) {
1831 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1832 final int delay = mAdvanceStagger * i;
1833 if (v instanceof Advanceable) {
1834 postDelayed(new Runnable() {
1835 public void run() {
1836 ((Advanceable) v).advance();
1837 }
1838 }, delay);
1839 }
1840 i++;
1841 }
1842 sendAdvanceMessage(mAdvanceInterval);
1843 }
1844 }
1845 };
1846
1847 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001848 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001849 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1850 if (v instanceof Advanceable) {
1851 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001852 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001853 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001854 }
1855 }
1856
1857 void removeWidgetToAutoAdvance(View hostView) {
1858 if (mWidgetsToAdvance.containsKey(hostView)) {
1859 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001860 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001861 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001862 }
1863
Joe Onorato9c1289c2009-08-17 11:03:03 -04001864 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001865 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001866 launcherInfo.hostView = null;
1867 }
1868
Hyunyoung Song3f471442015-04-08 19:01:34 -07001869 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001870 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1871 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001872 }
1873
Winson Chunga6945242014-01-08 14:04:34 -08001874 public DragLayer getDragLayer() {
1875 return mDragLayer;
1876 }
1877
Winson Chungb745afb2015-03-02 11:51:23 -08001878 public AppsContainerView getAppsView() {
1879 return mAppsView;
1880 }
1881
Hyunyoung Song3f471442015-04-08 19:01:34 -07001882 public WidgetsContainerView getWidgetsView() {
1883 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001884 }
1885
Winson Chunga6945242014-01-08 14:04:34 -08001886 public Workspace getWorkspace() {
1887 return mWorkspace;
1888 }
1889
1890 public Hotseat getHotseat() {
1891 return mHotseat;
1892 }
1893
Jorim Jaggid017f882014-01-14 17:08:48 -08001894 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001895 return mOverviewPanel;
1896 }
1897
1898 public SearchDropTargetBar getSearchBar() {
1899 return mSearchDropTargetBar;
1900 }
1901
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001902 public LauncherAppWidgetHost getAppWidgetHost() {
1903 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001904 }
Romain Guycbb89e42009-06-08 15:52:54 -07001905
Winson Chunga9abd0e2010-10-27 17:18:37 -07001906 public LauncherModel getModel() {
1907 return mModel;
1908 }
1909
Winson Chunga6945242014-01-08 14:04:34 -08001910 protected SharedPreferences getSharedPrefs() {
1911 return mSharedPrefs;
1912 }
1913
Adam Cohen2e6da152015-05-06 11:42:25 -07001914 public DeviceProfile getDeviceProfile() {
1915 return mDeviceProfile;
1916 }
1917
Bjorn Bringertc459e522013-06-07 19:36:01 +01001918 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001919 getWindow().closeAllPanels();
1920
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001921 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001922 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001923 }
1924
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 @Override
1926 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001927 long startTime = 0;
1928 if (DEBUG_RESUME_TIME) {
1929 startTime = System.currentTimeMillis();
1930 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 super.onNewIntent(intent);
1932
1933 // Close the menu
1934 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001935 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001936 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001937
Adam Cohened307df2013-10-02 09:37:31 -07001938 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1939 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1940 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001941
Adam Cohen6fecd412013-10-02 17:41:50 -07001942 if (mWorkspace == null) {
1943 // Can be cases where mWorkspace is null, this prevents a NPE
1944 return;
1945 }
1946 Folder openFolder = mWorkspace.getOpenFolder();
1947 // In all these cases, only animate if we're already on home
1948 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001949
1950 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1951 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Adam Cohen6fecd412013-10-02 17:41:50 -07001952 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Cohen9211d422014-10-07 18:14:53 -07001953 openFolder == null && moveToDefaultScreen) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001954 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001955 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001956
Adam Cohen6fecd412013-10-02 17:41:50 -07001957 closeFolder();
1958 exitSpringLoadedDragMode();
1959
1960 // If we are already on home, then just animate back to the workspace,
1961 // otherwise, just wait until onResume to set the state back to Workspace
1962 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001963 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001964 } else {
1965 mOnResumeState = State.WORKSPACE;
1966 }
1967
1968 final View v = getWindow().peekDecorView();
1969 if (v != null && v.getWindowToken() != null) {
1970 InputMethodManager imm = (InputMethodManager)getSystemService(
1971 INPUT_METHOD_SERVICE);
1972 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1973 }
1974
Winson Chungb745afb2015-03-02 11:51:23 -08001975 // Reset the apps view
1976 if (!alreadyOnHome && mAppsView != null) {
1977 mAppsView.scrollToTop();
1978 }
1979
Hyunyoung Song3f471442015-04-08 19:01:34 -07001980 // Reset the widgets view
1981 if (!alreadyOnHome && mWidgetsView != null) {
1982 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001983 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001984
Adam Cohen9211d422014-10-07 18:14:53 -07001985 if (mLauncherCallbacks != null) {
1986 mLauncherCallbacks.onHomeIntent();
1987 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001988 }
Adam Cohened307df2013-10-02 09:37:31 -07001989
Michael Jurka447bf842013-05-15 14:52:15 +02001990 if (DEBUG_RESUME_TIME) {
1991 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1992 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993
Adam Cohen9211d422014-10-07 18:14:53 -07001994 if (mLauncherCallbacks != null) {
1995 mLauncherCallbacks.onNewIntent(intent);
1996 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001997 }
1998
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07002000 public void onRestoreInstanceState(Bundle state) {
2001 super.onRestoreInstanceState(state);
2002 for (int page: mSynchronouslyBoundPages) {
2003 mWorkspace.restoreInstanceStateForChild(page);
2004 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 }
2006
2007 @Override
2008 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07002009 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08002010 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
2011 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07002012 }
Adam Cohen95bb8002011-07-03 23:40:28 -07002013 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014
Michael Jurka883f55b2010-10-21 15:47:14 -07002015 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07002016 // We close any open folder since it will not be re-opened, and we need to make sure
2017 // this state is reflected.
2018 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019
Adam Cohendcd297f2013-06-18 13:13:40 -07002020 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07002021 mWaitingForResult) {
2022 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07002023 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07002024 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2025 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002026 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2027 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2028 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08002029 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 }
2031
Hyunyoung Song3f471442015-04-08 19:01:34 -07002032 // Save the current widgets tray?
2033 // TODO(hyunyoungs)
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002034 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
Adam Cohen9211d422014-10-07 18:14:53 -07002035
2036 if (mLauncherCallbacks != null) {
2037 mLauncherCallbacks.onSaveInstanceState(outState);
2038 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002039 }
2040
2041 @Override
2042 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002044
Winson Chunge7a03942011-08-05 15:05:12 -07002045 // Remove all pending runnables
2046 mHandler.removeMessages(ADVANCE_MSG);
2047 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002048 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002049
Winson Chungcd2b0142011-06-08 16:02:26 -07002050 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002051 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07002052
2053 // It's possible to receive onDestroy after a new Launcher activity has
2054 // been created. In this case, don't interfere with the new Launcher.
2055 if (mModel.isCurrentCallbacks(this)) {
2056 mModel.stopLoader();
2057 app.setLauncher(null);
2058 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002061 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002063 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002064 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002065 mAppWidgetHost = null;
2066
2067 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068
2069 TextKeyListener.getInstance().release();
2070
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002071 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002072 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002073
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002074 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002075 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002076 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002077 mWorkspace = null;
2078 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002079
Michael Jurka2ecf9952012-06-18 12:52:28 -07002080 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002081
2082 if (mLauncherCallbacks != null) {
2083 mLauncherCallbacks.onDestroy();
2084 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002085 }
2086
Adam Cohena9cf38f2011-05-02 15:36:58 -07002087 public DragController getDragController() {
2088 return mDragController;
2089 }
2090
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 @Override
2092 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002093 onStartForResult(requestCode);
2094 super.startActivityForResult(intent, requestCode);
2095 }
2096
2097 @Override
2098 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2099 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2100 onStartForResult(requestCode);
2101 try {
2102 super.startIntentSenderForResult(intent, requestCode,
2103 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2104 } catch (IntentSender.SendIntentException e) {
2105 throw new ActivityNotFoundException();
2106 }
2107 }
2108
2109 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002110 if (requestCode >= 0) {
2111 setWaitingForResult(true);
2112 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002113 }
2114
Winson Chung70d72102011-08-12 11:24:35 -07002115 /**
2116 * Indicates that we want global search for this activity by setting the globalSearch
2117 * argument for {@link #startSearch} to true.
2118 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002119 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002120 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002121 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002122
Karl Rosaen138a0412009-04-23 19:00:21 -07002123 if (initialQuery == null) {
2124 // Use any text typed in the launcher as the initial query
2125 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002126 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002127 if (appSearchData == null) {
2128 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002129 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 }
Winson Chungadf0c182012-08-23 14:59:07 -07002131 Rect sourceBounds = new Rect();
2132 if (mSearchDropTargetBar != null) {
2133 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2134 }
Romain Guycbb89e42009-06-08 15:52:54 -07002135
Ian Parkinson047036e2014-09-01 15:40:53 +01002136 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002137 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002138 if (clearTextImmediately) {
2139 clearTypedText();
2140 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002141
2142 // We need to show the workspace after starting the search
2143 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002144 }
2145
Ian Parkinson047036e2014-09-01 15:40:53 +01002146 /**
2147 * Start a text search.
2148 *
2149 * @return {@code true} if the search will start immediately, so any further keypresses
2150 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2151 * to buffer keypresses.
2152 */
2153 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002154 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002155 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2156 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2157 sourceBounds);
2158 }
2159
Michael Jurkaa33411c2012-06-14 16:18:21 -07002160 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002161 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002162 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002163 }
2164
2165 /**
2166 * Starts the global search activity. This code is a copied from SearchManager
2167 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002168 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002169 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002170 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002171 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2172 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2173 if (globalSearchActivity == null) {
2174 Log.w(TAG, "No global search activity found.");
2175 return;
2176 }
2177 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2178 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2179 intent.setComponent(globalSearchActivity);
2180 // Make sure that we have a Bundle to put source in
2181 if (appSearchData == null) {
2182 appSearchData = new Bundle();
2183 } else {
2184 appSearchData = new Bundle(appSearchData);
2185 }
Adam Cohen9211d422014-10-07 18:14:53 -07002186 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002187 if (!appSearchData.containsKey("source")) {
2188 appSearchData.putString("source", getPackageName());
2189 }
2190 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2191 if (!TextUtils.isEmpty(initialQuery)) {
2192 intent.putExtra(SearchManager.QUERY, initialQuery);
2193 }
2194 if (selectInitialQuery) {
2195 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2196 }
2197 intent.setSourceBounds(sourceBounds);
2198 try {
2199 startActivity(intent);
2200 } catch (ActivityNotFoundException ex) {
2201 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2202 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 }
2204
Yura4f93ec62014-02-04 14:15:21 +00002205 public boolean isOnCustomContent() {
2206 return mWorkspace.isOnOrMovingToCustomContent();
2207 }
2208
Winson Chung70d72102011-08-12 11:24:35 -07002209 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002210 public boolean onPrepareOptionsMenu(Menu menu) {
2211 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002212 if (!isOnCustomContent()) {
2213 // Close any open folders
2214 closeFolder();
2215 // Stop resizing any widgets
2216 mWorkspace.exitWidgetResizeMode();
2217 if (!mWorkspace.isInOverviewMode()) {
2218 // Show the overview mode
2219 showOverviewMode(true);
2220 } else {
2221 showWorkspace(true);
2222 }
Winson Chunge0298742014-01-17 12:03:00 -08002223 }
Adam Cohen9211d422014-10-07 18:14:53 -07002224 if (mLauncherCallbacks != null) {
2225 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2226 }
2227
Michael Jurkab94f3f82013-09-11 18:08:54 +02002228 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002229 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002230
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002231 @Override
2232 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002233 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002234 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002235 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002236 }
2237
Joe Onorato9c1289c2009-08-17 11:03:03 -04002238 public boolean isWorkspaceLocked() {
2239 return mWorkspaceLoading || mWaitingForResult;
2240 }
2241
Adam Cohen517a7f52014-03-01 12:12:59 -08002242 public boolean isWorkspaceLoading() {
2243 return mWorkspaceLoading;
2244 }
2245
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002246 private void setWorkspaceLoading(boolean value) {
2247 boolean isLocked = isWorkspaceLocked();
2248 mWorkspaceLoading = value;
2249 if (isLocked != isWorkspaceLocked()) {
2250 onWorkspaceLockedChanged();
2251 }
2252 }
2253
2254 private void setWaitingForResult(boolean value) {
2255 boolean isLocked = isWorkspaceLocked();
2256 mWaitingForResult = value;
2257 if (isLocked != isWorkspaceLocked()) {
2258 onWorkspaceLockedChanged();
2259 }
2260 }
2261
Adam Cohen9211d422014-10-07 18:14:53 -07002262 protected void onWorkspaceLockedChanged() {
2263 if (mLauncherCallbacks != null) {
2264 mLauncherCallbacks.onWorkspaceLockedChanged();
2265 }
2266 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002267
Michael Jurka0280c3b2010-09-17 15:00:07 -07002268 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002269 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002270 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002271 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2272 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002273 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002274 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002275 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002276
Sunny Goyale6b63a32015-01-16 16:14:29 -08002277 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002278 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Adam Cohenad4e15c2013-10-17 16:21:35 -07002279 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2280 }
2281
Sunny Goyale6b63a32015-01-16 16:14:29 -08002282 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002283 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2284 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002285 if (appWidgetInfo.configure != null) {
2286 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002287 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002288
Bjorn Bringert7984c942009-12-09 15:38:25 +00002289 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002290 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2291 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2292
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002293 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002294 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002295 Runnable onComplete = new Runnable() {
2296 @Override
2297 public void run() {
2298 // Exit spring loaded mode if necessary after adding the widget
2299 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2300 null);
2301 }
2302 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002303 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002304 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002305 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002306 }
2307 }
Romain Guycbb89e42009-06-08 15:52:54 -07002308
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002309 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002310 // Close any folders that may be open.
2311 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002312 mWorkspace.moveToCustomContentScreen(animate);
2313 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002314
2315 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2316 int[] cell, int spanX, int spanY) {
2317 switch (info.itemType) {
2318 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2319 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2320 int span[] = new int[2];
2321 span[0] = spanX;
2322 span[1] = spanY;
2323 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2324 container, screenId, cell, span);
2325 break;
2326 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2327 processShortcutFromDrop(info.componentName, container, screenId, cell);
2328 break;
2329 default:
2330 throw new IllegalStateException("Unknown item type: " + info.itemType);
2331 }
2332 }
2333
Adam Cohenfbba09b2011-07-18 21:43:05 -07002334 /**
2335 * Process a shortcut drop.
2336 *
2337 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002338 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002339 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002340 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002341 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2342 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002343 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002344 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002345 mPendingAddInfo.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002346 mPendingAddInfo.dropPos = null;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002347
2348 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002349 mPendingAddInfo.cellX = cell[0];
2350 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002351 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002352
2353 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2354 createShortcutIntent.setComponent(componentName);
2355 processShortcut(createShortcutIntent);
2356 }
2357
Adam Cohenfbba09b2011-07-18 21:43:05 -07002358 /**
2359 * Process a widget drop.
2360 *
2361 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002362 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002363 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002364 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002365 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2366 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002367 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002368 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002369 mPendingAddInfo.screenId = info.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002370 mPendingAddInfo.dropPos = null;
Adam Cohend41fbf52012-02-16 23:53:59 -08002371 mPendingAddInfo.minSpanX = info.minSpanX;
2372 mPendingAddInfo.minSpanY = info.minSpanY;
2373
Adam Cohenfbba09b2011-07-18 21:43:05 -07002374 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002375 mPendingAddInfo.cellX = cell[0];
2376 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002377 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002378 if (span != null) {
2379 mPendingAddInfo.spanX = span[0];
2380 mPendingAddInfo.spanY = span[1];
2381 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002382
Adam Cohened66b2b2012-01-23 17:28:51 -08002383 AppWidgetHostView hostView = info.boundWidget;
2384 int appWidgetId;
2385 if (hostView != null) {
2386 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002387 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002388 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002389 // In this case, we either need to start an activity to get permission to bind
2390 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002391 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002392 Bundle options = info.bindOptions;
2393
Sunny Goyalffe83f12014-08-14 17:39:34 -07002394 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2395 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002396 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002397 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002398 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002399 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002400 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2401 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2402 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002403 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2404 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002405 // TODO: we need to make sure that this accounts for the options bundle.
2406 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002407 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2408 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002409 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002410 }
2411
Joe Onoratodeb98af2010-02-19 14:59:39 -08002412 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002413 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002414 }
2415
Winson Chung24ab2f12010-09-16 14:10:47 -07002416 void processWallpaper(Intent intent) {
2417 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2418 }
2419
Adam Cohendcd297f2013-06-18 13:13:40 -07002420 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002421 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002422 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002423 folderInfo.title = getText(R.string.folder_name);
2424
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002425 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002426 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2427 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002428 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429
2430 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002431 FolderIcon newFolder =
2432 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002433 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002434 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002435 // Force measure the new folder icon
2436 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2437 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002438 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002439 }
Romain Guycbb89e42009-06-08 15:52:54 -07002440
Joe Onorato9c1289c2009-08-17 11:03:03 -04002441 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002442 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002443 }
2444
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002445 /**
2446 * Registers various content observers. The current implementation registers
2447 * only a favorites observer to keep track of the favorites applications.
2448 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002449 private void registerContentObservers() {
2450 ContentResolver resolver = getContentResolver();
2451 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2452 true, mWidgetObserver);
2453 }
2454
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002455 @Override
2456 public boolean dispatchKeyEvent(KeyEvent event) {
2457 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2458 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002459 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002460 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002461 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002462 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002463 dumpState();
2464 return true;
2465 }
2466 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002467 }
2468 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2469 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002470 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002471 return true;
2472 }
2473 }
2474
2475 return super.dispatchKeyEvent(event);
2476 }
2477
Joe Onorato88ec0992009-11-19 13:16:06 -08002478 @Override
2479 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002480 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2481 return;
2482 }
2483
Winson Chung3d9490a2015-03-24 17:38:42 -07002484 LauncherAccessibilityDelegate delegate =
2485 LauncherAppState.getInstance().getAccessibilityDelegate();
2486 if (delegate != null && delegate.onBackPressed()) {
Adam Cohenc9735cf2015-01-23 16:11:55 -08002487 return;
2488 }
2489
Winson Chungb745afb2015-03-02 11:51:23 -08002490 if (isAppsViewVisible()) {
2491 showWorkspace(true);
2492 } else if (isWidgetsViewVisible()) {
2493 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002494 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002495 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002496 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002497 Folder openFolder = mWorkspace.getOpenFolder();
2498 if (openFolder.isEditingName()) {
2499 openFolder.dismissEditingName();
2500 } else {
2501 closeFolder();
2502 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002503 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002504 mWorkspace.exitWidgetResizeMode();
2505
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002506 // Back button is a no-op here, but give at least some feedback for the button press
2507 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002508 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002509 }
2510
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002511 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002512 * Re-listen when widgets are reset.
2513 */
Adam Cohen091440a2015-03-18 14:16:05 -07002514 @Thunk void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002515 if (mAppWidgetHost != null) {
2516 mAppWidgetHost.startListening();
2517 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002518 }
2519
2520 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002521 * Launches the intent referred by the clicked shortcut.
2522 *
2523 * @param v The view representing the clicked shortcut.
2524 */
2525 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002526 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2527 // view has detached (it's possible for this to happen if the view is removed mid touch).
2528 if (v.getWindowToken() == null) {
2529 return;
2530 }
2531
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002532 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002533 return;
2534 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002535
Adam Cohen1697b792013-09-17 19:08:21 -07002536 if (v instanceof Workspace) {
2537 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002538 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002539 }
2540 return;
2541 }
2542
2543 if (v instanceof CellLayout) {
2544 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002545 showWorkspace(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002546 }
2547 }
2548
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002549 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002550 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002551 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002553 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002554 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002555 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002556 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002557 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002558 } else if (tag instanceof AppInfo) {
2559 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002560 } else if (tag instanceof LauncherAppWidgetInfo) {
2561 if (v instanceof PendingAppWidgetHostView) {
2562 onClickPendingWidget((PendingAppWidgetHostView) v);
2563 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002564 }
2565 }
2566
Sunny Goyal508da152014-08-14 10:53:27 -07002567 public void onClickPagedViewIcon(View v) {
2568 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002569 if (mLauncherCallbacks != null) {
2570 mLauncherCallbacks.onClickPagedViewIcon(v);
2571 }
Sunny Goyal508da152014-08-14 10:53:27 -07002572 }
2573
Sunny Goyal70660032015-05-14 00:07:08 -07002574 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002575 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002576 return false;
2577 }
2578
Michael Jurkaaf442092010-06-10 17:01:57 -07002579 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002580 * Event handler for the app widget view which has not fully restored.
2581 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002582 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002583 if (mIsSafeModeEnabled) {
2584 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2585 return;
2586 }
2587
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002588 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002589 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002590 int widgetId = info.appWidgetId;
2591 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2592 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002593 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2594 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002595 mPendingAddInfo.copyFrom(info);
2596 mPendingAddWidgetId = widgetId;
2597
Sunny Goyalffe83f12014-08-14 17:39:34 -07002598 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2599 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002600 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002601 } else if (info.installProgress < 0) {
2602 // The install has not been queued
2603 final String packageName = info.providerName.getPackageName();
2604 showBrokenAppInstallDialog(packageName,
2605 new DialogInterface.OnClickListener() {
2606 public void onClick(DialogInterface dialog, int id) {
2607 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2608 }
2609 });
2610 } else {
2611 // Download has started.
2612 final String packageName = info.providerName.getPackageName();
2613 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002614 }
2615 }
2616
2617 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002618 * Event handler for the "grid" button that appears on the home screen, which
2619 * enters all apps mode.
2620 *
2621 * @param v The view that was clicked.
2622 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002623 protected void onClickAllAppsButton(View v) {
2624 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chungb745afb2015-03-02 11:51:23 -08002625 if (isAppsViewVisible()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002626 showWorkspace(true);
2627 } else {
Winson Chung4ac30062015-05-08 17:34:17 -07002628 // Try and refresh the set of predicted apps before we enter launcher
2629 showAppsView(true /* animated */, false /* resetListToTop */,
2630 true /* updatePredictedApps */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002631 }
2632 }
2633
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002634 private void showBrokenAppInstallDialog(final String packageName,
2635 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002636 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002637 .setTitle(R.string.abandoned_promises_title)
2638 .setMessage(R.string.abandoned_promise_explanation)
2639 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2640 .setNeutralButton(R.string.abandoned_clean_this,
2641 new DialogInterface.OnClickListener() {
2642 public void onClick(DialogInterface dialog, int id) {
2643 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2644 mWorkspace.removeAbandonedPromise(packageName, user);
2645 }
2646 })
2647 .create().show();
2648 return;
2649 }
2650
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002651 /**
2652 * Event handler for an app shortcut click.
2653 *
2654 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2655 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002656 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002657 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2658 Object tag = v.getTag();
2659 if (!(tag instanceof ShortcutInfo)) {
2660 throw new IllegalArgumentException("Input must be a Shortcut");
2661 }
2662
2663 // Open shortcut
2664 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002665
2666 if (shortcut.isDisabled != 0) {
2667 int error = R.string.activity_not_available;
2668 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2669 error = R.string.safemode_shortcut_error;
2670 }
2671 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2672 return;
2673 }
2674
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002675 final Intent intent = shortcut.intent;
2676
2677 // Check for special shortcuts
2678 if (intent.getComponent() != null) {
2679 final String shortcutClass = intent.getComponent().getClassName();
2680
2681 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2682 MemoryDumpActivity.startDump(this);
2683 return;
2684 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2685 toggleShowWeightWatcher();
2686 return;
2687 }
2688 }
2689
Chris Wren40c5ed32014-06-24 18:24:23 -04002690 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002691 if ((v instanceof BubbleTextView)
2692 && shortcut.isPromise()
2693 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002694 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002695 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002696 new DialogInterface.OnClickListener() {
2697 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002698 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002699 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002700 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002701 return;
2702 }
2703
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002704 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002705 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002706
2707 if (mLauncherCallbacks != null) {
2708 mLauncherCallbacks.onClickAppShortcut(v);
2709 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002710 }
2711
Adam Cohen091440a2015-03-18 14:16:05 -07002712 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002713 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002714 final ShortcutInfo shortcut;
2715 final Intent intent;
2716 if (tag instanceof ShortcutInfo) {
2717 shortcut = (ShortcutInfo) tag;
2718 intent = shortcut.intent;
2719 int[] pos = new int[2];
2720 v.getLocationOnScreen(pos);
2721 intent.setSourceBounds(new Rect(pos[0], pos[1],
2722 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002723
Sunny Goyal508da152014-08-14 10:53:27 -07002724 } else if (tag instanceof AppInfo) {
2725 shortcut = null;
2726 intent = ((AppInfo) tag).intent;
2727 } else {
2728 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2729 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002730
2731 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002732 mStats.recordLaunch(intent, shortcut);
2733
2734 if (success && v instanceof BubbleTextView) {
2735 mWaitingForResume = (BubbleTextView) v;
2736 mWaitingForResume.setStayPressed(true);
2737 }
2738 }
2739
2740 /**
2741 * Event handler for a folder icon click.
2742 *
2743 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2744 */
2745 protected void onClickFolderIcon(View v) {
2746 if (LOGD) Log.d(TAG, "onClickFolder");
2747 if (!(v instanceof FolderIcon)){
2748 throw new IllegalArgumentException("Input must be a FolderIcon");
2749 }
2750
2751 FolderIcon folderIcon = (FolderIcon) v;
2752 final FolderInfo info = folderIcon.getFolderInfo();
2753 Folder openFolder = mWorkspace.getFolderForTag(info);
2754
2755 // If the folder info reports that the associated folder is open, then verify that
2756 // it is actually opened. There have been a few instances where this gets out of sync.
2757 if (info.opened && openFolder == null) {
2758 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2759 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2760 info.opened = false;
2761 }
2762
2763 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2764 // Close any open folder
2765 closeFolder();
2766 // Open the requested folder
2767 openFolder(folderIcon);
2768 } else {
2769 // Find the open folder...
2770 int folderScreen;
2771 if (openFolder != null) {
2772 folderScreen = mWorkspace.getPageForView(openFolder);
2773 // .. and close it
2774 closeFolder(openFolder);
2775 if (folderScreen != mWorkspace.getCurrentPage()) {
2776 // Close any folder open on the current screen
2777 closeFolder();
2778 // Pull the folder onto this screen
2779 openFolder(folderIcon);
2780 }
2781 }
2782 }
Adam Cohen9211d422014-10-07 18:14:53 -07002783
2784 if (mLauncherCallbacks != null) {
2785 mLauncherCallbacks.onClickFolderIcon(v);
2786 }
Michael Jurka5130e402011-10-13 04:55:35 -07002787 }
2788
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002789 /**
2790 * Event handler for the (Add) Widgets button that appears after a long press
2791 * on the home screen.
2792 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002793 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002794 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002795 if (mIsSafeModeEnabled) {
2796 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2797 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002798 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002799 if (mLauncherCallbacks != null) {
2800 mLauncherCallbacks.onClickAddWidgetButton(view);
2801 }
Adam Cohen9211d422014-10-07 18:14:53 -07002802 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002803 }
2804
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002805 /**
2806 * Event handler for the wallpaper picker button that appears after a long press
2807 * on the home screen.
2808 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002809 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002810 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002811 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName()),
2812 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002813
2814 if (mLauncherCallbacks != null) {
2815 mLauncherCallbacks.onClickWallpaperPicker(v);
2816 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002817 }
2818
2819 /**
2820 * Event handler for a click on the settings button that appears after a long press
2821 * on the home screen.
2822 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002823 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002824 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002825 if (mLauncherCallbacks != null) {
2826 mLauncherCallbacks.onClickSettingsButton(v);
2827 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002828 }
2829
Michael Jurka5130e402011-10-13 04:55:35 -07002830 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002831 // Provide the same haptic feedback that the system offers for virtual keys.
2832 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002833 }
2834
Adam Cohen61f560d2013-09-30 15:58:20 -07002835 public void performHapticFeedbackOnTouchDown(View v) {
2836 // Provide the same haptic feedback that the system offers for virtual keys.
2837 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2838 }
2839
2840 public View.OnTouchListener getHapticFeedbackTouchListener() {
2841 if (mHapticFeedbackTouchListener == null) {
2842 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002843 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002844 @Override
2845 public boolean onTouch(View v, MotionEvent event) {
2846 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2847 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2848 }
2849 return false;
2850 }
2851 };
2852 }
2853 return mHapticFeedbackTouchListener;
2854 }
2855
Adam Cohen9211d422014-10-07 18:14:53 -07002856 public void onDragStarted(View view) {
2857 if (isOnCustomContent()) {
2858 // Custom content screen doesn't participate in drag and drop. If on custom
2859 // content screen, move to default.
2860 moveWorkspaceToDefaultScreen();
2861 }
2862
2863 if (mLauncherCallbacks != null) {
2864 mLauncherCallbacks.onDragStarted(view);
2865 }
2866 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002867
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002868 /**
2869 * Called when the user stops interacting with the launcher.
2870 * This implies that the user is now on the homescreen and is not doing housekeeping.
2871 */
Adam Cohen9211d422014-10-07 18:14:53 -07002872 protected void onInteractionEnd() {
2873 if (mLauncherCallbacks != null) {
2874 mLauncherCallbacks.onInteractionEnd();
2875 }
2876 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002877
2878 /**
2879 * Called when the user starts interacting with the launcher.
2880 * The possible interactions are:
2881 * - open all apps
2882 * - reorder an app shortcut, or a widget
2883 * - open the overview mode.
2884 * This is a good time to stop doing things that only make sense
2885 * when the user is on the homescreen and not doing housekeeping.
2886 */
Adam Cohen9211d422014-10-07 18:14:53 -07002887 protected void onInteractionBegin() {
2888 if (mLauncherCallbacks != null) {
2889 mLauncherCallbacks.onInteractionBegin();
2890 }
2891 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002892
Winson Chungcd99cd32015-04-29 11:03:24 -07002893 /** Updates the interaction state. */
2894 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002895 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002896 // overlay
Winson Chung83f59ab2015-05-05 17:21:58 -07002897 boolean fromStateWithOverlay;
2898 boolean toStateWithOverlay;
2899 if (Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
2900 fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2901 toStateWithOverlay = toState != Workspace.State.NORMAL;
2902 } else {
2903 fromStateWithOverlay = fromState != Workspace.State.NORMAL &&
2904 fromState != Workspace.State.NORMAL_HIDDEN;
2905 toStateWithOverlay = toState != Workspace.State.NORMAL &&
2906 toState != Workspace.State.NORMAL_HIDDEN;
2907 }
2908 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002909 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002910 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002911 onInteractionEnd();
2912 }
2913 }
2914
Kenny Guyf07af7b2014-07-31 11:39:16 +01002915 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002916 try {
2917 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002918 launcherApps.showAppDetailsForProfile(componentName, user);
2919 } catch (SecurityException e) {
2920 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2921 Log.e(TAG, "Launcher does not have permission to launch settings");
2922 } catch (ActivityNotFoundException e) {
2923 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2924 Log.e(TAG, "Unable to launch settings");
2925 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002926 }
2927
Michael Jurka1e2f4652013-07-08 18:03:46 -07002928 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002929 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2930 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002931 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002932 // System applications cannot be installed. For now, show a toast explaining that.
2933 // We may give them the option of disabling apps this way.
2934 int messageId = R.string.uninstall_system_app_text;
2935 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002936 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002937 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002938 String packageName = componentName.getPackageName();
2939 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002940 Intent intent = new Intent(
2941 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002942 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2943 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002944 if (user != null) {
2945 user.addToIntent(intent, Intent.EXTRA_USER);
2946 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002947 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002948 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002949 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002950 }
2951
Michael Jurka86a720e2012-05-09 11:23:23 -07002952 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002953 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002954 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002955 // Only launch using the new animation if the shortcut has not opted out (this is a
2956 // private contract between launcher and may be ignored in the future).
2957 boolean useLaunchAnimation = (v != null) &&
2958 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002959 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2960 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002961
Kenny Guy1317e2d2014-05-08 18:52:50 +01002962 UserHandleCompat user = null;
2963 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2964 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2965 user = userManager.getUserForSerialNumber(serialNumber);
2966 }
2967
2968 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002969 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002970 ActivityOptions opts = null;
2971 if (sClipRevealMethod != null) {
2972 // TODO: call method directly when Launcher3 can depend on M APIs
2973 int left = 0, top = 0;
2974 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2975 if (v instanceof TextView) {
2976 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002977 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2978 if (icon != null) {
2979 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002980 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002981 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002982 width = bounds.width();
2983 height = bounds.height();
2984 }
2985 }
2986 try {
2987 opts = (ActivityOptions) sClipRevealMethod.invoke(null, v,
2988 left, top, width, height);
2989 } catch (IllegalAccessException e) {
2990 Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
2991 sClipRevealMethod = null;
2992 } catch (InvocationTargetException e) {
2993 Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
2994 sClipRevealMethod = null;
2995 }
2996 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002997 if (opts == null && !Utilities.isLmpOrAbove()) {
2998 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002999 v.getMeasuredWidth(), v.getMeasuredHeight());
3000 }
Adam Cohen2e52c902015-04-06 13:11:28 -07003001 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07003002 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01003003
3004 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
3005 // Could be launching some bookkeeping activity
3006 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07003007 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07003008 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01003009 launcherApps.startActivityForProfile(intent.getComponent(), user,
3010 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07003011 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08003012 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003013 } catch (SecurityException e) {
3014 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08003015 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003016 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07003017 "or use the exported attribute for this activity. "
3018 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003019 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08003020 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003021 }
Winson Chungaafa03c2010-06-11 17:34:16 -07003022
Michael Jurka86a720e2012-05-09 11:23:23 -07003023 boolean startActivitySafely(View v, Intent intent, Object tag) {
3024 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07003025 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
3026 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
3027 return false;
3028 }
Michael Jurka86a720e2012-05-09 11:23:23 -07003029 try {
3030 success = startActivity(v, intent, tag);
3031 } catch (ActivityNotFoundException e) {
3032 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
3033 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
3034 }
3035 return success;
3036 }
3037
Adam Cohen268c4752012-06-06 17:47:33 -07003038 /**
3039 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
3040 * in the DragLayer in the exact absolute location of the original FolderIcon.
3041 */
3042 private void copyFolderIconToImage(FolderIcon fi) {
3043 final int width = fi.getMeasuredWidth();
3044 final int height = fi.getMeasuredHeight();
3045
3046 // Lazy load ImageView, Bitmap and Canvas
3047 if (mFolderIconImageView == null) {
3048 mFolderIconImageView = new ImageView(this);
3049 }
3050 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3051 mFolderIconBitmap.getHeight() != height) {
3052 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3053 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3054 }
3055
3056 DragLayer.LayoutParams lp;
3057 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3058 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3059 } else {
3060 lp = new DragLayer.LayoutParams(width, height);
3061 }
3062
Adam Cohen307fe232012-08-16 17:55:58 -07003063 // The layout from which the folder is being opened may be scaled, adjust the starting
3064 // view size by this scale factor.
3065 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003066 lp.customPosition = true;
3067 lp.x = mRectForFolderAnimation.left;
3068 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003069 lp.width = (int) (scale * width);
3070 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003071
3072 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3073 fi.draw(mFolderIconCanvas);
3074 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003075 if (fi.getFolder() != null) {
3076 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3077 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003078 }
Adam Cohen268c4752012-06-06 17:47:33 -07003079 // Just in case this image view is still in the drag layer from a previous animation,
3080 // we remove it and re-add it.
3081 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3082 mDragLayer.removeView(mFolderIconImageView);
3083 }
3084 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003085 if (fi.getFolder() != null) {
3086 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003087 }
Adam Cohen268c4752012-06-06 17:47:33 -07003088 }
3089
Adam Cohen2801caf2011-05-13 20:57:39 -07003090 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003091 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003092 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
3093 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
3094 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
3095
Adam Cohenc51934b2011-07-26 21:07:43 -07003096 FolderInfo info = (FolderInfo) fi.getTag();
3097 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3098 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003099 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3100 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003101 }
3102
Adam Cohen268c4752012-06-06 17:47:33 -07003103 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3104 copyFolderIconToImage(fi);
3105 fi.setVisibility(View.INVISIBLE);
3106
Michael Jurka2ecf9952012-06-18 12:52:28 -07003107 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003108 scaleX, scaleY);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003109 if (Utilities.isLmpOrAbove()) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003110 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3111 }
3112 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003113 oa.start();
3114 }
3115
Adam Cohen268c4752012-06-06 17:47:33 -07003116 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003117 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003118 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3119 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3120 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3121
Adam Cohen268c4752012-06-06 17:47:33 -07003122 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003123
Adam Cohen268c4752012-06-06 17:47:33 -07003124 // We remove and re-draw the FolderIcon in-case it has changed
3125 mDragLayer.removeView(mFolderIconImageView);
3126 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003127 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003128 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003129 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003130 oa.addListener(new AnimatorListenerAdapter() {
3131 @Override
3132 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003133 if (cl != null) {
3134 cl.clearFolderLeaveBehind();
3135 // Remove the ImageView copy of the FolderIcon and make the original visible.
3136 mDragLayer.removeView(mFolderIconImageView);
3137 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003138 }
3139 }
3140 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003141 oa.start();
3142 }
3143
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003144 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003145 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003146 * is animated relative to the specified View. If the View is null, no animation
3147 * is played.
3148 *
3149 * @param folderInfo The FolderInfo describing the folder to open.
3150 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003151 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003152 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003153 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3154 if (openFolder != null && openFolder != folder) {
3155 // Close any open folder before opening a folder.
3156 closeFolder();
3157 }
3158
Adam Cohena9cf38f2011-05-02 15:36:58 -07003159 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003160
Adam Cohena9cf38f2011-05-02 15:36:58 -07003161 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003162
Sunny Goyalf4066152015-04-15 09:42:19 -07003163 // While the folder is open, the position of the icon cannot change.
3164 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3165
Adam Cohen4554ee12011-08-03 16:13:21 -07003166 // Just verify that the folder hasn't already been added to the DragLayer.
3167 // There was a one-off crash where the folder had a parent already.
3168 if (folder.getParent() == null) {
3169 mDragLayer.addView(folder);
3170 mDragController.addDropTarget((DropTarget) folder);
3171 } else {
3172 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3173 folder.getParent() + ").");
3174 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003175 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003176 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003177
3178 // Notify the accessibility manager that this folder "window" has appeared and occluded
3179 // the workspace items
3180 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3181 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003182 }
3183
3184 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003185 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003186 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003187 if (folder.isEditingName()) {
3188 folder.dismissEditingName();
3189 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003190 closeFolder(folder);
3191 }
3192 }
3193
Sunny Goyal83a8f042015-05-19 12:52:12 -07003194 public void closeFolder(Folder folder) {
Adam Cohen4554ee12011-08-03 16:13:21 -07003195 folder.getInfo().opened = false;
3196
3197 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3198 if (parent != null) {
3199 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3200 shrinkAndFadeInFolderIcon(fi);
Sunny Goyalf4066152015-04-15 09:42:19 -07003201 if (fi != null) {
3202 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3203 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003204 }
3205 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003206
3207 // Notify the accessibility manager that this folder "window" has disappeard and no
3208 // longer occludeds the workspace items
3209 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003210 }
3211
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003212 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003213 if (!isDraggingEnabled()) return false;
3214 if (isWorkspaceLocked()) return false;
3215 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003216
Adam Cohen1697b792013-09-17 19:08:21 -07003217 if (v instanceof Workspace) {
3218 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003219 if (!mWorkspace.isTouchActive()) {
3220 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003221 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3222 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3223 return true;
3224 } else {
3225 return false;
3226 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003227 } else {
3228 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003229 }
Adam Cohen1697b792013-09-17 19:08:21 -07003230 }
3231
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003232 CellLayout.CellInfo longClickCellInfo = null;
3233 View itemUnderLongClick = null;
3234 if (v.getTag() instanceof ItemInfo) {
3235 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003236 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003237 itemUnderLongClick = longClickCellInfo.cell;
3238 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003239 }
3240
Winson Chung3d503fb2011-07-13 17:25:49 -07003241 // The hotseat touch handling does not go through Workspace, and we always allow long press
3242 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003243 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003244 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003245 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003246 // User long pressed on empty space
3247 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3248 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003249 if (mWorkspace.isInOverviewMode()) {
3250 mWorkspace.startReordering(v);
3251 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003252 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003253 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003254 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003255 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3256 mHotseat.getOrderInHotseat(
3257 longClickCellInfo.cellX,
3258 longClickCellInfo.cellY));
3259 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003260 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003261 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003262 }
3263 }
3264 }
3265 return true;
3266 }
3267
Winson Chung3d503fb2011-07-13 17:25:49 -07003268 boolean isHotseatLayout(View layout) {
3269 return mHotseat != null && layout != null &&
3270 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3271 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003272
Winson Chung3d503fb2011-07-13 17:25:49 -07003273 /**
3274 * Returns the CellLayout of the specified container at the specified screen.
3275 */
Sunny Goyal92820592015-03-02 11:31:35 -08003276 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003277 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3278 if (mHotseat != null) {
3279 return mHotseat.getLayout();
3280 } else {
3281 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003282 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003283 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003284 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003285 }
3286 }
3287
Winson Chungb745afb2015-03-02 11:51:23 -08003288 /**
3289 * For overridden classes.
3290 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003291 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003292 return isAppsViewVisible();
3293 }
3294
3295 public boolean isAppsViewVisible() {
3296 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3297 }
3298
3299 public boolean isWidgetsViewVisible() {
3300 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003301 }
3302
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003303 private void setWorkspaceBackground(int background) {
3304 switch (background) {
3305 case WORKSPACE_BACKGROUND_TRANSPARENT:
3306 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3307 break;
3308 case WORKSPACE_BACKGROUND_BLACK:
3309 getWindow().setBackgroundDrawable(null);
3310 break;
3311 default:
3312 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3313 }
Craig Mautner360310b2012-10-26 15:13:08 -07003314 }
3315
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003316 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003317 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3318 int curflags = getWindow().getAttributes().flags
3319 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3320 if (wpflags != curflags) {
3321 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3322 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003323 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003324 }
3325
Michael Jurkae326f182011-11-21 14:05:46 -08003326 @Override
3327 public void onTrimMemory(int level) {
3328 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003329 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3330 // The widget preview db can result in holding onto over
3331 // 3MB of memory for caching which isn't necessary.
3332 SQLiteDatabase.releaseMemory();
3333
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003334 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003335 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003336 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003337 if (mLauncherCallbacks != null) {
3338 mLauncherCallbacks.onTrimMemory(level);
3339 }
Michael Jurkae326f182011-11-21 14:05:46 -08003340 }
3341
Winson Chungb745afb2015-03-02 11:51:23 -08003342 @Override
3343 public void onStateTransitionHideSearchBar() {
3344 // Hide the search bar
3345 if (mSearchDropTargetBar != null) {
3346 mSearchDropTargetBar.hideSearchBar(false /* animated */);
3347 }
Adam Cohened66b2b2012-01-23 17:28:51 -08003348 }
3349
Winson Chungb745afb2015-03-02 11:51:23 -08003350 protected void showWorkspace(boolean animated) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003351 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated, null,
3352 true);
Adam Cohened307df2013-10-02 09:37:31 -07003353 }
3354
Sunny Goyal83a8f042015-05-19 12:52:12 -07003355 public void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003356 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
3357 onCompleteRunnable, true);
3358 }
3359
3360 protected void showWorkspace(int snapToPage, boolean animated) {
3361 showWorkspace(snapToPage, animated, null, true);
3362 }
3363
3364 void showWorkspace(int snapToPage, boolean animated, Runnable onCompleteRunnable,
3365 boolean notifyLauncherCallbacks) {
Winson Chung0f785722015-04-08 10:27:49 -07003366 boolean changed = mState != State.WORKSPACE ||
3367 mWorkspace.getState() != Workspace.State.NORMAL;
3368 if (changed) {
Winson Chung2d75f122013-09-23 16:53:31 -07003369 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003370 mWorkspace.setVisibility(View.VISIBLE);
Winson Chungb745afb2015-03-02 11:51:23 -08003371 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.NORMAL,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003372 snapToPage, animated, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003373
Winson Chungc7d2b602012-05-16 17:02:20 -07003374 // Show the search bar (only animate if we were showing the drop target bar in spring
3375 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003376 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003377 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003378 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003379
Michael Jurkab3e22d92011-10-31 15:58:33 -07003380 // Set focus to the AppsCustomize button
3381 if (mAllAppsButton != null) {
3382 mAllAppsButton.requestFocus();
3383 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003384 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003385
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003386 // Change the state *after* we've called all the transition code
3387 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003388
Winson Chung5fb63472011-02-02 17:03:37 -08003389 // Resume the auto-advance of widgets
3390 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003391 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003392
Winson Chung0f785722015-04-08 10:27:49 -07003393 if (changed) {
3394 // Send an accessibility event to announce the context change
3395 getWindow().getDecorView()
3396 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chungcd99cd32015-04-29 11:03:24 -07003397 if (notifyLauncherCallbacks) {
3398 // Dismiss all apps when the workspace is shown
Winson Chung83f59ab2015-05-05 17:21:58 -07003399 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003400 mLauncherCallbacks.onAllAppsHidden();
3401 }
3402 }
Winson Chung0f785722015-04-08 10:27:49 -07003403 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01003404 }
3405
Adam Cohened307df2013-10-02 09:37:31 -07003406 void showOverviewMode(boolean animated) {
3407 mWorkspace.setVisibility(View.VISIBLE);
Winson Chungb745afb2015-03-02 11:51:23 -08003408 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.OVERVIEW,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003409 WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
3410 null /* onCompleteRunnable */);
Adam Cohened307df2013-10-02 09:37:31 -07003411 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003412 }
3413
Winson Chungb745afb2015-03-02 11:51:23 -08003414 /**
3415 * Shows the apps view.
3416 */
Winson Chung4ac30062015-05-08 17:34:17 -07003417 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps) {
Winson Chungb745afb2015-03-02 11:51:23 -08003418 if (resetListToTop) {
3419 mAppsView.scrollToTop();
3420 }
Winson Chung4ac30062015-05-08 17:34:17 -07003421 if (updatePredictedApps) {
3422 tryAndUpdatePredictedApps();
3423 }
Winson Chungb745afb2015-03-02 11:51:23 -08003424 showAppsOrWidgets(animated, State.APPS);
3425 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003426
Winson Chungb745afb2015-03-02 11:51:23 -08003427 /**
3428 * Shows the widgets view.
3429 */
3430 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003431 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003432 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003433 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003434 }
Winson Chungb745afb2015-03-02 11:51:23 -08003435 showAppsOrWidgets(animated, State.WIDGETS);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003436
3437 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003438 @Override
3439 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003440 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003441 }
3442 });
Winson Chungb745afb2015-03-02 11:51:23 -08003443 }
3444
3445 /**
3446 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003447 *
3448 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003449 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003450 // TODO: calling method should use the return value so that when {@code false} is returned
3451 // the workspace transition doesn't fall into invalid state.
3452 private boolean showAppsOrWidgets(boolean animated, State toState) {
3453 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3454 mState != State.WIDGETS_SPRING_LOADED) {
3455 return false;
3456 }
3457 if (toState != State.APPS && toState != State.WIDGETS) {
3458 return false;
3459 }
Winson Chungb745afb2015-03-02 11:51:23 -08003460
3461 if (toState == State.APPS) {
3462 mStateTransitionAnimation.startAnimationToAllApps(animated);
Winson Chung83f59ab2015-05-05 17:21:58 -07003463 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chung0f785722015-04-08 10:27:49 -07003464 mLauncherCallbacks.onAllAppsShown();
3465 }
Winson Chungb745afb2015-03-02 11:51:23 -08003466 } else {
3467 mStateTransitionAnimation.startAnimationToWidgets(animated);
3468 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003469
Michael Jurkab3e22d92011-10-31 15:58:33 -07003470 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003471 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003472
3473 // Pause the auto-advance of widgets until we are out of AllApps
3474 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003475 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003476 closeFolder();
3477
3478 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003479 getWindow().getDecorView()
3480 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003481 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003482 }
3483
Winson Chungcd99cd32015-04-29 11:03:24 -07003484 /**
3485 * Updates the workspace and interaction state on state change, and return the animation to this
3486 * new state.
3487 */
3488 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState, int toPage,
3489 boolean animated, HashMap<View, Integer> layerViews) {
3490 Workspace.State fromState = mWorkspace.getState();
3491 Animator anim = mWorkspace.setStateWithAnimation(toState, toPage, animated, layerViews);
3492 updateInteraction(fromState, toState);
3493 return anim;
3494 }
3495
Hyunyoung Song3f471442015-04-08 19:01:34 -07003496 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003497 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Winson Chungb745afb2015-03-02 11:51:23 -08003498 if (mState == State.WORKSPACE || mState == State.APPS_SPRING_LOADED ||
3499 mState == State.WIDGETS_SPRING_LOADED) {
3500 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003501 }
Winson Chungb745afb2015-03-02 11:51:23 -08003502
3503 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.SPRING_LOADED,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003504 WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true /* animated */,
3505 null /* onCompleteRunnable */);
Winson Chungb745afb2015-03-02 11:51:23 -08003506 mState = isAppsViewVisible() ? State.APPS_SPRING_LOADED : State.WIDGETS_SPRING_LOADED;
Michael Jurkad3ef3062010-11-23 16:23:58 -08003507 }
Adam Cohen7777d962011-08-18 18:58:38 -07003508
Hyunyoung Song3f471442015-04-08 19:01:34 -07003509 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003510 final Runnable onCompleteRunnable) {
Winson Chungb745afb2015-03-02 11:51:23 -08003511 if (mState != State.APPS_SPRING_LOADED && mState != State.WIDGETS_SPRING_LOADED) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003512
Winson Chungcd99cd32015-04-29 11:03:24 -07003513 if (successfulDrop) {
3514 // We need to trigger all apps hidden to notify search to update itself before the
3515 // delayed call to showWorkspace below
Winson Chung83f59ab2015-05-05 17:21:58 -07003516 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003517 mLauncherCallbacks.onAllAppsHidden();
3518 }
3519 }
3520
Winson Chunge7a03942011-08-05 15:05:12 -07003521 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003522 @Override
3523 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003524 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003525 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3526 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003527 // Before we show workspace, hide all apps again because
3528 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3529 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003530 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003531 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003532 } else {
3533 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003534 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003535 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003536 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003537 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003538
Michael Jurkad3ef3062010-11-23 16:23:58 -08003539 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003540 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003541 showAppsView(true /* animated */, false /* resetListToTop */,
3542 false /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08003543 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003544 showWidgetsView(true, false);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003545 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003546 }
3547
Winson Chung4ac30062015-05-08 17:34:17 -07003548 /**
3549 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3550 * resumed.
3551 */
3552 private void tryAndUpdatePredictedApps() {
3553 if (mLauncherCallbacks != null) {
3554 List<ComponentName> apps = mLauncherCallbacks.getPredictedApps();
3555 if (!apps.isEmpty()) {
3556 mAppsView.setPredictedApps(apps);
3557 }
3558 }
3559 }
3560
Michael Jurkab3e22d92011-10-31 15:58:33 -07003561 void lockAllApps() {
3562 // TODO
3563 }
3564
3565 void unlockAllApps() {
3566 // TODO
3567 }
3568
Sunny Goyal594d76d2014-11-06 10:12:54 -08003569 protected void disableVoiceButtonProxy(boolean disable) {
3570 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003571 }
3572
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003573 public View getOrCreateQsbBar() {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003574 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
3575 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003576 }
3577
Adam Cohen24ce0b32014-01-14 16:18:14 -08003578 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003579 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3580 if (searchProvider == null) {
3581 return null;
3582 }
3583
3584 Bundle opts = new Bundle();
3585 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003586 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003587
3588 SharedPreferences sp = getSharedPreferences(
3589 LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
3590 int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003591 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003592 if (!searchProvider.provider.flattenToString().equals(
3593 sp.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003594 || (widgetInfo == null)
3595 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003596 // A valid widget is not already bound.
3597 if (widgetId > -1) {
3598 mAppWidgetHost.deleteAppWidgetId(widgetId);
3599 widgetId = -1;
3600 }
3601
3602 // Try to bind a new widget
3603 widgetId = mAppWidgetHost.allocateAppWidgetId();
3604
3605 if (!AppWidgetManagerCompat.getInstance(this)
3606 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3607 mAppWidgetHost.deleteAppWidgetId(widgetId);
3608 widgetId = -1;
3609 }
3610
3611 sp.edit()
3612 .putInt(QSB_WIDGET_ID, widgetId)
3613 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
3614 .commit();
3615 }
3616
3617 if (widgetId != -1) {
3618 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
3619 mQsb.updateAppWidgetOptions(opts);
3620 mQsb.setPadding(0, 0, 0, 0);
3621 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003622 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003623 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003624 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003625 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003626 }
3627
Sunny Goyal22235bc2015-04-03 09:23:43 -07003628 private void reinflateQSBIfNecessary() {
3629 if (mQsb instanceof LauncherAppWidgetHostView &&
3630 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3631 mSearchDropTargetBar.removeView(mQsb);
3632 mQsb = null;
3633 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3634 }
3635 }
3636
Michael Jurkad7c28052012-04-27 15:43:36 -07003637 @Override
3638 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003639 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003640 final List<CharSequence> text = event.getText();
3641 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003642 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003643 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003644 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003645 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003646 text.add(getString(R.string.widget_button_text));
alanv1d4fde62012-10-17 13:15:47 -07003647 } else {
3648 text.add(getString(R.string.all_apps_home_button_label));
3649 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003650 return result;
3651 }
3652
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003653 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003654 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003655 */
Adam Cohen091440a2015-03-18 14:16:05 -07003656 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003657 @Override
3658 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003659 closeSystemDialogs();
3660 }
3661 }
3662
3663 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003664 * Receives notifications whenever the appwidgets are reset.
3665 */
3666 private class AppWidgetResetObserver extends ContentObserver {
3667 public AppWidgetResetObserver() {
3668 super(new Handler());
3669 }
3670
3671 @Override
3672 public void onChange(boolean selfChange) {
3673 onAppWidgetReset();
3674 }
3675 }
3676
3677 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003678 * If the activity is currently paused, signal that we need to run the passed Runnable
3679 * in onResume.
3680 *
3681 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003682 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3683 * wrong when we're not running, and if the activity comes back to what the configuration was
3684 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003685 *
3686 * Implementation of the method from LauncherModel.Callbacks.
3687 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003688 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003689 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003690 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003691 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003692 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003693 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003694 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003695 }
3696 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003697 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003698 return true;
3699 } else {
3700 return false;
3701 }
3702 }
3703
Michael Jurkac402cd92013-05-20 15:49:32 +02003704 private boolean waitUntilResume(Runnable run) {
3705 return waitUntilResume(run, false);
3706 }
3707
Michael Jurka1e2f4652013-07-08 18:03:46 -07003708 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003709 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003710 }
3711
Michael Jurka7607c2f2013-04-03 14:33:19 -07003712 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003713 * If the activity is currently paused, signal that we need to re-run the loader
3714 * in onResume.
3715 *
3716 * This needs to be called from incoming places where resources might have been loaded
3717 * while we are paused. That is becaues the Configuration might be wrong
3718 * when we're not running, and if it comes back to what it was when we
3719 * were paused, we are not restarted.
3720 *
3721 * Implementation of the method from LauncherModel.Callbacks.
3722 *
3723 * @return true if we are currently paused. The caller might be able to
3724 * skip some work in that case since we will come back again.
3725 */
3726 public boolean setLoadOnResume() {
3727 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003728 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003729 mOnResumeNeedsLoad = true;
3730 return true;
3731 } else {
3732 return false;
3733 }
3734 }
3735
3736 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003737 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003738 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003739 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003740 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003741 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003742 } else {
3743 return SCREEN_COUNT / 2;
3744 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003745 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003746
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747 /**
3748 * Refreshes the shortcuts shown on the workspace.
3749 *
3750 * Implementation of the method from LauncherModel.Callbacks.
3751 */
3752 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003753 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003754
Michael Jurka7607c2f2013-04-03 14:33:19 -07003755 // If we're starting binding all over again, clear any bind calls we'd postponed in
3756 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3757 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003758 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003759
Winson Chungd64d1762013-08-20 14:37:16 -07003760 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003761 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003762 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003763
Michael Jurka05bf6442011-11-30 20:28:53 -08003764 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003765 if (mHotseat != null) {
3766 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003767 }
3768 }
3769
Adam Cohendcd297f2013-06-18 13:13:40 -07003770 @Override
3771 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003772 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003773
Adam Cohen5084cba2013-09-03 12:01:16 -07003774 // If there are no screens, we need to have an empty screen
3775 if (orderedScreenIds.size() == 0) {
3776 mWorkspace.addExtraEmptyScreen();
3777 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003778
3779 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003780 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003781 if (hasCustomContentToLeft()) {
3782 mWorkspace.createCustomContentContainer();
3783 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003784 }
Winson Chung64359a52013-07-08 17:17:08 -07003785 }
3786
3787 @Override
3788 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003789 // Log to disk
3790 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3791 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3792 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003793 int count = orderedScreenIds.size();
3794 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003795 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003796 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003797 }
3798
Adam Cohen39a06042013-07-19 14:30:12 -07003799 private boolean shouldShowWeightWatcher() {
3800 String spKey = LauncherAppState.getSharedPreferencesKey();
3801 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003802 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003803
3804 return show;
3805 }
3806
3807 private void toggleShowWeightWatcher() {
3808 String spKey = LauncherAppState.getSharedPreferencesKey();
3809 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3810 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3811
3812 show = !show;
3813
3814 SharedPreferences.Editor editor = sp.edit();
3815 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3816 editor.commit();
3817
3818 if (mWeightWatcher != null) {
3819 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3820 }
3821 }
3822
Winson Chungd64d1762013-08-20 14:37:16 -07003823 public void bindAppsAdded(final ArrayList<Long> newScreens,
3824 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003825 final ArrayList<ItemInfo> addAnimated,
3826 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003827 Runnable r = new Runnable() {
3828 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003829 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003830 }
3831 };
3832 if (waitUntilResume(r)) {
3833 return;
3834 }
3835
Winson Chungd64d1762013-08-20 14:37:16 -07003836 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003837 if (newScreens != null) {
3838 bindAddScreens(newScreens);
3839 }
Winson Chungd64d1762013-08-20 14:37:16 -07003840
3841 // We add the items without animation on non-visible pages, and with
3842 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003843 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003844 bindItems(addNotAnimated, 0,
3845 addNotAnimated.size(), false);
3846 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003847 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003848 bindItems(addAnimated, 0,
3849 addAnimated.size(), true);
3850 }
Winson Chungc58497e2013-09-03 17:48:37 -07003851
Winson Chung87412982013-10-03 18:34:14 -07003852 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003853 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003854
Winson Chungb745afb2015-03-02 11:51:23 -08003855 if (addedApps != null && mAppsView != null) {
3856 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003857 }
Winson Chungd64d1762013-08-20 14:37:16 -07003858 }
3859
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003860 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003861 * Bind the items start-end from the list.
3862 *
3863 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003864 */
Winson Chung64359a52013-07-08 17:17:08 -07003865 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3866 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003867 Runnable r = new Runnable() {
3868 public void run() {
3869 bindItems(shortcuts, start, end, forceAnimateIcons);
3870 }
3871 };
3872 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003873 return;
3874 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003875
Winson Chungf0c6ae02012-03-21 16:10:31 -07003876 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003877 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3878 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003879 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003880 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003881 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003882 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003883 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003884
3885 // Short circuit if we are loading dock items for a configuration which has no dock
3886 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3887 mHotseat == null) {
3888 continue;
3889 }
3890
Joe Onorato9c1289c2009-08-17 11:03:03 -04003891 switch (item.itemType) {
3892 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3893 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003894 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003895 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003896
Winson Chung64359a52013-07-08 17:17:08 -07003897 /*
3898 * TODO: FIX collision case
3899 */
Winson Chungce376632013-07-11 16:12:41 -07003900 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3901 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3902 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003903 View v = cl.getChildAt(item.cellX, item.cellY);
3904 Object tag = v.getTag();
3905 String desc = "Collision while binding workspace item: " + item
3906 + ". Collides with " + tag;
3907 if (LauncherAppState.isDogfoodBuild()) {
3908 throw (new RuntimeException(desc));
3909 } else {
3910 Log.d(TAG, desc);
3911 }
Winson Chungce376632013-07-11 16:12:41 -07003912 }
Winson Chung64359a52013-07-08 17:17:08 -07003913 }
3914
Adam Cohendcd297f2013-06-18 13:13:40 -07003915 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3916 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003917 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003918 // Animate all the applications up now
3919 shortcut.setAlpha(0f);
3920 shortcut.setScaleX(0f);
3921 shortcut.setScaleY(0f);
3922 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003923 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003924 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003925 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003926 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003927 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003928 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003929 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003930 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3931 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003932 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003933 default:
3934 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003936 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003937
Winson Chung997a9232013-07-24 15:33:46 -07003938 if (animateIcons) {
3939 // Animate to the correct page
3940 if (newShortcutsScreenId > -1) {
3941 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003942 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003943 final Runnable startBounceAnimRunnable = new Runnable() {
3944 public void run() {
3945 anim.playTogether(bounceAnims);
3946 anim.start();
3947 }
3948 };
Winson Chung997a9232013-07-24 15:33:46 -07003949 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003950 // We post the animation slightly delayed to prevent slowdowns
3951 // when we are loading right after we return to launcher.
3952 mWorkspace.postDelayed(new Runnable() {
3953 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003954 if (mWorkspace != null) {
3955 mWorkspace.snapToPage(newScreenIndex);
3956 mWorkspace.postDelayed(startBounceAnimRunnable,
3957 NEW_APPS_ANIMATION_DELAY);
3958 }
Winson Chung94d67682013-09-25 16:29:40 -07003959 }
3960 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003961 } else {
3962 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003963 }
3964 }
Winson Chung64359a52013-07-08 17:17:08 -07003965 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003966 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003967 }
3968
Joe Onorato9c1289c2009-08-17 11:03:03 -04003969 /**
3970 * Implementation of the method from LauncherModel.Callbacks.
3971 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003972 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003973 Runnable r = new Runnable() {
3974 public void run() {
3975 bindFolders(folders);
3976 }
3977 };
3978 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003979 return;
3980 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003981 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003982 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003983
3984 /**
3985 * Add the views for a widget to the workspace.
3986 *
3987 * Implementation of the method from LauncherModel.Callbacks.
3988 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003989 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003990 Runnable r = new Runnable() {
3991 public void run() {
3992 bindAppWidget(item);
3993 }
3994 };
3995 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003996 return;
3997 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003998
Daniel Sandler843e8602010-06-07 14:59:01 -04003999 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4000 if (DEBUG_WIDGETS) {
4001 Log.d(TAG, "bindAppWidget: " + item);
4002 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004003 final Workspace workspace = mWorkspace;
4004
Adam Cohen59400422014-03-05 18:07:04 -08004005 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00004006 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08004007
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004008 if (!mIsSafeModeEnabled
4009 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
4010 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
Sunny Goyalff572272014-07-23 13:58:07 -07004011 if (appWidgetInfo == null) {
4012 if (DEBUG_WIDGETS) {
4013 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4014 + " belongs to component " + item.providerName
4015 + ", as the povider is null");
4016 }
4017 LauncherModel.deleteItemFromDatabase(this, item);
4018 return;
4019 }
4020 // Note: This assumes that the id remap broadcast is received before this step.
4021 // If that is not the case, the id remap will be ignored and user may see the
4022 // click to setup view.
Adam Cohen2e6da152015-05-06 11:42:25 -07004023 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null);
Sunny Goyalff572272014-07-23 13:58:07 -07004024 pendingInfo.spanX = item.spanX;
4025 pendingInfo.spanY = item.spanY;
4026 pendingInfo.minSpanX = item.minSpanX;
4027 pendingInfo.minSpanY = item.minSpanY;
Hyunyoung Song3f471442015-04-08 19:01:34 -07004028 Bundle options = null;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -07004029 WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004030
Sunny Goyalff572272014-07-23 13:58:07 -07004031 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004032 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4033 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004034
4035 // TODO consider showing a permission dialog when the widget is clicked.
4036 if (!success) {
4037 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4038 if (DEBUG_WIDGETS) {
4039 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4040 + " belongs to component " + item.providerName
4041 + ", as the launcher is unable to bing a new widget id");
4042 }
4043 LauncherModel.deleteItemFromDatabase(this, item);
4044 return;
4045 }
4046
4047 item.appWidgetId = newWidgetId;
4048
4049 // If the widget has a configure activity, it is still needs to set it up, otherwise
4050 // the widget is ready to go.
4051 item.restoreStatus = (appWidgetInfo.configure == null)
4052 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4053 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4054
4055 LauncherModel.updateItemInDatabase(this, item);
4056 }
4057
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004058 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004059 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004060 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004061 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4062 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004063 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004064
Sunny Goyal651077b2014-06-30 14:15:31 -07004065 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4066 } else {
4067 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004068 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4069 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004070 view.updateIcon(mIconCache);
4071 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004072 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004073 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004074 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004075
Joe Onorato9c1289c2009-08-17 11:03:03 -04004076 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004077 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004078
Adam Cohendcd297f2013-06-18 13:13:40 -07004079 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004080 item.cellY, item.spanX, item.spanY, false);
Adam Cohen59400422014-03-05 18:07:04 -08004081 if (!item.isCustomWidget()) {
4082 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4083 }
Adam Cohended9f8d2010-11-03 13:25:16 -07004084
Joe Onorato9c1289c2009-08-17 11:03:03 -04004085 workspace.requestLayout();
4086
Daniel Sandler843e8602010-06-07 14:59:01 -04004087 if (DEBUG_WIDGETS) {
4088 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4089 + (SystemClock.uptimeMillis()-start) + "ms");
4090 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004091 }
4092
Sunny Goyalff572272014-07-23 13:58:07 -07004093 /**
4094 * Restores a pending widget.
4095 *
4096 * @param appWidgetId The app widget id
4097 * @param cellInfo The position on screen where to create the widget.
4098 */
4099 private void completeRestoreAppWidget(final int appWidgetId) {
4100 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4101 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4102 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4103 return;
4104 }
4105
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004106 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004107 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4108
4109 mWorkspace.reinflateWidgetsIfNecessary();
4110 LauncherModel.updateItemInDatabase(this, info);
4111 }
4112
Adam Cohen1462de32012-07-24 22:34:36 -07004113 public void onPageBoundSynchronously(int page) {
4114 mSynchronouslyBoundPages.add(page);
4115 }
4116
Joe Onorato9c1289c2009-08-17 11:03:03 -04004117 /**
4118 * Callback saying that there aren't any more items to bind.
4119 *
4120 * Implementation of the method from LauncherModel.Callbacks.
4121 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004122 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004123 Runnable r = new Runnable() {
4124 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004125 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004126 }
4127 };
4128 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004129 return;
4130 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004131 if (mSavedState != null) {
4132 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004133 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004134 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004135 mSavedState = null;
4136 }
4137
Adam Cohen1462de32012-07-24 22:34:36 -07004138 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004140 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004141 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004142
4143 // If we received the result of any pending adds while the loader was running (e.g. the
4144 // widget configuration forced an orientation change), process them now.
4145 if (sPendingAddItem != null) {
4146 final long screenId = completeAdd(sPendingAddItem);
4147
4148 // TODO: this moves the user to the page where the pending item was added. Ideally,
4149 // the screen would be guaranteed to exist after bind, and the page would be set through
4150 // the workspace restore process.
4151 mWorkspace.post(new Runnable() {
4152 @Override
4153 public void run() {
4154 mWorkspace.snapToScreenId(screenId);
4155 }
4156 });
4157 sPendingAddItem = null;
4158 }
4159
Sunny Goyal756adbc2015-04-16 15:20:51 -07004160 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004161
4162 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004163 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004164 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004165 }
4166
Adam Cohen3ed316a2014-07-23 18:21:20 -07004167 private void sendLoadingCompleteBroadcastIfNecessary() {
4168 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4169 String permission =
4170 getResources().getString(R.string.receive_first_load_broadcast_permission);
4171 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4172 sendBroadcast(intent, permission);
4173 SharedPreferences.Editor editor = mSharedPrefs.edit();
4174 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4175 editor.apply();
4176 }
4177 }
4178
Winson Chunga0b7e862013-09-05 16:03:15 -07004179 public boolean isAllAppsButtonRank(int rank) {
4180 if (mHotseat != null) {
4181 return mHotseat.isAllAppsButtonRank(rank);
4182 }
4183 return false;
4184 }
4185
Winson Chunga2413752012-04-03 14:22:34 -07004186 private boolean canRunNewAppsAnimation() {
4187 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4188 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4189 }
4190
Winson Chungc9168342013-06-26 14:54:55 -07004191 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4192 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4193 PropertyValuesHolder.ofFloat("alpha", 1f),
4194 PropertyValuesHolder.ofFloat("scaleX", 1f),
4195 PropertyValuesHolder.ofFloat("scaleY", 1f));
4196 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4197 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4198 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4199 return bounceAnim;
4200 }
4201
Adam Cohen27772732013-11-11 14:00:56 +00004202 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004203 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004204 }
4205
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004206 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004207 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004208 }
4209
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004210 public void bindSearchablesChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004211 if (mSearchDropTargetBar == null) {
4212 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004213 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004214 if (mQsb != null) {
4215 mSearchDropTargetBar.removeView(mQsb);
4216 mQsb = null;
4217 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004218 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004219 }
4220
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004221 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004222 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4223 * multiple calls to bind the same list.)
4224 */
4225 @Thunk ArrayList<AppInfo> mTmpAppsList;
4226 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4227 public void run() {
4228 bindAllApplications(mTmpAppsList);
4229 mTmpAppsList = null;
4230 }
4231 };
4232
4233 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004234 * Add the icons for all apps.
4235 *
4236 * Implementation of the method from LauncherModel.Callbacks.
4237 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004238 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004239 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4240 mTmpAppsList = apps;
4241 return;
4242 }
4243
Winson Chungb745afb2015-03-02 11:51:23 -08004244 if (mAppsView != null) {
4245 mAppsView.setApps(apps);
4246 }
Adam Cohen9211d422014-10-07 18:14:53 -07004247 if (mLauncherCallbacks != null) {
4248 mLauncherCallbacks.bindAllApplications(apps);
4249 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004250 }
4251
4252 /**
4253 * A package was updated.
4254 *
4255 * Implementation of the method from LauncherModel.Callbacks.
4256 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004257 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004258 Runnable r = new Runnable() {
4259 public void run() {
4260 bindAppsUpdated(apps);
4261 }
4262 };
4263 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004264 return;
4265 }
4266
Winson Chungb745afb2015-03-02 11:51:23 -08004267 if (mAppsView != null) {
4268 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004269 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004270 }
4271
Sunny Goyal4390ace2014-10-13 11:33:11 -07004272 @Override
4273 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4274 Runnable r = new Runnable() {
4275 public void run() {
4276 bindWidgetsRestored(widgets);
4277 }
4278 };
4279 if (waitUntilResume(r)) {
4280 return;
4281 }
4282 mWorkspace.widgetsRestored(widgets);
4283 }
4284
Joe Onorato9c1289c2009-08-17 11:03:03 -04004285 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004286 * Some shortcuts were updated in the background.
4287 *
4288 * Implementation of the method from LauncherModel.Callbacks.
4289 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004290 @Override
4291 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4292 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004293 Runnable r = new Runnable() {
4294 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004295 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004296 }
4297 };
4298 if (waitUntilResume(r)) {
4299 return;
4300 }
4301
Sunny Goyal4390ace2014-10-13 11:33:11 -07004302 if (!updated.isEmpty()) {
4303 mWorkspace.updateShortcuts(updated);
4304 }
4305
4306 if (!removed.isEmpty()) {
4307 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4308 for (ShortcutInfo si : removed) {
4309 removedComponents.add(si.getTargetComponent());
4310 }
4311 mWorkspace.removeItemsByComponentName(removedComponents, user);
4312 // Notify the drag controller
4313 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004314 }
4315 }
4316
4317 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004318 * Update the state of a package, typically related to install state.
4319 *
4320 * Implementation of the method from LauncherModel.Callbacks.
4321 */
Sunny Goyale755d462014-07-22 13:48:29 -07004322 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004323 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4324 Runnable r = new Runnable() {
4325 public void run() {
4326 bindRestoreItemsChange(updates);
4327 }
4328 };
4329 if (waitUntilResume(r)) {
4330 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004331 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004332
Sunny Goyal756adbc2015-04-16 15:20:51 -07004333 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004334 }
4335
4336 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004337 * A package was uninstalled. We take both the super set of packageNames
4338 * in addition to specific applications to remove, the reason being that
4339 * this can be called when a package is updated as well. In that scenario,
4340 * we only remove specific components from the workspace, where as
4341 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004342 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004343 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004344 * Implementation of the method from LauncherModel.Callbacks.
4345 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004346 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004347 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004348 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004349 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004350 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004351 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004352 }
Winson Chungd64d1762013-08-20 14:37:16 -07004353 };
4354 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004355 return;
4356 }
4357
Sunny Goyal1a745e82014-10-02 15:58:31 -07004358 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004359 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4360 for (AppInfo info : appInfos) {
4361 removedComponents.add(info.componentName);
4362 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004363 if (!packageNames.isEmpty()) {
4364 mWorkspace.removeItemsByPackageName(packageNames, user);
4365 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004366 if (!removedComponents.isEmpty()) {
4367 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004368 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004369 // Notify the drag controller
4370 mDragController.onAppsRemoved(packageNames, removedComponents);
4371
Sunny Goyal1a745e82014-10-02 15:58:31 -07004372 } else {
4373 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004374 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004375
Winson Chungdf95eb12013-10-16 14:57:07 -07004376 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004377 if (mAppsView != null) {
4378 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004379 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004380 }
Joe Onoratobe386092009-11-17 17:32:16 -08004381
Michael Jurkac402cd92013-05-20 15:49:32 +02004382 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004383 public void run() {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004384 bindAllPackages(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004385 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004386 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004387
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004388 @Override
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004389 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004390 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004391 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004392 return;
4393 }
4394
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004395 if (mWidgetsView != null && model != null) {
4396 mWidgetsView.addWidgets(model);
4397 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004398 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004399 }
4400
Winson Chung400438b2011-01-16 17:53:48 -08004401 private int mapConfigurationOriActivityInfoOri(int configOri) {
4402 final Display d = getWindowManager().getDefaultDisplay();
4403 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4404 switch (d.getRotation()) {
4405 case Surface.ROTATION_0:
4406 case Surface.ROTATION_180:
4407 // We are currently in the same basic orientation as the natural orientation
4408 naturalOri = configOri;
4409 break;
4410 case Surface.ROTATION_90:
4411 case Surface.ROTATION_270:
4412 // We are currently in the other basic orientation to the natural orientation
4413 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4414 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4415 break;
4416 }
4417
4418 int[] oriMap = {
4419 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4420 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4421 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4422 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4423 };
4424 // Since the map starts at portrait, we need to offset if this device's natural orientation
4425 // is landscape.
4426 int indexOffset = 0;
4427 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4428 indexOffset = 1;
4429 }
4430 return oriMap[(d.getRotation() + indexOffset) % 4];
4431 }
Adam Cohen446e9402011-09-15 18:21:21 -07004432
Winson Chung4b919f82012-05-01 10:44:08 -07004433 public void lockScreenOrientation() {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004434 if (Utilities.isRotationEnabled(this)) {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004435 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
4436 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4437 .getConfiguration().orientation));
4438 } else {
4439 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4440 }
Winson Chung4b919f82012-05-01 10:44:08 -07004441 }
4442 }
4443 public void unlockScreenOrientation(boolean immediate) {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004444 if (Utilities.isRotationEnabled(this)) {
Winson Chung4b919f82012-05-01 10:44:08 -07004445 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004446 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004447 } else {
4448 mHandler.postDelayed(new Runnable() {
4449 public void run() {
4450 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4451 }
4452 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004453 }
Winson Chung4b919f82012-05-01 10:44:08 -07004454 }
Winson Chung400438b2011-01-16 17:53:48 -08004455 }
4456
Winson Chunge43a1e72014-01-15 10:33:02 -08004457 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004458 if (mLauncherCallbacks != null) {
4459 return mLauncherCallbacks.isLauncherPreinstalled();
4460 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004461 PackageManager pm = getPackageManager();
4462 try {
4463 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4464 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4465 return true;
4466 } else {
4467 return false;
4468 }
4469 } catch (NameNotFoundException e) {
4470 e.printStackTrace();
4471 return false;
4472 }
4473 }
4474
Adam Cohenea90f832014-05-21 15:03:34 -07004475 /**
4476 * This method indicates whether or not we should suggest default wallpaper dimensions
4477 * when our wallpaper cropper was not yet used to set a wallpaper.
4478 */
4479 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004480 if (mLauncherCallbacks != null) {
4481 return mLauncherCallbacks.overrideWallpaperDimensions();
4482 }
Adam Cohenea90f832014-05-21 15:03:34 -07004483 return true;
4484 }
4485
Adam Cohen432609a2014-03-13 17:03:22 -07004486 /**
4487 * To be overridden by subclasses to indicate that there is an activity to launch
4488 * before showing the standard launcher experience.
4489 */
4490 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004491 if (mLauncherCallbacks != null) {
4492 return mLauncherCallbacks.hasFirstRunActivity();
4493 }
Adam Cohen432609a2014-03-13 17:03:22 -07004494 return false;
4495 }
4496
4497 /**
4498 * To be overridden by subclasses to launch any first run activity
4499 */
4500 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004501 if (mLauncherCallbacks != null) {
4502 return mLauncherCallbacks.getFirstRunActivity();
4503 }
Adam Cohen432609a2014-03-13 17:03:22 -07004504 return null;
4505 }
4506
Winson Chung2826a402015-04-17 16:18:53 -07004507 /**
4508 * Returns whether the launcher callbacks overrides search in all apps.
Winson Chung2826a402015-04-17 16:18:53 -07004509 */
4510 @Thunk boolean isAllAppsSearchOverridden() {
Winson Chung83f59ab2015-05-05 17:21:58 -07004511 if (DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
4512 return false;
4513 }
4514
Winson Chung2826a402015-04-17 16:18:53 -07004515 if (mLauncherCallbacks != null) {
4516 return mLauncherCallbacks.overrideAllAppsSearch();
4517 }
4518 return false;
4519 }
4520
Winson Chunga6945242014-01-08 14:04:34 -08004521 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004522 return !ActivityManager.isRunningInTestHarness() &&
4523 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004524 }
4525
Adam Cohen4a9423d2014-03-28 14:22:31 -07004526 protected boolean hasRunFirstRunActivity() {
4527 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4528 }
4529
Adam Cohen432609a2014-03-13 17:03:22 -07004530 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004531 if (shouldRunFirstRunActivity() &&
4532 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004533 Intent firstRunIntent = getFirstRunActivity();
4534 if (firstRunIntent != null) {
4535 startActivity(firstRunIntent);
4536 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004537 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004538 }
4539 }
Adam Cohen432609a2014-03-13 17:03:22 -07004540 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004541 }
4542
4543 private void markFirstRunActivityShown() {
4544 SharedPreferences.Editor editor = mSharedPrefs.edit();
4545 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4546 editor.apply();
4547 }
4548
Adam Cohen432609a2014-03-13 17:03:22 -07004549 /**
4550 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4551 * screen that must be displayed and dismissed.
4552 */
4553 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004554 if (mLauncherCallbacks != null) {
4555 return mLauncherCallbacks.hasDismissableIntroScreen();
4556 }
Adam Cohen432609a2014-03-13 17:03:22 -07004557 return false;
4558 }
4559
4560 /**
4561 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4562 */
4563 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004564 if (mLauncherCallbacks != null) {
4565 return mLauncherCallbacks.getIntroScreen();
4566 }
Adam Cohen432609a2014-03-13 17:03:22 -07004567 return null;
4568 }
4569
4570 /**
4571 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4572 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4573 */
4574 private boolean shouldShowIntroScreen() {
4575 return hasDismissableIntroScreen() &&
4576 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4577 }
4578
4579 protected void showIntroScreen() {
4580 View introScreen = getIntroScreen();
4581 changeWallpaperVisiblity(false);
4582 if (introScreen != null) {
4583 mDragLayer.showOverlayView(introScreen);
4584 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004585 if (mLauncherOverlayContainer != null) {
4586 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4587 }
Adam Cohen432609a2014-03-13 17:03:22 -07004588 }
4589
4590 public void dismissIntroScreen() {
4591 markIntroScreenDismissed();
4592 if (showFirstRunActivity()) {
4593 // We delay hiding the intro view until the first run activity is showing. This
4594 // avoids a blip.
4595 mWorkspace.postDelayed(new Runnable() {
4596 @Override
4597 public void run() {
4598 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004599 if (mLauncherOverlayContainer != null) {
4600 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4601 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004602 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004603 }
4604 }, ACTIVITY_START_DELAY);
4605 } else {
4606 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004607 if (mLauncherOverlayContainer != null) {
4608 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4609 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004610 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004611 }
4612 changeWallpaperVisiblity(true);
4613 }
4614
4615 private void markIntroScreenDismissed() {
4616 SharedPreferences.Editor editor = mSharedPrefs.edit();
4617 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4618 editor.apply();
4619 }
4620
Adam Cohen091440a2015-03-18 14:16:05 -07004621 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004622 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4623 // on the device, then we always show the first run cling experience (or if there is no
4624 // launcher2). Otherwise, we prompt the user upon started for migration
4625 LauncherClings launcherClings = new LauncherClings(this);
4626 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
4627 if (mModel.canMigrateFromOldLauncherDb(this)) {
4628 launcherClings.showMigrationCling();
4629 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004630 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004631 }
4632 }
4633 }
4634
Winson Chunga6945242014-01-08 14:04:34 -08004635 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004636 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4637 if (mHotseat != null) mHotseat.setAlpha(1f);
4638 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4639 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004640 }
4641
4642 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004643 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4644 if (mHotseat != null) mHotseat.setAlpha(0f);
4645 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4646 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004647 }
4648
Mathew Inwood72fbec12013-11-19 15:45:07 +00004649 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004650 // Called from search suggestion, not supported in other profiles.
4651 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4652 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4653 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4654 myUser);
4655 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004656 return null;
4657 }
Sunny Goyal4fbc3822015-02-18 16:46:50 -08004658 return new AppInfo(this, activityInfo, myUser, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004659 }
4660
4661 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4662 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004663 // Called from search suggestion, not supported in other profiles.
4664 return createShortcutDragInfo(shortcutIntent, caption, icon,
4665 UserHandleCompat.myUserHandle());
4666 }
4667
4668 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4669 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004670 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004671 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004672 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004673 }
4674
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004675 protected void moveWorkspaceToDefaultScreen() {
4676 mWorkspace.moveToDefaultScreen(false);
4677 }
4678
Mathew Inwood72fbec12013-11-19 15:45:07 +00004679 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4680 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004681 mWorkspace.onExternalDragStartedWithItem(dragView);
4682 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004683 }
4684
Anjali Koppalf5d29132014-02-28 13:33:27 -08004685 @Override
4686 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004687 if (mLauncherCallbacks != null) {
4688 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4689 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004690 }
4691
Winson Chung80baf5a2010-08-09 16:03:15 -07004692 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004693 * Prints out out state for debugging.
4694 */
4695 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004696 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004697 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004698 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4699 Log.d(TAG, "mRestoring=" + mRestoring);
4700 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4701 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004702 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004703 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004704 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004705
Daniel Sandler325dc232013-06-05 22:57:57 -04004706 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004707 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004708
4709 @Override
4710 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4711 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004712 synchronized (sDumpLogs) {
4713 writer.println(" ");
4714 writer.println("Debug logs: ");
4715 for (int i = 0; i < sDumpLogs.size(); i++) {
4716 writer.println(" " + sDumpLogs.get(i));
4717 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004718 }
Adam Cohen9211d422014-10-07 18:14:53 -07004719 if (mLauncherCallbacks != null) {
4720 mLauncherCallbacks.dump(prefix, fd, writer, args);
4721 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004722 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004723
4724 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004725 if (DEBUG_DUMP_LOG) {
4726 synchronized (sDumpLogs) {
4727 Log.d(TAG, "");
4728 Log.d(TAG, "*********************");
4729 Log.d(TAG, "Launcher debug logs: ");
4730 for (int i = 0; i < sDumpLogs.size(); i++) {
4731 Log.d(TAG, " " + sDumpLogs.get(i));
4732 }
4733 Log.d(TAG, "*********************");
4734 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004735 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004736 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004737 }
4738
4739 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004740 addDumpLog(tag, log, null, debugLog);
4741 }
4742
4743 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004744 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004745 if (e != null) {
4746 Log.d(tag, log, e);
4747 } else {
4748 Log.d(tag, log);
4749 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004750 }
Winson Chungede41292013-09-19 16:27:36 -07004751 if (DEBUG_DUMP_LOG) {
4752 sDateStamp.setTime(System.currentTimeMillis());
4753 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004754 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4755 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004756 }
Winson Chungede41292013-09-19 16:27:36 -07004757 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004758 }
4759
Adam Cohen59400422014-03-05 18:07:04 -08004760 public static CustomAppWidget getCustomAppWidget(String name) {
4761 return sCustomAppWidgets.get(name);
4762 }
4763
4764 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4765 return sCustomAppWidgets;
4766 }
4767
Winson Chungede41292013-09-19 16:27:36 -07004768 public void dumpLogsToLocalData() {
4769 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004770 new AsyncTask<Void, Void, Void>() {
4771 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004772 boolean success = false;
4773 sDateStamp.setTime(sRunStart);
4774 String FILENAME = sDateStamp.getMonth() + "-"
4775 + sDateStamp.getDay() + "_"
4776 + sDateStamp.getHours() + "-"
4777 + sDateStamp.getMinutes() + "_"
4778 + sDateStamp.getSeconds() + ".txt";
4779
4780 FileOutputStream fos = null;
4781 File outFile = null;
4782 try {
4783 outFile = new File(getFilesDir(), FILENAME);
4784 outFile.createNewFile();
4785 fos = new FileOutputStream(outFile);
4786 } catch (Exception e) {
4787 e.printStackTrace();
4788 }
4789 if (fos != null) {
4790 PrintWriter writer = new PrintWriter(fos);
4791
4792 writer.println(" ");
4793 writer.println("Debug logs: ");
4794 synchronized (sDumpLogs) {
4795 for (int i = 0; i < sDumpLogs.size(); i++) {
4796 writer.println(" " + sDumpLogs.get(i));
4797 }
4798 }
4799 writer.close();
4800 }
4801 try {
4802 if (fos != null) {
4803 fos.close();
4804 success = true;
4805 }
4806 } catch (IOException e) {
4807 e.printStackTrace();
4808 }
Michael Jurka43467462013-11-14 12:03:58 +01004809 return null;
Winson Chungede41292013-09-19 16:27:36 -07004810 }
Michael Jurka43467462013-11-14 12:03:58 +01004811 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004812 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004813 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004814}
Michael Jurka2763be32011-02-24 11:19:57 -08004815
Michael Jurkaabded662011-03-04 12:06:57 -08004816interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004817 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004818 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004819 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004820 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004821 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004822}
Dan Sandlerd5024042014-01-09 15:01:33 -05004823
4824interface DebugIntents {
4825 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4826 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004827}