blob: d7282eb73d5648b9c7bbfc6351e48d5b35d0974d [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;
Sunny Goyale2df0622015-04-24 11:27:00 -0700106import com.android.launcher3.util.LongArrayMap;
Adam Cohen091440a2015-03-18 14:16:05 -0700107import com.android.launcher3.util.Thunk;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700108import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700109import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700110import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700111
Adam Cohenc0dcf592011-06-01 15:30:43 -0700112import java.io.DataInputStream;
113import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700114import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700115import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700117import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700118import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700119import java.io.PrintWriter;
Chet Haasea8f996d2015-02-17 12:56:04 -0800120import java.lang.reflect.InvocationTargetException;
121import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700122import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700124import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700127import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700128import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000129import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131/**
132 * Default launcher application.
133 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100134public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700135 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungb745afb2015-03-02 11:51:23 -0800136 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener,
137 LauncherStateTransitionAnimation.Callbacks {
Hyunyoung Song4e8fb912015-04-11 15:44:32 -0700138 static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700139 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
Winson Chung83f59ab2015-05-05 17:21:58 -0700141 // Temporary flag
142 static final boolean DISABLE_ALL_APPS_SEARCH_INTEGRATION = true;
143
Daniel Sandlerf061f822013-06-27 13:59:36 -0400144 static final boolean PROFILE_STARTUP = false;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700145 static final boolean DEBUG_WIDGETS = true;
Winson Chunga2413752012-04-03 14:22:34 -0700146 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400147 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700148 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700149
Dan Sandlerd5024042014-01-09 15:01:33 -0500150 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
151
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700153 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700154 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700155 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
Michael Jurka8b805b12012-04-18 14:23:14 -0700157 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700158 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700159
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700160 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
161 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
162 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
163
Mathew Inwood876a8462013-06-14 14:12:41 +0100164 /**
165 * IntentStarter uses request codes starting with this. This must be greater than all activity
166 * request codes used internally.
167 */
168 protected static final int REQUEST_LAST = 100;
169
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
171
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800172 static final int SCREEN_COUNT = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Michael Jurka0a457bf2012-11-19 14:05:05 -0800174 // To turn on these properties, type
175 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800176 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Winson Chung2672ff92012-05-04 16:22:30 -0700178 // The Intent extra that defines whether to ignore the launch animation
179 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400180 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
183 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700184 // Type: int
185 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700187 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
188 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
190 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700191 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700193 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700194 // Type: int
195 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
196 // Type: int
197 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
198 // Type: parcelable
199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000200 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800201 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000202 // Type: int[]
203 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
Adam Cohen432609a2014-03-13 17:03:22 -0700205 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800206 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
207
Adam Cohen3ed316a2014-07-23 18:21:20 -0700208 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
209 static final String ACTION_FIRST_LOAD_COMPLETE =
210 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
211
Adam Cohen39a06042013-07-19 14:30:12 -0700212 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700213 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700214
Sunny Goyal594d76d2014-11-06 10:12:54 -0800215 private static final String QSB_WIDGET_ID = "qsb_widget_id";
216 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
217
Winson Chunga6945242014-01-08 14:04:34 -0800218 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
219
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700220 /** The different states that Launcher can be in. */
Winson Chungb745afb2015-03-02 11:51:23 -0800221 enum State { NONE, WORKSPACE, APPS, APPS_SPRING_LOADED, WIDGETS, WIDGETS_SPRING_LOADED };
Adam Cohen091440a2015-03-18 14:16:05 -0700222 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700223 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700224
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700225 private boolean mIsSafeModeEnabled;
226
Adam Cohenc2d6e892014-10-16 09:49:24 -0700227 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
228 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700229 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700230
Joe Onorato9c1289c2009-08-17 11:03:03 -0400231 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700232 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
233 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700234 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000236 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
237 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
238
Winson Chunga2413752012-04-03 14:22:34 -0700239 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700240 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
241 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700242 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700243
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800244 private final BroadcastReceiver mCloseSystemDialogsReceiver
245 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800246 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
247
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private LayoutInflater mInflater;
249
Adam Cohen091440a2015-03-18 14:16:05 -0700250 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700251 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800252 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700253 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800254 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700255 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700256
Sunny Goyalffe83f12014-08-14 17:39:34 -0700257 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700258 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700259
Adam Cohen091440a2015-03-18 14:16:05 -0700260 @Thunk ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800261 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800262 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700263
Michael Jurka0280c3b2010-09-17 15:00:07 -0700264 private int[] mTmpAddItemCellCoordinates = new int[2];
265
Winson Chung3d503fb2011-07-13 17:25:49 -0700266 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800267 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700268
Michael Jurka838a4ca2011-02-07 13:33:06 -0800269 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700270
Winson Chungc51db6a2011-10-05 11:44:49 -0700271 private SearchDropTargetBar mSearchDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700272
273 // Main container view for the all apps screen.
Adam Cohen091440a2015-03-18 14:16:05 -0700274 @Thunk AppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700275
276 // Main container view for the widget tray screen.
277 private WidgetsContainerView mWidgetsView;
278
Winson Chungf0ea4d32011-06-06 14:27:16 -0700279 private boolean mAutoAdvanceRunning = false;
Sunny Goyal594d76d2014-11-06 10:12:54 -0800280 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700283 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
284 // scroll issues (because the workspace may not have been measured yet) and extra work.
285 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
286 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287
288 private SpannableStringBuilder mDefaultKeySsb = null;
289
Adam Cohen091440a2015-03-18 14:16:05 -0700290 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800292 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 private boolean mRestoring;
294 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700295 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296
Michael Jurka1e2f4652013-07-08 18:03:46 -0700297 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700298 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 private Bundle mSavedInstanceState;
301
Joe Onorato9c1289c2009-08-17 11:03:03 -0400302 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800303 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700304 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800305 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700306 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800307 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400308
Adam Cohen091440a2015-03-18 14:16:05 -0700309 @Thunk static LocaleConfiguration sLocaleConfiguration = null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700310
Sunny Goyale2df0622015-04-24 11:27:00 -0700311 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700312
Adam Cohen61f560d2013-09-30 15:58:20 -0700313 private View.OnTouchListener mHapticFeedbackTouchListener;
314
Adam Cohended9f8d2010-11-03 13:25:16 -0700315 // Related to the auto-advancing of widgets
316 private final int ADVANCE_MSG = 1;
317 private final int mAdvanceInterval = 20000;
318 private final int mAdvanceStagger = 250;
319 private long mAutoAdvanceSentTime;
320 private long mAutoAdvanceTimeLeft = -1;
Adam Cohen091440a2015-03-18 14:16:05 -0700321 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
Adam Cohended9f8d2010-11-03 13:25:16 -0700322 new HashMap<View, AppWidgetProviderInfo>();
323
Winson Chung400438b2011-01-16 17:53:48 -0800324 // Determines how long to wait after a rotation before restoring the screen orientation to
325 // match the sensor state.
326 private final int mRestoreScreenOrientationDelay = 500;
327
Adam Cohen091440a2015-03-18 14:16:05 -0700328 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700329
Adam Cohen1462de32012-07-24 22:34:36 -0700330 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700331 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700332
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700333 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700334 static Date sDateStamp = new Date();
335 static DateFormat sDateFormat =
336 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
337 static long sRunStart = System.currentTimeMillis();
338 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700339
Winson Chung46353de2012-02-16 14:05:10 -0800340 // We only want to get the SharedPreferences once since it does an FS stat each time we get
341 // it from the context.
342 private SharedPreferences mSharedPrefs;
343
Winson Chungf0c6ae02012-03-21 16:10:31 -0700344 // Holds the page that we need to animate to, and the icon views that we need to animate up
345 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700346 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700347 private Bitmap mFolderIconBitmap;
348 private Canvas mFolderIconCanvas;
349 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700350
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700351 private DeviceProfile mDeviceProfile;
352
Winson Chung13eb5272015-05-11 16:30:13 -0700353 // This is set to the view that launched the activity that navigated the user away from
354 // launcher. Since there is no callback for when the activity has finished launching, enable
355 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800356 private BubbleTextView mWaitingForResume;
357
Adam Cohen59400422014-03-05 18:07:04 -0800358 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
359 new HashMap<String, CustomAppWidget>();
360
361 private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
362 static {
363 if (ENABLE_CUSTOM_WIDGET_TEST) {
364 sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
365 }
366 }
367
Chet Haasea8f996d2015-02-17 12:56:04 -0800368 // TODO: remove this field and call method directly when Launcher3 can depend on M APIs
369 private static Method sClipRevealMethod = null;
370 static {
371 Class<?> activityOptionsClass = ActivityOptions.class;
372 try {
373 sClipRevealMethod = activityOptionsClass.getDeclaredMethod("makeClipRevealAnimation",
374 View.class, int.class, int.class, int.class, int.class);
375 } catch (Exception e) {
376 // Earlier version
377 }
378 }
379
Adam Cohen091440a2015-03-18 14:16:05 -0700380 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700381 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700382 if (mWorkspace != null) {
383 mWorkspace.buildPageHardwareLayers();
384 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700385 }
386 };
387
Adam Cohendb364c32014-05-20 14:23:40 -0700388 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800389
Adam Cohen091440a2015-03-18 14:16:05 -0700390 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800391 int requestCode;
392 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700393 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700394 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800395 int cellX;
396 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700397 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800398 }
399
Daniel Sandlerff02d492013-08-05 02:12:05 -0400400 private Stats mStats;
401
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700402 FocusIndicatorView mFocusHandler;
403
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 @Override
405 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700406 if (DEBUG_STRICT_MODE) {
407 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
408 .detectDiskReads()
409 .detectDiskWrites()
410 .detectNetwork() // or .detectAll() for all detectable problems
411 .penaltyLog()
412 .build());
413 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
414 .detectLeakedSqlLiteObjects()
415 .detectLeakedClosableObjects()
416 .penaltyLog()
417 .penaltyDeath()
418 .build());
419 }
420
Adam Cohen9211d422014-10-07 18:14:53 -0700421 if (mLauncherCallbacks != null) {
422 mLauncherCallbacks.preOnCreate();
423 }
424
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400426
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400427 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400428 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700429 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700430
Winson Chung5f8afe62013-08-12 16:19:28 -0700431 // Lazy-initialize the dynamic grid
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700432 mDeviceProfile = app.initDynamicGrid(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700433
434 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400435 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700436 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700437 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800438 mModel = app.setLauncher(this);
439 mIconCache = app.getIconCache();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700440 mIconCache.flushInvalidIcons(mDeviceProfile);
Joe Onorato41a12d22009-10-31 18:30:00 -0400441 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 mInflater = getLayoutInflater();
Winson Chungb745afb2015-03-02 11:51:23 -0800443 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);
Romain Guycbb89e42009-06-08 15:52:54 -0700444
Daniel Sandlerff02d492013-08-05 02:12:05 -0400445 mStats = new Stats(this);
446
Sunny Goyalffe83f12014-08-14 17:39:34 -0700447 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700448
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700449 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
450 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700451
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700452 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
453 // this also ensures that any synchronous binding below doesn't re-trigger another
454 // LauncherModel load.
455 mPaused = false;
456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200458 android.os.Debug.startMethodTracing(
459 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 }
461
462 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700466 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800468 registerContentObservers();
469
Joe Onorato7c312c12009-08-13 21:36:53 -0700470 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700471
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800472 mSavedState = savedInstanceState;
473 restoreState(mSavedState);
474
475 if (PROFILE_STARTUP) {
476 android.os.Debug.stopMethodTracing();
477 }
478
479 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700480 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700481 // If the user leaves launcher, then we should just load items asynchronously when
482 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700483 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700484 } else {
485 // We only load the page synchronously if the user rotates (or triggers a
486 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700487 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700488 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800489 }
490
491 // For handling default keys
492 mDefaultKeySsb = new SpannableStringBuilder();
493 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800494
495 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
496 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800497
Adam Cohenf9426d52012-06-04 17:26:21 -0700498 // On large interfaces, we want the screen to auto-rotate based on the current orientation
499 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700500
Adam Cohen9211d422014-10-07 18:14:53 -0700501 if (mLauncherCallbacks != null) {
502 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700503 if (mLauncherCallbacks.hasLauncherOverlay()) {
504 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700505 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
506 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
507 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700508 mWorkspace.setLauncherOverlay(mLauncherOverlay);
509 }
Adam Cohen9211d422014-10-07 18:14:53 -0700510 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700511
512 if (shouldShowIntroScreen()) {
513 showIntroScreen();
514 } else {
515 showFirstRunActivity();
516 showFirstRunClings();
517 }
Adam Cohen9211d422014-10-07 18:14:53 -0700518 }
519
520 private LauncherCallbacks mLauncherCallbacks;
521
522 public void onPostCreate(Bundle savedInstanceState) {
523 super.onPostCreate(savedInstanceState);
524 if (mLauncherCallbacks != null) {
525 mLauncherCallbacks.onPostCreate(savedInstanceState);
526 }
527 }
528
529 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
530 mLauncherCallbacks = callbacks;
Winson Chung0f785722015-04-08 10:27:49 -0700531 mLauncherCallbacks.setLauncherAppsCallback(new Launcher.LauncherAppsCallbacks() {
532 @Override
533 public void onAllAppsBoundsChanged(Rect bounds) {
Winson Chungcd99cd32015-04-29 11:03:24 -0700534 if (LOGD) {
535 Log.d(TAG, "onAllAppsBoundsChanged(Rect): " + bounds);
536 }
Winson Chung94804152015-05-08 13:06:44 -0700537 mAppsView.setFixedBounds(bounds);
538 mWidgetsView.setFixedBounds(bounds);
Winson Chung0f785722015-04-08 10:27:49 -0700539 }
540
541 @Override
542 public void dismissAllApps() {
Winson Chung83f59ab2015-05-05 17:21:58 -0700543 if (!DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
544 // Dismiss All Apps if we aren't already paused/invisible
545 if (!mPaused) {
546 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true,
547 null /* onCompleteRunnable */, false /* notifyLauncherCallbacks */);
548 }
Winson Chungcd99cd32015-04-29 11:03:24 -0700549 }
Winson Chung0f785722015-04-08 10:27:49 -0700550 }
551 });
Adam Cohen9211d422014-10-07 18:14:53 -0700552 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700553 }
554
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700555 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700556 public void onLauncherProviderChange() {
557 if (mLauncherCallbacks != null) {
558 mLauncherCallbacks.onLauncherProviderChange();
559 }
560 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700561
Adam Cohen9211d422014-10-07 18:14:53 -0700562 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700563 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700564 if (mLauncherCallbacks != null) {
565 return mLauncherCallbacks.hasCustomContentToLeft();
566 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700567 return false;
568 }
569
Dave Hawkeya8881582013-09-17 15:55:33 -0600570 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500571 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600572 * {@link #addToCustomContentPage}. This will only be invoked if
573 * {@link #hasCustomContentToLeft()} is {@code true}.
574 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500575 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700576 if (mLauncherCallbacks != null) {
577 mLauncherCallbacks.populateCustomContentContainer();
578 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600579 }
580
581 /**
582 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
583 * ensure the custom content page is added or removed if necessary.
584 */
585 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600586 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600587 // Not bound yet, wait for bindScreens to be called.
588 return;
589 }
590
591 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
592 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500593 mWorkspace.createCustomContentContainer();
594 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600595 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
596 mWorkspace.removeCustomContentPage();
597 }
598 }
599
Adam Cohen091440a2015-03-18 14:16:05 -0700600 @Thunk void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601 if (sLocaleConfiguration == null) {
602 new AsyncTask<Void, Void, LocaleConfiguration>() {
603 @Override
604 protected LocaleConfiguration doInBackground(Void... unused) {
605 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
606 readConfiguration(Launcher.this, localeConfiguration);
607 return localeConfiguration;
608 }
609
610 @Override
611 protected void onPostExecute(LocaleConfiguration result) {
612 sLocaleConfiguration = result;
613 checkForLocaleChange(); // recursive, but now with a locale configuration
614 }
615 }.execute();
616 return;
617 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700618
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800619 final Configuration configuration = getResources().getConfiguration();
620
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700621 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800622 final String locale = configuration.locale.toString();
623
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700624 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800625 final int mcc = configuration.mcc;
626
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700627 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800628 final int mnc = configuration.mnc;
629
Romain Guy84f296c2009-11-04 15:00:44 -0800630 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800631
Romain Guy84f296c2009-11-04 15:00:44 -0800632 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700633 sLocaleConfiguration.locale = locale;
634 sLocaleConfiguration.mcc = mcc;
635 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700636
Joe Onorato0589f0f2010-02-08 13:44:00 -0800637 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700638
639 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100640 new AsyncTask<Void, Void, Void>() {
641 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700642 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100643 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700644 }
Michael Jurka43467462013-11-14 12:03:58 +0100645 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700646 }
647 }
648
Adam Cohen091440a2015-03-18 14:16:05 -0700649 @Thunk static class LocaleConfiguration {
Romain Guy98d01652009-06-30 16:21:04 -0700650 public String locale;
651 public int mcc = -1;
652 public int mnc = -1;
653 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700654
Adam Cohen091440a2015-03-18 14:16:05 -0700655 @Thunk static void readConfiguration(Context context, LocaleConfiguration configuration) {
Romain Guy98d01652009-06-30 16:21:04 -0700656 DataInputStream in = null;
657 try {
Helena Josol28db2802014-10-09 17:04:09 +0100658 in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
Romain Guy98d01652009-06-30 16:21:04 -0700659 configuration.locale = in.readUTF();
660 configuration.mcc = in.readInt();
661 configuration.mnc = in.readInt();
662 } catch (FileNotFoundException e) {
663 // Ignore
664 } catch (IOException e) {
665 // Ignore
666 } finally {
667 if (in != null) {
668 try {
669 in.close();
670 } catch (IOException e) {
671 // Ignore
672 }
673 }
674 }
675 }
676
Adam Cohen091440a2015-03-18 14:16:05 -0700677 @Thunk static void writeConfiguration(Context context, LocaleConfiguration configuration) {
Romain Guy98d01652009-06-30 16:21:04 -0700678 DataOutputStream out = null;
679 try {
Helena Josol4fbbb3e2014-10-06 16:06:46 +0100680 out = new DataOutputStream(context.openFileOutput(
Helena Josol28db2802014-10-09 17:04:09 +0100681 LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE));
Romain Guy98d01652009-06-30 16:21:04 -0700682 out.writeUTF(configuration.locale);
683 out.writeInt(configuration.mcc);
684 out.writeInt(configuration.mnc);
685 out.flush();
686 } catch (FileNotFoundException e) {
687 // Ignore
688 } catch (IOException e) {
689 //noinspection ResultOfMethodCallIgnored
Helena Josol28db2802014-10-09 17:04:09 +0100690 context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete();
Romain Guy98d01652009-06-30 16:21:04 -0700691 } finally {
692 if (out != null) {
693 try {
694 out.close();
695 } catch (IOException e) {
696 // Ignore
697 }
698 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 }
700 }
701
Anton Hanssona2f665f2013-09-26 12:18:32 +0100702 public Stats getStats() {
703 return mStats;
704 }
705
Bjorn Bringertc459e522013-06-07 19:36:01 +0100706 public LayoutInflater getInflater() {
707 return mInflater;
708 }
709
Hyunyoung Song3f471442015-04-08 19:01:34 -0700710 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700711 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
712 // that is subsequently removed from the workspace in startBinding().
713 return !mModel.isLoadingWorkspace();
714 }
715
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800716 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000717 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100718 if (Build.VERSION.SDK_INT >= 17) {
719 return View.generateViewId();
720 } else {
721 // View.generateViewId() is not available. The following fallback logic is a copy
722 // of its implementation.
723 for (;;) {
724 final int result = sNextGeneratedId.get();
725 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
726 int newValue = result + 1;
727 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
728 if (sNextGeneratedId.compareAndSet(result, newValue)) {
729 return result;
730 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000731 }
732 }
733 }
734
735 public int getViewIdForItem(ItemInfo info) {
736 // This cast is safe given the > 2B range for int.
737 int itemId = (int) info.id;
738 if (mItemIdToViewId.containsKey(itemId)) {
739 return mItemIdToViewId.get(itemId);
740 }
741 int viewId = generateViewId();
742 mItemIdToViewId.put(itemId, viewId);
743 return viewId;
744 }
745
746 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700747 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
748 * a configuration step, this allows the proper animations to run after other transitions.
749 */
Adam Cohendb364c32014-05-20 14:23:40 -0700750 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700751 long screenId = args.screenId;
752 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
753 // When the screen id represents an actual screen (as opposed to a rank) we make sure
754 // that the drop page actually exists.
755 screenId = ensurePendingDropLayoutExists(args.screenId);
756 }
Adam Cohendb364c32014-05-20 14:23:40 -0700757
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800758 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800759 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700760 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700761 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700762 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800763 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700764 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700765 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700766 case REQUEST_RECONFIGURE_APPWIDGET:
767 completeRestoreAppWidget(args.appWidgetId);
768 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800769 }
Michael Jurka27614d22012-04-02 06:40:22 -0700770 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
771 // if you turned the screen off and then back while in All Apps, Launcher would not
772 // return to the workspace. Clearing mAddInfo.container here fixes this issue
773 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700774 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800775 }
776
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800777 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700779 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700780 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700781 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800782 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700783
Adam Cohenad4e15c2013-10-17 16:21:35 -0700784 Runnable exitSpringLoaded = new Runnable() {
785 @Override
786 public void run() {
787 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
788 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
789 }
790 };
791
Michael Jurka8b805b12012-04-18 14:23:14 -0700792 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700793 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700794 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
795 if (resultCode == RESULT_CANCELED) {
796 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700797 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700798 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700799 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800800 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700801 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700802 }
803 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200804 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
805 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -0700806 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200807 }
808 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700809 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200810
Adam Cohened66b2b2012-01-23 17:28:51 -0800811 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Hyunyoung Songb7900832015-05-15 16:29:45 -0700812 requestCode == REQUEST_CREATE_APPWIDGET || requestCode == REQUEST_CREATE_SHORTCUT);
Romain Guyaad5ef42009-06-10 02:48:37 -0700813
Adam Cohendb364c32014-05-20 14:23:40 -0700814 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800815 // We have special handling for widgets
816 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800817 final int appWidgetId;
818 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
819 : -1;
820 if (widgetId < 0) {
821 appWidgetId = pendingAddWidgetId;
822 } else {
823 appWidgetId = widgetId;
824 }
825
Adam Cohenad4e15c2013-10-17 16:21:35 -0700826 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800827 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700828 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
829 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700830 result = RESULT_CANCELED;
831 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700832 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700833 @Override
834 public void run() {
835 exitSpringLoadedDragModeDelayed(false, 0, null);
836 }
837 };
Adam Cohendb364c32014-05-20 14:23:40 -0700838 if (workspaceLocked) {
839 // No need to remove the empty screen if we're mid-binding, as the
840 // the bind will not add the empty screen.
841 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
842 } else {
843 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
844 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
845 }
Winson Chung5aaab772012-04-27 15:24:02 -0700846 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700847 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700848 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
849 // When the screen id represents an actual screen (as opposed to a rank)
850 // we make sure that the drop page actually exists.
851 mPendingAddInfo.screenId =
852 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
853 }
Adam Cohendb364c32014-05-20 14:23:40 -0700854 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
855
856 dropLayout.setDropPending(true);
857 final Runnable onComplete = new Runnable() {
858 @Override
859 public void run() {
860 completeTwoStageWidgetDrop(resultCode, appWidgetId);
861 dropLayout.setDropPending(false);
862 }
863 };
864 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
865 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
866 } else {
867 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
868 mPendingAddInfo);
869 sPendingAddItem = args;
870 }
Winson Chung5aaab772012-04-27 15:24:02 -0700871 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800872 return;
873 }
874
Sunny Goyalff572272014-07-23 13:58:07 -0700875 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
876 if (resultCode == RESULT_OK) {
877 // Update the widget view.
878 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
879 pendingAddWidgetId, mPendingAddInfo);
880 if (workspaceLocked) {
881 sPendingAddItem = args;
882 } else {
883 completeAdd(args);
884 }
885 }
886 // Leave the widget in the pending state if the user canceled the configure.
887 return;
888 }
889
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890 // The pattern used here is that a user PICKs a specific application,
891 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700892
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800893 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
894 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700895 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700896 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
897 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800898 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700899 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800900 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700901 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700902 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
903 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800904 }
Adam Cohen00074722013-10-11 17:46:09 -0700905 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700906 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700907 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800908 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800909 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800910
911 }
912
913 @Override
914 protected void onActivityResult(
915 final int requestCode, final int resultCode, final Intent data) {
916 handleActivityResult(requestCode, resultCode, data);
917 if (mLauncherCallbacks != null) {
918 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
919 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800920 }
921
Adam Cohendb364c32014-05-20 14:23:40 -0700922 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
923 appWidgetId, ItemInfo info) {
924 PendingAddArguments args = new PendingAddArguments();
925 args.requestCode = requestCode;
926 args.intent = data;
927 args.container = info.container;
928 args.screenId = info.screenId;
929 args.cellX = info.cellX;
930 args.cellY = info.cellY;
931 args.appWidgetId = appWidgetId;
932 return args;
933 }
934
935 /**
936 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
937 *
938 * @param screenId the screen id to check
939 * @return the new screen, or screenId if it exists
940 */
941 private long ensurePendingDropLayoutExists(long screenId) {
942 CellLayout dropLayout =
943 (CellLayout) mWorkspace.getScreenWithId(screenId);
944 if (dropLayout == null) {
945 // it's possible that the add screen was removed because it was
946 // empty and a re-bind occurred
947 mWorkspace.addExtraEmptyScreen();
948 return mWorkspace.commitExtraEmptyScreen();
949 } else {
950 return screenId;
951 }
952 }
953
Adam Cohen091440a2015-03-18 14:16:05 -0700954 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700955 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700956 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800957 Runnable onCompleteRunnable = null;
958 int animationType = 0;
959
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700960 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800961 if (resultCode == RESULT_OK) {
962 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
963 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700964 mPendingAddWidgetInfo);
965 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800966 onCompleteRunnable = new Runnable() {
967 @Override
968 public void run() {
969 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700970 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700971 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
972 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800973 }
974 };
975 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800976 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800977 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800978 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700979 if (mDragLayer.getAnimatedView() != null) {
980 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
981 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
982 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700983 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700984 // The animated view may be null in the case of a rotation during widget configuration
985 onCompleteRunnable.run();
986 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987 }
988
989 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700990 protected void onStop() {
991 super.onStop();
992 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700993
994 if (mLauncherCallbacks != null) {
995 mLauncherCallbacks.onStop();
996 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700997 }
998
999 @Override
1000 protected void onStart() {
1001 super.onStart();
1002 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -07001003
1004 if (mLauncherCallbacks != null) {
1005 mLauncherCallbacks.onStart();
1006 }
Michael Jurkacd496d72013-04-11 11:32:45 -07001007 }
1008
1009 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +02001011 long startTime = 0;
1012 if (DEBUG_RESUME_TIME) {
1013 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -04001014 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +02001015 }
Adam Cohen9211d422014-10-07 18:14:53 -07001016
1017 if (mLauncherCallbacks != null) {
1018 mLauncherCallbacks.preOnResume();
1019 }
1020
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001021 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001022
Winson Chung4a2afa32012-07-19 14:53:05 -07001023 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001024 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001025 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001026 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001027 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001028 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001029 // view after launching an app, as they may be depending on the UI to be static to
1030 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -07001031 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung13eb5272015-05-11 16:30:13 -07001032 !launchedFromApp /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08001033 } else if (mOnResumeState == State.WIDGETS) {
1034 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001035 }
1036 mOnResumeState = State.NONE;
1037
Winson Chungcd99cd32015-04-29 11:03:24 -07001038 // Restore the apps state if we are in all apps
Winson Chung4ac30062015-05-08 17:34:17 -07001039 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
1040 // Otherwise, notify the callbacks if we are in all apps mode
1041 if (mState == State.APPS) {
1042 if (mLauncherCallbacks != null) {
1043 mLauncherCallbacks.onAllAppsShown();
1044 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001045 }
1046 }
1047
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001048 // Background was set to gradient in onPause(), restore to transparent if in all apps.
1049 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_TRANSPARENT
1050 : WORKSPACE_BACKGROUND_GRADIENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001051
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001052 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001053 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001054 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001055 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001056 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001057 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001059 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001060 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1061 // execute them here
1062 long startTimeCallbacks = 0;
1063 if (DEBUG_RESUME_TIME) {
1064 startTimeCallbacks = System.currentTimeMillis();
1065 }
1066
Michael Jurka1e2f4652013-07-08 18:03:46 -07001067 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1068 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001069 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001070 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001071 if (DEBUG_RESUME_TIME) {
1072 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1073 (System.currentTimeMillis() - startTimeCallbacks));
1074 }
Michael Jurka447bf842013-05-15 14:52:15 +02001075 }
Michael Jurka54554252013-08-01 12:52:23 +02001076 if (mOnResumeCallbacks.size() > 0) {
1077 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1078 mOnResumeCallbacks.get(i).run();
1079 }
1080 mOnResumeCallbacks.clear();
1081 }
Winson Chunge4e50662012-01-23 14:45:13 -08001082
1083 // Reset the pressed state of icons that were locked in the press state while activities
1084 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001085 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001086 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001087 mWaitingForResume.setStayPressed(false);
1088 }
Winson Chung82963d52013-10-09 11:20:57 -07001089
Adam Cohen06dff352012-06-01 17:17:08 -07001090 // It is possible that widgets can receive updates while launcher is not in the foreground.
1091 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1092 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1093 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001094 getWorkspace().reinflateWidgetsIfNecessary();
Sunny Goyal22235bc2015-04-03 09:23:43 -07001095 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001096
Michael Jurka447bf842013-05-15 14:52:15 +02001097 if (DEBUG_RESUME_TIME) {
1098 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1099 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001100
1101 if (mWorkspace.getCustomContentCallbacks() != null) {
1102 // If we are resuming and the custom content is the current page, we call onShow().
1103 // It is also poassible that onShow will instead be called slightly after first layout
1104 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1105 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001106 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001107 }
1108 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001109 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001110 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001111
Sunny Goyal756adbc2015-04-16 15:20:51 -07001112 if (!isWorkspaceLoading()) {
1113 // Process any items that were added while Launcher was away.
1114 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1115 }
Adam Cohen9211d422014-10-07 18:14:53 -07001116
1117 if (mLauncherCallbacks != null) {
1118 mLauncherCallbacks.onResume();
1119 }
Adam Cohen06dff352012-06-01 17:17:08 -07001120 }
1121
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001123 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001124 // Ensure that items added to Launcher are queued until Launcher returns
1125 InstallShortcutReceiver.enableInstallQueue();
1126
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001127 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001128 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001129 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001130 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001131
1132 // We call onHide() aggressively. The custom content callbacks should be able to
1133 // debounce excess onHide calls.
1134 if (mWorkspace.getCustomContentCallbacks() != null) {
1135 mWorkspace.getCustomContentCallbacks().onHide();
1136 }
Romain Guycbb89e42009-06-08 15:52:54 -07001137
Adam Cohen9211d422014-10-07 18:14:53 -07001138 if (mLauncherCallbacks != null) {
1139 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001140 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001141 }
1142
1143 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001144 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1145 // by a onResume or by scrolling otherwise.
1146 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001147
1148 // Custom content is completely hidden
1149 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001150
1151 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1152 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001153
1154 // Indicates whether the user is allowed to scroll away from the custom content.
1155 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001156 }
1157
Adam Cohenc2d6e892014-10-16 09:49:24 -07001158 public interface LauncherOverlay {
1159
1160 /**
1161 * Touch interaction leading to overscroll has begun
1162 */
1163 public void onScrollInteractionBegin();
1164
1165 /**
1166 * Touch interaction related to overscroll has ended
1167 */
1168 public void onScrollInteractionEnd();
1169
1170 /**
1171 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1172 * screen (or in the case of RTL, the rightmost screen).
1173 */
1174 public void onScrollChange(int progress, boolean rtl);
1175
1176 /**
1177 * Screen has stopped scrolling
1178 */
1179 public void onScrollSettled();
1180
1181 /**
1182 * This method can be called by the Launcher in order to force the LauncherOverlay
1183 * to exit fully immersive mode.
1184 */
1185 public void forceExitFullImmersion();
1186 }
1187
Winson Chung0f785722015-04-08 10:27:49 -07001188 public interface LauncherAppsCallbacks {
1189 /**
1190 * Updates launcher to the available space that AllApps can take so as not to overlap with
1191 * any other views.
1192 */
1193 public void onAllAppsBoundsChanged(Rect bounds);
1194
1195 /**
1196 * Called to dismiss all apps if it is showing.
1197 */
1198 public void dismissAllApps();
1199 }
1200
Adam Cohenc2d6e892014-10-16 09:49:24 -07001201 public interface LauncherOverlayCallbacks {
1202 /**
1203 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1204 * however it doesn't modify any state within the launcher.
1205 */
1206 public boolean canEnterFullImmersion();
1207
1208 /**
1209 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1210 * eg. by occupying the full screen and handling all touch events.
1211 *
1212 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1213 * case, Launcher will modify any necessary state and assumes the overlay is
1214 * handling all interaction. If false, the LauncherOverlay should cancel any
1215 *
1216 */
1217 public boolean enterFullImmersion();
1218
1219 /**
1220 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1221 * full control over UI and state.
1222 */
1223 public void exitFullImmersion();
1224 }
1225
1226 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1227
1228 @Override
1229 public boolean canEnterFullImmersion() {
1230 return mState == State.WORKSPACE;
1231 }
1232
1233 @Override
1234 public boolean enterFullImmersion() {
1235 if (mState == State.WORKSPACE) {
1236 // When fully immersed, disregard any touches which fall through.
1237 mDragLayer.setBlockTouch(true);
1238 return true;
1239 }
1240 return false;
1241 }
1242
1243 @Override
1244 public void exitFullImmersion() {
1245 mDragLayer.setBlockTouch(false);
1246 }
1247 }
1248
Jorim Jaggid017f882014-01-14 17:08:48 -08001249 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001250 if (mLauncherCallbacks != null) {
1251 return mLauncherCallbacks.hasSettings();
1252 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001253 return false;
1254 }
1255
Adam Cohen9211d422014-10-07 18:14:53 -07001256 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001257 CustomContentCallbacks callbacks, String description) {
1258 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001259 }
1260
Adam Cohenedb40762013-07-18 16:45:45 -07001261 // The custom content needs to offset its content to account for the QSB
1262 public int getTopOffsetForCustomContent() {
1263 return mWorkspace.getPaddingTop();
1264 }
1265
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001266 @Override
1267 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001268 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001269 if (mModel.isCurrentCallbacks(this)) {
1270 mModel.stopLoader();
1271 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001272 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1273
Romain Guy13c2e7b2010-03-10 19:45:00 -08001274 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001275 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001276
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001277 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001278 @Override
1279 public void onWindowFocusChanged(boolean hasFocus) {
1280 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001281 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001282
1283 if (mLauncherCallbacks != null) {
1284 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1285 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001286 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001287
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288 private boolean acceptFilter() {
1289 final InputMethodManager inputManager = (InputMethodManager)
1290 getSystemService(Context.INPUT_METHOD_SERVICE);
1291 return !inputManager.isFullscreenMode();
1292 }
1293
1294 @Override
1295 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001296 final int uniChar = event.getUnicodeChar();
1297 final boolean handled = super.onKeyDown(keyCode, event);
1298 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1299 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1301 keyCode, event);
1302 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001303 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001304 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001305 // showSearchDialog()
1306 // If there are multiple keystrokes before the search dialog takes focus,
1307 // onSearchRequested() will be called for every keystroke,
1308 // but it is idempotent, so it's fine.
1309 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 }
1311 }
1312
Joe Onorato8a9625e2010-01-28 15:55:35 -08001313 // Eat the long press event so the keyboard doesn't come up.
1314 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1315 return true;
1316 }
1317
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 return handled;
1319 }
1320
Karl Rosaen138a0412009-04-23 19:00:21 -07001321 private String getTypedText() {
1322 return mDefaultKeySsb.toString();
1323 }
1324
1325 private void clearTypedText() {
1326 mDefaultKeySsb.clear();
1327 mDefaultKeySsb.clearSpans();
1328 Selection.setSelection(mDefaultKeySsb, 0);
1329 }
1330
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001332 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1333 * State
1334 */
1335 private static State intToState(int stateOrdinal) {
1336 State state = State.WORKSPACE;
1337 final State[] stateValues = State.values();
1338 for (int i = 0; i < stateValues.length; i++) {
1339 if (stateValues[i].ordinal() == stateOrdinal) {
1340 state = stateValues[i];
1341 break;
1342 }
1343 }
1344 return state;
1345 }
1346
1347 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001348 * Restores the previous state, if it exists.
1349 *
1350 * @param savedState The previous state.
1351 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001352 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 private void restoreState(Bundle savedState) {
1354 if (savedState == null) {
1355 return;
1356 }
1357
Michael Jurka883f55b2010-10-21 15:47:14 -07001358 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001359 if (state == State.APPS || state == State.WIDGETS) {
1360 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001361 }
1362
Adam Cohen21cd0022013-10-09 18:57:02 -07001363 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1364 PagedView.INVALID_RESTORE_PAGE);
1365 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001366 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367 }
1368
Winson Chung3d503fb2011-07-13 17:25:49 -07001369 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001370 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001371
Winson Chung3d503fb2011-07-13 17:25:49 -07001372 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1373 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001374 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001375 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1376 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001377 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1378 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Adam Cohenb823ae42015-03-27 18:07:52 -07001379 AppWidgetProviderInfo info = savedState.getParcelable(
1380 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001381 mPendingAddWidgetInfo = info == null ?
1382 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1383
Adam Cohen4637b5a2013-11-04 18:21:24 -08001384 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001385 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001386 mRestoring = true;
1387 }
1388
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001389 mItemIdToViewId = (HashMap<Integer, Integer>)
1390 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 }
1392
1393 /**
1394 * Finds all the views we need and configure them properly.
1395 */
1396 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001397 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001398
Craig Mautner360310b2012-10-26 15:13:08 -07001399 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001400 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001401 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1402 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001403 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001404 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001405
John Spurlock77e1f472013-09-11 10:09:51 -04001406 mLauncherView.setSystemUiVisibility(
1407 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001408 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001409
Winson Chung4c98d922011-05-31 16:50:48 -07001410 // Setup the drag layer
1411 mDragLayer.setup(this, dragController);
1412
Winson Chung3d503fb2011-07-13 17:25:49 -07001413 // Setup the hotseat
1414 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1415 if (mHotseat != null) {
1416 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001417 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001418 }
1419
Jorim Jaggid017f882014-01-14 17:08:48 -08001420 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001421 View widgetButton = findViewById(R.id.widget_button);
1422 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001423 @Override
1424 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001425 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001426 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001427 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001428 }
1429 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001430 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1431
1432 View wallpaperButton = findViewById(R.id.wallpaper_button);
1433 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001434 @Override
1435 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001436 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001437 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001438 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001439 }
1440 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001441 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1442
1443 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001444 if (hasSettings()) {
1445 settingsButton.setOnClickListener(new OnClickListener() {
1446 @Override
1447 public void onClick(View arg0) {
1448 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001449 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001450 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001451 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001452 });
1453 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1454 } else {
1455 settingsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001456 }
1457
Adam Cohendbdff6b2013-09-18 19:09:15 -07001458 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001459
Winson Chung4c98d922011-05-31 16:50:48 -07001460 // Setup the workspace
1461 mWorkspace.setHapticFeedbackEnabled(false);
1462 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001463 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001464 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001465
Winson Chungf0ea4d32011-06-06 14:27:16 -07001466 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001467 mSearchDropTargetBar = (SearchDropTargetBar)
1468 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001469
Winson Chungb745afb2015-03-02 11:51:23 -08001470 // Setup Apps
1471 mAppsView = (AppsContainerView) findViewById(R.id.apps_view);
Winson Chung83f59ab2015-05-05 17:21:58 -07001472 if (isAllAppsSearchOverridden()) {
1473 mAppsView.hideHeaderBar();
Winson Chung0f785722015-04-08 10:27:49 -07001474 }
Winson Chungb745afb2015-03-02 11:51:23 -08001475
Winson Chungf0ea4d32011-06-06 14:27:16 -07001476 // Setup AppsCustomize
Hyunyoung Song3f471442015-04-08 19:01:34 -07001477 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001478
Winson Chung3d503fb2011-07-13 17:25:49 -07001479 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001480 dragController.setDragScoller(mWorkspace);
1481 dragController.setScrollView(mDragLayer);
1482 dragController.setMoveTarget(mWorkspace);
1483 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001484 if (mSearchDropTargetBar != null) {
1485 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001486 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001487 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001488
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001489 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001490 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001491 mWeightWatcher = new WeightWatcher(this);
1492 mWeightWatcher.setAlpha(0.5f);
1493 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001494 new FrameLayout.LayoutParams(
1495 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001496 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001497 Gravity.BOTTOM)
1498 );
Adam Cohen39a06042013-07-19 14:30:12 -07001499
1500 boolean show = shouldShowWeightWatcher();
1501 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001502 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001503 }
1504
1505 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001506 * Sets the all apps button. This method is called from {@link Hotseat}.
1507 */
1508 public void setAllAppsButton(View allAppsButton) {
1509 mAllAppsButton = allAppsButton;
1510 }
1511
1512 public View getAllAppsButton() {
1513 return mAllAppsButton;
1514 }
1515
1516 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 * Creates a view representing a shortcut.
1518 *
1519 * @param info The data structure describing the shortcut.
1520 *
1521 * @return A View inflated from R.layout.application.
1522 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001523 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001524 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 }
1526
1527 /**
1528 * Creates a view representing a shortcut inflated from the specified resource.
1529 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001530 * @param parent The group the shortcut belongs to.
1531 * @param info The data structure describing the shortcut.
1532 *
1533 * @return A View inflated from layoutResId.
1534 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001535 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
1536 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(R.layout.application,
1537 parent, false);
1538 favorite.applyFromShortcutInfo(info, mIconCache);
1539 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001540 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001541 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 return favorite;
1543 }
1544
1545 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546 * Add a shortcut to the workspace.
1547 *
1548 * @param data The intent describing the shortcut.
1549 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001550 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001551 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001552 int cellY) {
1553 int[] cellXY = mTmpAddItemCellCoordinates;
1554 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001555 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001556
Michael Jurkad3ef3062010-11-23 16:23:58 -08001557 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001558
Sunny Goyal2350bc92014-10-14 16:42:54 -07001559 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001560 if (info == null) {
1561 return;
1562 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001563 final View view = createShortcut(info);
1564
Adam Cohenfbba09b2011-07-18 21:43:05 -07001565 // First we check if we already know the exact location where we want to add this item.
1566 if (cellX >= 0 && cellY >= 0) {
1567 cellXY[0] = cellX;
1568 cellXY[1] = cellY;
1569 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001570
1571 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001572 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001573 true, null,null)) {
1574 return;
1575 }
1576 DragObject dragObject = new DragObject();
1577 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001578 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1579 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001580 return;
1581 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001582 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001583 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001584 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001585 foundCellSpan = (result != null);
1586 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001587 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001588 }
1589
1590 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001591 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001592 return;
1593 }
1594
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001595 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596
1597 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001598 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001599 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001600 }
1601 }
1602
Adam Cohen2f093b62012-04-30 18:59:53 -07001603 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1604 int minHeight) {
1605 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001606 // We want to account for the extra amount of padding that we are adding to the widget
1607 // to ensure that it gets the full amount of space that it has requested
1608 int requiredWidth = minWidth + padding.left + padding.right;
1609 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001610 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001611 }
1612
Adam Cohen2f093b62012-04-30 18:59:53 -07001613 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1614 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001615 }
1616
Adam Cohen2f093b62012-04-30 18:59:53 -07001617 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1618 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001619 }
1620
Adam Cohen2f093b62012-04-30 18:59:53 -07001621 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1622 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001623 }
1624
Adam Cohen2f093b62012-04-30 18:59:53 -07001625 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1626 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001627 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001628 }
1629
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001630 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001631 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001632 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001633 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001634 */
Adam Cohen091440a2015-03-18 14:16:05 -07001635 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001636 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1637
1638 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001639 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001640 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1641 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001642 }
Romain Guycbb89e42009-06-08 15:52:54 -07001643
Adam Cohen59400422014-03-05 18:07:04 -08001644 if (appWidgetInfo.isCustomWidget) {
1645 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001646 }
1647
Adam Cohen59400422014-03-05 18:07:04 -08001648 LauncherAppWidgetInfo launcherInfo;
1649 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1650 launcherInfo.spanX = info.spanX;
1651 launcherInfo.spanY = info.spanY;
1652 launcherInfo.minSpanX = info.minSpanX;
1653 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001654 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001655
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001656 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001657 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001658
1659 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001660 if (hostView == null) {
1661 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001662 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1663 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001664 } else {
1665 // The AppWidgetHostView has already been inflated and instantiated
1666 launcherInfo.hostView = hostView;
1667 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001668 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001669 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001670 launcherInfo.notifyWidgetSizeChanged(this);
1671
Adam Cohen59400422014-03-05 18:07:04 -08001672 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
1673 info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001674
1675 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001676 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001677 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001678 }
Romain Guycbb89e42009-06-08 15:52:54 -07001679
Adam Cohended9f8d2010-11-03 13:25:16 -07001680 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1681 @Override
1682 public void onReceive(Context context, Intent intent) {
1683 final String action = intent.getAction();
1684 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1685 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001686 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001687 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001688
Winson Chungc100e8e2011-08-09 16:02:43 -07001689 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001690 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001691 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001692 mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001693 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001694 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001695 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1696 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001697 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001698 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_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 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1703 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001704 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001705 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1706 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001707 }
1708 }
1709 };
1710
1711 @Override
1712 public void onAttachedToWindow() {
1713 super.onAttachedToWindow();
1714
1715 // Listen for broadcasts related to user-presence
1716 final IntentFilter filter = new IntentFilter();
1717 filter.addAction(Intent.ACTION_SCREEN_OFF);
1718 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001719 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001720 if (ENABLE_DEBUG_INTENTS) {
1721 filter.addAction(DebugIntents.DELETE_DATABASE);
1722 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1723 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001724 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001725 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001726 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001727 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001728 mVisible = true;
1729 }
1730
Adam Cohen0b395352014-06-09 22:54:36 +00001731 /**
1732 * Sets up transparent navigation and status bars in LMP.
1733 * This method is a no-op for other platform versions.
1734 */
Sunny Goyald0091012015-01-20 15:55:34 -08001735 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Adam Cohen0b395352014-06-09 22:54:36 +00001736 private void setupTransparentSystemBarsForLmp() {
Kenny Guyd794a3f2014-09-16 15:17:58 +01001737 if (Utilities.isLmpOrAbove()) {
Sunny Goyald0091012015-01-20 15:55:34 -08001738 Window window = getWindow();
1739 window.getAttributes().systemUiVisibility |=
1740 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1741 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1742 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1743 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1744 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1745 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
1746 window.setStatusBarColor(Color.TRANSPARENT);
1747 window.setNavigationBarColor(Color.TRANSPARENT);
Adam Cohen0b395352014-06-09 22:54:36 +00001748 }
1749 }
1750
Adam Cohended9f8d2010-11-03 13:25:16 -07001751 @Override
1752 public void onDetachedFromWindow() {
1753 super.onDetachedFromWindow();
1754 mVisible = false;
1755
Adam Cohend113e0c2010-11-11 10:48:05 -08001756 if (mAttached) {
1757 unregisterReceiver(mReceiver);
1758 mAttached = false;
1759 }
Winson Chungb745afb2015-03-02 11:51:23 -08001760 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001761 }
1762
1763 public void onWindowVisibilityChanged(int visibility) {
1764 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001765 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001766 // The following code used to be in onResume, but it turns out onResume is called when
1767 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1768 // is a more appropriate event to handle
1769 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001770 if (!mWorkspaceLoading) {
1771 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001772 // We want to let Launcher draw itself at least once before we force it to build
1773 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001774 // apps is nice and speedy.
1775 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001776 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001777 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001778 if (mStarted) return;
1779 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001780 // We delay the layer building a bit in order to give
1781 // other message processing a time to run. In particular
1782 // this avoids a delay in hiding the IME if it was
1783 // currently shown, because doing that may involve
1784 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001785 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001786 final ViewTreeObserver.OnDrawListener listener = this;
1787 mWorkspace.post(new Runnable() {
1788 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001789 if (mWorkspace != null &&
1790 mWorkspace.getViewTreeObserver() != null) {
1791 mWorkspace.getViewTreeObserver().
1792 removeOnDrawListener(listener);
1793 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001794 }
1795 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001796 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001797 }
1798 });
1799 }
1800 clearTypedText();
1801 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001802 }
1803
Adam Cohen091440a2015-03-18 14:16:05 -07001804 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001805 mHandler.removeMessages(ADVANCE_MSG);
1806 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1807 mHandler.sendMessageDelayed(msg, delay);
1808 mAutoAdvanceSentTime = System.currentTimeMillis();
1809 }
1810
Adam Cohen091440a2015-03-18 14:16:05 -07001811 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001812 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1813 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1814 mAutoAdvanceRunning = autoAdvanceRunning;
1815 if (autoAdvanceRunning) {
1816 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1817 sendAdvanceMessage(delay);
1818 } else {
1819 if (!mWidgetsToAdvance.isEmpty()) {
1820 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1821 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1822 }
1823 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001824 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001825 }
1826 }
1827 }
1828
1829 private final Handler mHandler = new Handler() {
1830 @Override
1831 public void handleMessage(Message msg) {
1832 if (msg.what == ADVANCE_MSG) {
1833 int i = 0;
1834 for (View key: mWidgetsToAdvance.keySet()) {
1835 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1836 final int delay = mAdvanceStagger * i;
1837 if (v instanceof Advanceable) {
1838 postDelayed(new Runnable() {
1839 public void run() {
1840 ((Advanceable) v).advance();
1841 }
1842 }, delay);
1843 }
1844 i++;
1845 }
1846 sendAdvanceMessage(mAdvanceInterval);
1847 }
1848 }
1849 };
1850
1851 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001852 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001853 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1854 if (v instanceof Advanceable) {
1855 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001856 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001857 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001858 }
1859 }
1860
1861 void removeWidgetToAutoAdvance(View hostView) {
1862 if (mWidgetsToAdvance.containsKey(hostView)) {
1863 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001864 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001865 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001866 }
1867
Joe Onorato9c1289c2009-08-17 11:03:03 -04001868 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001869 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001870 launcherInfo.hostView = null;
1871 }
1872
Hyunyoung Song3f471442015-04-08 19:01:34 -07001873 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001874 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1875 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001876 }
1877
Winson Chunga6945242014-01-08 14:04:34 -08001878 public DragLayer getDragLayer() {
1879 return mDragLayer;
1880 }
1881
Winson Chungb745afb2015-03-02 11:51:23 -08001882 public AppsContainerView getAppsView() {
1883 return mAppsView;
1884 }
1885
Hyunyoung Song3f471442015-04-08 19:01:34 -07001886 public WidgetsContainerView getWidgetsView() {
1887 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001888 }
1889
Winson Chunga6945242014-01-08 14:04:34 -08001890 public Workspace getWorkspace() {
1891 return mWorkspace;
1892 }
1893
1894 public Hotseat getHotseat() {
1895 return mHotseat;
1896 }
1897
Jorim Jaggid017f882014-01-14 17:08:48 -08001898 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001899 return mOverviewPanel;
1900 }
1901
1902 public SearchDropTargetBar getSearchBar() {
1903 return mSearchDropTargetBar;
1904 }
1905
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001906 public LauncherAppWidgetHost getAppWidgetHost() {
1907 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 }
Romain Guycbb89e42009-06-08 15:52:54 -07001909
Winson Chunga9abd0e2010-10-27 17:18:37 -07001910 public LauncherModel getModel() {
1911 return mModel;
1912 }
1913
Winson Chunga6945242014-01-08 14:04:34 -08001914 protected SharedPreferences getSharedPrefs() {
1915 return mSharedPrefs;
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 Jurka05bf644e2011-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 Sandler6053b8002013-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 Cohen59400422014-03-05 18:07:04 -08004023 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(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 Goyaldfaccf62015-05-11 16:30:44 -07004207 return mDeviceProfile.getSearchBarBounds();
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
Adam Cohen091440a2015-03-18 14:16:05 -07004382 @Thunk ArrayList<Object> mWidgetsAndShortcuts;
Michael Jurkac402cd92013-05-20 15:49:32 +02004383 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004384 public void run() {
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004385 bindAllPackages(mWidgetsAndShortcuts);
Winson Chung83892cc2013-05-01 16:53:33 -07004386 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004387 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004388
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004389 @Override
4390 public void bindAllPackages(final ArrayList<Object> widgetsAndShortcuts) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004391 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4392 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004393 return;
4394 }
4395
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004396 if (mWidgetsView != null && widgetsAndShortcuts != null) {
4397 mWidgetsView.addWidgets(widgetsAndShortcuts, getPackageManager());
4398 mWidgetsAndShortcuts = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004399 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004400 }
4401
Winson Chung400438b2011-01-16 17:53:48 -08004402 private int mapConfigurationOriActivityInfoOri(int configOri) {
4403 final Display d = getWindowManager().getDefaultDisplay();
4404 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4405 switch (d.getRotation()) {
4406 case Surface.ROTATION_0:
4407 case Surface.ROTATION_180:
4408 // We are currently in the same basic orientation as the natural orientation
4409 naturalOri = configOri;
4410 break;
4411 case Surface.ROTATION_90:
4412 case Surface.ROTATION_270:
4413 // We are currently in the other basic orientation to the natural orientation
4414 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4415 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4416 break;
4417 }
4418
4419 int[] oriMap = {
4420 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4421 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4422 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4423 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4424 };
4425 // Since the map starts at portrait, we need to offset if this device's natural orientation
4426 // is landscape.
4427 int indexOffset = 0;
4428 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4429 indexOffset = 1;
4430 }
4431 return oriMap[(d.getRotation() + indexOffset) % 4];
4432 }
Adam Cohen446e9402011-09-15 18:21:21 -07004433
Winson Chung4b919f82012-05-01 10:44:08 -07004434 public void lockScreenOrientation() {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004435 if (Utilities.isRotationEnabled(this)) {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004436 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
4437 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4438 .getConfiguration().orientation));
4439 } else {
4440 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4441 }
Winson Chung4b919f82012-05-01 10:44:08 -07004442 }
4443 }
4444 public void unlockScreenOrientation(boolean immediate) {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004445 if (Utilities.isRotationEnabled(this)) {
Winson Chung4b919f82012-05-01 10:44:08 -07004446 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004447 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004448 } else {
4449 mHandler.postDelayed(new Runnable() {
4450 public void run() {
4451 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4452 }
4453 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004454 }
Winson Chung4b919f82012-05-01 10:44:08 -07004455 }
Winson Chung400438b2011-01-16 17:53:48 -08004456 }
4457
Winson Chunge43a1e72014-01-15 10:33:02 -08004458 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004459 if (mLauncherCallbacks != null) {
4460 return mLauncherCallbacks.isLauncherPreinstalled();
4461 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004462 PackageManager pm = getPackageManager();
4463 try {
4464 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4465 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4466 return true;
4467 } else {
4468 return false;
4469 }
4470 } catch (NameNotFoundException e) {
4471 e.printStackTrace();
4472 return false;
4473 }
4474 }
4475
Adam Cohenea90f832014-05-21 15:03:34 -07004476 /**
4477 * This method indicates whether or not we should suggest default wallpaper dimensions
4478 * when our wallpaper cropper was not yet used to set a wallpaper.
4479 */
4480 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004481 if (mLauncherCallbacks != null) {
4482 return mLauncherCallbacks.overrideWallpaperDimensions();
4483 }
Adam Cohenea90f832014-05-21 15:03:34 -07004484 return true;
4485 }
4486
Adam Cohen432609a2014-03-13 17:03:22 -07004487 /**
4488 * To be overridden by subclasses to indicate that there is an activity to launch
4489 * before showing the standard launcher experience.
4490 */
4491 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004492 if (mLauncherCallbacks != null) {
4493 return mLauncherCallbacks.hasFirstRunActivity();
4494 }
Adam Cohen432609a2014-03-13 17:03:22 -07004495 return false;
4496 }
4497
4498 /**
4499 * To be overridden by subclasses to launch any first run activity
4500 */
4501 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004502 if (mLauncherCallbacks != null) {
4503 return mLauncherCallbacks.getFirstRunActivity();
4504 }
Adam Cohen432609a2014-03-13 17:03:22 -07004505 return null;
4506 }
4507
Winson Chung2826a402015-04-17 16:18:53 -07004508 /**
4509 * Returns whether the launcher callbacks overrides search in all apps.
Winson Chung2826a402015-04-17 16:18:53 -07004510 */
4511 @Thunk boolean isAllAppsSearchOverridden() {
Winson Chung83f59ab2015-05-05 17:21:58 -07004512 if (DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
4513 return false;
4514 }
4515
Winson Chung2826a402015-04-17 16:18:53 -07004516 if (mLauncherCallbacks != null) {
4517 return mLauncherCallbacks.overrideAllAppsSearch();
4518 }
4519 return false;
4520 }
4521
Winson Chunga6945242014-01-08 14:04:34 -08004522 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004523 return !ActivityManager.isRunningInTestHarness() &&
4524 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004525 }
4526
Adam Cohen4a9423d2014-03-28 14:22:31 -07004527 protected boolean hasRunFirstRunActivity() {
4528 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4529 }
4530
Adam Cohen432609a2014-03-13 17:03:22 -07004531 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004532 if (shouldRunFirstRunActivity() &&
4533 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004534 Intent firstRunIntent = getFirstRunActivity();
4535 if (firstRunIntent != null) {
4536 startActivity(firstRunIntent);
4537 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004538 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004539 }
4540 }
Adam Cohen432609a2014-03-13 17:03:22 -07004541 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004542 }
4543
4544 private void markFirstRunActivityShown() {
4545 SharedPreferences.Editor editor = mSharedPrefs.edit();
4546 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4547 editor.apply();
4548 }
4549
Adam Cohen432609a2014-03-13 17:03:22 -07004550 /**
4551 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4552 * screen that must be displayed and dismissed.
4553 */
4554 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004555 if (mLauncherCallbacks != null) {
4556 return mLauncherCallbacks.hasDismissableIntroScreen();
4557 }
Adam Cohen432609a2014-03-13 17:03:22 -07004558 return false;
4559 }
4560
4561 /**
4562 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4563 */
4564 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004565 if (mLauncherCallbacks != null) {
4566 return mLauncherCallbacks.getIntroScreen();
4567 }
Adam Cohen432609a2014-03-13 17:03:22 -07004568 return null;
4569 }
4570
4571 /**
4572 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4573 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4574 */
4575 private boolean shouldShowIntroScreen() {
4576 return hasDismissableIntroScreen() &&
4577 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4578 }
4579
4580 protected void showIntroScreen() {
4581 View introScreen = getIntroScreen();
4582 changeWallpaperVisiblity(false);
4583 if (introScreen != null) {
4584 mDragLayer.showOverlayView(introScreen);
4585 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004586 if (mLauncherOverlayContainer != null) {
4587 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4588 }
Adam Cohen432609a2014-03-13 17:03:22 -07004589 }
4590
4591 public void dismissIntroScreen() {
4592 markIntroScreenDismissed();
4593 if (showFirstRunActivity()) {
4594 // We delay hiding the intro view until the first run activity is showing. This
4595 // avoids a blip.
4596 mWorkspace.postDelayed(new Runnable() {
4597 @Override
4598 public void run() {
4599 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004600 if (mLauncherOverlayContainer != null) {
4601 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4602 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004603 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004604 }
4605 }, ACTIVITY_START_DELAY);
4606 } else {
4607 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004608 if (mLauncherOverlayContainer != null) {
4609 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4610 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004611 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004612 }
4613 changeWallpaperVisiblity(true);
4614 }
4615
4616 private void markIntroScreenDismissed() {
4617 SharedPreferences.Editor editor = mSharedPrefs.edit();
4618 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4619 editor.apply();
4620 }
4621
Adam Cohen091440a2015-03-18 14:16:05 -07004622 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004623 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4624 // on the device, then we always show the first run cling experience (or if there is no
4625 // launcher2). Otherwise, we prompt the user upon started for migration
4626 LauncherClings launcherClings = new LauncherClings(this);
4627 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
4628 if (mModel.canMigrateFromOldLauncherDb(this)) {
4629 launcherClings.showMigrationCling();
4630 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004631 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004632 }
4633 }
4634 }
4635
Winson Chunga6945242014-01-08 14:04:34 -08004636 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004637 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4638 if (mHotseat != null) mHotseat.setAlpha(1f);
4639 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4640 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004641 }
4642
4643 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004644 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4645 if (mHotseat != null) mHotseat.setAlpha(0f);
4646 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4647 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004648 }
4649
Mathew Inwood72fbec12013-11-19 15:45:07 +00004650 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004651 // Called from search suggestion, not supported in other profiles.
4652 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4653 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4654 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4655 myUser);
4656 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004657 return null;
4658 }
Sunny Goyal4fbc3822015-02-18 16:46:50 -08004659 return new AppInfo(this, activityInfo, myUser, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004660 }
4661
4662 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4663 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004664 // Called from search suggestion, not supported in other profiles.
4665 return createShortcutDragInfo(shortcutIntent, caption, icon,
4666 UserHandleCompat.myUserHandle());
4667 }
4668
4669 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4670 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004671 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004672 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004673 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004674 }
4675
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004676 protected void moveWorkspaceToDefaultScreen() {
4677 mWorkspace.moveToDefaultScreen(false);
4678 }
4679
Mathew Inwood72fbec12013-11-19 15:45:07 +00004680 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4681 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004682 mWorkspace.onExternalDragStartedWithItem(dragView);
4683 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004684 }
4685
Anjali Koppalf5d29132014-02-28 13:33:27 -08004686 @Override
4687 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004688 if (mLauncherCallbacks != null) {
4689 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4690 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004691 }
4692
Winson Chung80baf5a2010-08-09 16:03:15 -07004693 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004694 * Prints out out state for debugging.
4695 */
4696 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004697 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004698 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004699 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4700 Log.d(TAG, "mRestoring=" + mRestoring);
4701 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4702 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004703 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004704 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004705 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004706
Daniel Sandler325dc232013-06-05 22:57:57 -04004707 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004708 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004709
4710 @Override
4711 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4712 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004713 synchronized (sDumpLogs) {
4714 writer.println(" ");
4715 writer.println("Debug logs: ");
4716 for (int i = 0; i < sDumpLogs.size(); i++) {
4717 writer.println(" " + sDumpLogs.get(i));
4718 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004719 }
Adam Cohen9211d422014-10-07 18:14:53 -07004720 if (mLauncherCallbacks != null) {
4721 mLauncherCallbacks.dump(prefix, fd, writer, args);
4722 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004723 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004724
4725 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004726 if (DEBUG_DUMP_LOG) {
4727 synchronized (sDumpLogs) {
4728 Log.d(TAG, "");
4729 Log.d(TAG, "*********************");
4730 Log.d(TAG, "Launcher debug logs: ");
4731 for (int i = 0; i < sDumpLogs.size(); i++) {
4732 Log.d(TAG, " " + sDumpLogs.get(i));
4733 }
4734 Log.d(TAG, "*********************");
4735 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004736 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004737 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004738 }
4739
4740 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004741 addDumpLog(tag, log, null, debugLog);
4742 }
4743
4744 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004745 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004746 if (e != null) {
4747 Log.d(tag, log, e);
4748 } else {
4749 Log.d(tag, log);
4750 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004751 }
Winson Chungede41292013-09-19 16:27:36 -07004752 if (DEBUG_DUMP_LOG) {
4753 sDateStamp.setTime(System.currentTimeMillis());
4754 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004755 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4756 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004757 }
Winson Chungede41292013-09-19 16:27:36 -07004758 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004759 }
4760
Adam Cohen59400422014-03-05 18:07:04 -08004761 public static CustomAppWidget getCustomAppWidget(String name) {
4762 return sCustomAppWidgets.get(name);
4763 }
4764
4765 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4766 return sCustomAppWidgets;
4767 }
4768
Winson Chungede41292013-09-19 16:27:36 -07004769 public void dumpLogsToLocalData() {
4770 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004771 new AsyncTask<Void, Void, Void>() {
4772 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004773 boolean success = false;
4774 sDateStamp.setTime(sRunStart);
4775 String FILENAME = sDateStamp.getMonth() + "-"
4776 + sDateStamp.getDay() + "_"
4777 + sDateStamp.getHours() + "-"
4778 + sDateStamp.getMinutes() + "_"
4779 + sDateStamp.getSeconds() + ".txt";
4780
4781 FileOutputStream fos = null;
4782 File outFile = null;
4783 try {
4784 outFile = new File(getFilesDir(), FILENAME);
4785 outFile.createNewFile();
4786 fos = new FileOutputStream(outFile);
4787 } catch (Exception e) {
4788 e.printStackTrace();
4789 }
4790 if (fos != null) {
4791 PrintWriter writer = new PrintWriter(fos);
4792
4793 writer.println(" ");
4794 writer.println("Debug logs: ");
4795 synchronized (sDumpLogs) {
4796 for (int i = 0; i < sDumpLogs.size(); i++) {
4797 writer.println(" " + sDumpLogs.get(i));
4798 }
4799 }
4800 writer.close();
4801 }
4802 try {
4803 if (fos != null) {
4804 fos.close();
4805 success = true;
4806 }
4807 } catch (IOException e) {
4808 e.printStackTrace();
4809 }
Michael Jurka43467462013-11-14 12:03:58 +01004810 return null;
Winson Chungede41292013-09-19 16:27:36 -07004811 }
Michael Jurka43467462013-11-14 12:03:58 +01004812 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004813 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004814 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004815}
Michael Jurka2763be32011-02-24 11:19:57 -08004816
Michael Jurkaabded662011-03-04 12:06:57 -08004817interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004818 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004819 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004820 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004821 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004822 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004823}
Dan Sandlerd5024042014-01-09 15:01:33 -05004824
4825interface DebugIntents {
4826 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4827 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004828}