blob: a305d101df894b189ca87b904bc300d942ed6d53 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Gilles Debunnedd6c9922010-10-25 11:23:41 -070019import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080020import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070021import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070022import android.animation.ObjectAnimator;
23import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.ValueAnimator;
Sunny Goyal70660032015-05-14 00:07:08 -070025import android.annotation.SuppressLint;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070044import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen3f9c9712014-10-31 11:48:25 -070052import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070053import android.graphics.Bitmap;
54import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070055import android.graphics.Color;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Sunny Goyal4a6c6f32015-05-19 12:36:46 -070058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020064import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080065import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070066import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070067import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040068import android.os.SystemClock;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
Adam Cohenc2d6e892014-10-16 09:49:24 -070086import android.view.ViewStub;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.ViewTreeObserver;
Sunny Goyal651077b2014-06-30 14:15:31 -070088import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080090import android.view.accessibility.AccessibilityEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
93import android.widget.FrameLayout;
94import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080095import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070096import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -070097
Sunny Goyal651077b2014-06-30 14:15:31 -070098import com.android.launcher3.DropTarget.DragObject;
99import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyal83a8f042015-05-19 12:52:12 -0700100import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700101import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100102import com.android.launcher3.compat.LauncherActivityInfoCompat;
103import com.android.launcher3.compat.LauncherAppsCompat;
104import com.android.launcher3.compat.UserHandleCompat;
105import com.android.launcher3.compat.UserManagerCompat;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700106import com.android.launcher3.model.WidgetsModel;
Sunny Goyale2df0622015-04-24 11:27:00 -0700107import com.android.launcher3.util.LongArrayMap;
Adam Cohen091440a2015-03-18 14:16:05 -0700108import com.android.launcher3.util.Thunk;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700109import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700110import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700111import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700112
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.io.DataInputStream;
114import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700115import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700116import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700118import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700120import java.io.PrintWriter;
Chet Haasea8f996d2015-02-17 12:56:04 -0800121import java.lang.reflect.InvocationTargetException;
122import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700123import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700124import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700125import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700126import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700127import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700128import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700129import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000130import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132/**
133 * Default launcher application.
134 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100135public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700136 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungb745afb2015-03-02 11:51:23 -0800137 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener,
138 LauncherStateTransitionAnimation.Callbacks {
Hyunyoung Song4e8fb912015-04-11 15:44:32 -0700139 static final String TAG = "Launcher";
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700140 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Winson Chung83f59ab2015-05-05 17:21:58 -0700142 // Temporary flag
143 static final boolean DISABLE_ALL_APPS_SEARCH_INTEGRATION = true;
144
Daniel Sandlerf061f822013-06-27 13:59:36 -0400145 static final boolean PROFILE_STARTUP = false;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700146 static final boolean DEBUG_WIDGETS = true;
Winson Chunga2413752012-04-03 14:22:34 -0700147 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400148 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700149 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700150
Dan Sandlerd5024042014-01-09 15:01:33 -0500151 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
152
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700154 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700155 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700156 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157
Michael Jurka8b805b12012-04-18 14:23:14 -0700158 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700159 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700160
Sunny Goyal4a6c6f32015-05-19 12:36:46 -0700161 private static final int WORKSPACE_BACKGROUND_GRADIENT = 0;
162 private static final int WORKSPACE_BACKGROUND_TRANSPARENT = 1;
163 private static final int WORKSPACE_BACKGROUND_BLACK = 2;
164
Mathew Inwood876a8462013-06-14 14:12:41 +0100165 /**
166 * IntentStarter uses request codes starting with this. This must be greater than all activity
167 * request codes used internally.
168 */
169 protected static final int REQUEST_LAST = 100;
170
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
172
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800173 static final int SCREEN_COUNT = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
Michael Jurka0a457bf2012-11-19 14:05:05 -0800175 // To turn on these properties, type
176 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800177 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178
Winson Chung2672ff92012-05-04 16:22:30 -0700179 // The Intent extra that defines whether to ignore the launch animation
180 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400181 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 // Type: int
184 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700185 // Type: int
186 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700188 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
189 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
191 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700192 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700194 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700195 // Type: int
196 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
197 // Type: int
198 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
199 // Type: parcelable
200 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000201 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800202 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000203 // Type: int[]
204 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205
Adam Cohen432609a2014-03-13 17:03:22 -0700206 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800207 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
208
Adam Cohen3ed316a2014-07-23 18:21:20 -0700209 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
210 static final String ACTION_FIRST_LOAD_COMPLETE =
211 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
212
Adam Cohen39a06042013-07-19 14:30:12 -0700213 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700214 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700215
Sunny Goyal594d76d2014-11-06 10:12:54 -0800216 private static final String QSB_WIDGET_ID = "qsb_widget_id";
217 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
218
Winson Chunga6945242014-01-08 14:04:34 -0800219 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
220
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700221 /** The different states that Launcher can be in. */
Winson Chungb745afb2015-03-02 11:51:23 -0800222 enum State { NONE, WORKSPACE, APPS, APPS_SPRING_LOADED, WIDGETS, WIDGETS_SPRING_LOADED };
Adam Cohen091440a2015-03-18 14:16:05 -0700223 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700224 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700225
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700226 private boolean mIsSafeModeEnabled;
227
Adam Cohenc2d6e892014-10-16 09:49:24 -0700228 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
229 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700230 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700231
Joe Onorato9c1289c2009-08-17 11:03:03 -0400232 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700233 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
234 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700235 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000237 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
238 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
239
Winson Chunga2413752012-04-03 14:22:34 -0700240 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700241 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
242 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700243 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700244
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800245 private final BroadcastReceiver mCloseSystemDialogsReceiver
246 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800247 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private LayoutInflater mInflater;
250
Adam Cohen091440a2015-03-18 14:16:05 -0700251 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700252 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800253 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700254 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800255 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700256 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700257
Sunny Goyalffe83f12014-08-14 17:39:34 -0700258 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
Adam Cohen091440a2015-03-18 14:16:05 -0700261 @Thunk ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800262 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800263 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700264
Michael Jurka0280c3b2010-09-17 15:00:07 -0700265 private int[] mTmpAddItemCellCoordinates = new int[2];
266
Winson Chung3d503fb2011-07-13 17:25:49 -0700267 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800268 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700269
Michael Jurka838a4ca2011-02-07 13:33:06 -0800270 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700271
Winson Chungc51db6a2011-10-05 11:44:49 -0700272 private SearchDropTargetBar mSearchDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700273
274 // Main container view for the all apps screen.
Adam Cohen091440a2015-03-18 14:16:05 -0700275 @Thunk AppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700276
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700277 // Main container view and the model for the widget tray screen.
278 @Thunk WidgetsContainerView mWidgetsView;
279 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700280
Winson Chungf0ea4d32011-06-06 14:27:16 -0700281 private boolean mAutoAdvanceRunning = false;
Sunny Goyal594d76d2014-11-06 10:12:54 -0800282 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700285 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
286 // scroll issues (because the workspace may not have been measured yet) and extra work.
287 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
288 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289
290 private SpannableStringBuilder mDefaultKeySsb = null;
291
Adam Cohen091440a2015-03-18 14:16:05 -0700292 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400293
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800294 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 private boolean mRestoring;
296 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700297 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298
Michael Jurka1e2f4652013-07-08 18:03:46 -0700299 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700300 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
301
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302 private Bundle mSavedInstanceState;
303
Joe Onorato9c1289c2009-08-17 11:03:03 -0400304 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800305 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700306 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800307 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700308 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800309 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400310
Adam Cohen091440a2015-03-18 14:16:05 -0700311 @Thunk static LocaleConfiguration sLocaleConfiguration = null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700312
Sunny Goyale2df0622015-04-24 11:27:00 -0700313 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700314
Adam Cohen61f560d2013-09-30 15:58:20 -0700315 private View.OnTouchListener mHapticFeedbackTouchListener;
316
Adam Cohended9f8d2010-11-03 13:25:16 -0700317 // Related to the auto-advancing of widgets
318 private final int ADVANCE_MSG = 1;
319 private final int mAdvanceInterval = 20000;
320 private final int mAdvanceStagger = 250;
321 private long mAutoAdvanceSentTime;
322 private long mAutoAdvanceTimeLeft = -1;
Adam Cohen091440a2015-03-18 14:16:05 -0700323 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
Adam Cohended9f8d2010-11-03 13:25:16 -0700324 new HashMap<View, AppWidgetProviderInfo>();
325
Winson Chung400438b2011-01-16 17:53:48 -0800326 // Determines how long to wait after a rotation before restoring the screen orientation to
327 // match the sensor state.
328 private final int mRestoreScreenOrientationDelay = 500;
329
Adam Cohen091440a2015-03-18 14:16:05 -0700330 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700331
Adam Cohen1462de32012-07-24 22:34:36 -0700332 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700333 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700334
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700335 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700336 static Date sDateStamp = new Date();
337 static DateFormat sDateFormat =
338 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
339 static long sRunStart = System.currentTimeMillis();
340 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700341
Winson Chung46353de2012-02-16 14:05:10 -0800342 // We only want to get the SharedPreferences once since it does an FS stat each time we get
343 // it from the context.
344 private SharedPreferences mSharedPrefs;
345
Winson Chungf0c6ae02012-03-21 16:10:31 -0700346 // Holds the page that we need to animate to, and the icon views that we need to animate up
347 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700348 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700349 private Bitmap mFolderIconBitmap;
350 private Canvas mFolderIconCanvas;
351 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700352
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700353 private DeviceProfile mDeviceProfile;
354
Winson Chung13eb5272015-05-11 16:30:13 -0700355 // This is set to the view that launched the activity that navigated the user away from
356 // launcher. Since there is no callback for when the activity has finished launching, enable
357 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800358 private BubbleTextView mWaitingForResume;
359
Adam Cohen59400422014-03-05 18:07:04 -0800360 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
361 new HashMap<String, CustomAppWidget>();
362
363 private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
364 static {
365 if (ENABLE_CUSTOM_WIDGET_TEST) {
366 sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
367 }
368 }
369
Chet Haasea8f996d2015-02-17 12:56:04 -0800370 // TODO: remove this field and call method directly when Launcher3 can depend on M APIs
371 private static Method sClipRevealMethod = null;
372 static {
373 Class<?> activityOptionsClass = ActivityOptions.class;
374 try {
375 sClipRevealMethod = activityOptionsClass.getDeclaredMethod("makeClipRevealAnimation",
376 View.class, int.class, int.class, int.class, int.class);
377 } catch (Exception e) {
378 // Earlier version
379 }
380 }
381
Adam Cohen091440a2015-03-18 14:16:05 -0700382 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700383 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700384 if (mWorkspace != null) {
385 mWorkspace.buildPageHardwareLayers();
386 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700387 }
388 };
389
Adam Cohendb364c32014-05-20 14:23:40 -0700390 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800391
Adam Cohen091440a2015-03-18 14:16:05 -0700392 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800393 int requestCode;
394 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700395 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700396 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800397 int cellX;
398 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700399 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800400 }
401
Daniel Sandlerff02d492013-08-05 02:12:05 -0400402 private Stats mStats;
403
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700404 FocusIndicatorView mFocusHandler;
405
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 @Override
407 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700408 if (DEBUG_STRICT_MODE) {
409 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
410 .detectDiskReads()
411 .detectDiskWrites()
412 .detectNetwork() // or .detectAll() for all detectable problems
413 .penaltyLog()
414 .build());
415 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
416 .detectLeakedSqlLiteObjects()
417 .detectLeakedClosableObjects()
418 .penaltyLog()
419 .penaltyDeath()
420 .build());
421 }
422
Adam Cohen9211d422014-10-07 18:14:53 -0700423 if (mLauncherCallbacks != null) {
424 mLauncherCallbacks.preOnCreate();
425 }
426
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400428
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400429 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400430 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700431 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700432
Winson Chung5f8afe62013-08-12 16:19:28 -0700433 // Lazy-initialize the dynamic grid
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700434 mDeviceProfile = app.initDynamicGrid(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700435
436 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400437 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700438 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700439 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800440 mModel = app.setLauncher(this);
441 mIconCache = app.getIconCache();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700442 mIconCache.flushInvalidIcons(mDeviceProfile);
Joe Onorato41a12d22009-10-31 18:30:00 -0400443 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 mInflater = getLayoutInflater();
Winson Chungb745afb2015-03-02 11:51:23 -0800445 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);
Romain Guycbb89e42009-06-08 15:52:54 -0700446
Daniel Sandlerff02d492013-08-05 02:12:05 -0400447 mStats = new Stats(this);
448
Sunny Goyalffe83f12014-08-14 17:39:34 -0700449 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700450
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700451 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
452 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700453
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700454 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
455 // this also ensures that any synchronous binding below doesn't re-trigger another
456 // LauncherModel load.
457 mPaused = false;
458
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200460 android.os.Debug.startMethodTracing(
461 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 }
463
464 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700466
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700468 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800469
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800470 registerContentObservers();
471
Joe Onorato7c312c12009-08-13 21:36:53 -0700472 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700473
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 mSavedState = savedInstanceState;
475 restoreState(mSavedState);
476
477 if (PROFILE_STARTUP) {
478 android.os.Debug.stopMethodTracing();
479 }
480
481 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700482 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700483 // If the user leaves launcher, then we should just load items asynchronously when
484 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700485 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700486 } else {
487 // We only load the page synchronously if the user rotates (or triggers a
488 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700489 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700490 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800491 }
492
493 // For handling default keys
494 mDefaultKeySsb = new SpannableStringBuilder();
495 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800496
497 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
498 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800499
Adam Cohenf9426d52012-06-04 17:26:21 -0700500 // On large interfaces, we want the screen to auto-rotate based on the current orientation
501 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700502
Adam Cohen9211d422014-10-07 18:14:53 -0700503 if (mLauncherCallbacks != null) {
504 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700505 if (mLauncherCallbacks.hasLauncherOverlay()) {
506 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700507 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
508 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
509 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700510 mWorkspace.setLauncherOverlay(mLauncherOverlay);
511 }
Adam Cohen9211d422014-10-07 18:14:53 -0700512 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700513
514 if (shouldShowIntroScreen()) {
515 showIntroScreen();
516 } else {
517 showFirstRunActivity();
518 showFirstRunClings();
519 }
Adam Cohen9211d422014-10-07 18:14:53 -0700520 }
521
522 private LauncherCallbacks mLauncherCallbacks;
523
524 public void onPostCreate(Bundle savedInstanceState) {
525 super.onPostCreate(savedInstanceState);
526 if (mLauncherCallbacks != null) {
527 mLauncherCallbacks.onPostCreate(savedInstanceState);
528 }
529 }
530
531 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
532 mLauncherCallbacks = callbacks;
Winson Chung0f785722015-04-08 10:27:49 -0700533 mLauncherCallbacks.setLauncherAppsCallback(new Launcher.LauncherAppsCallbacks() {
534 @Override
535 public void onAllAppsBoundsChanged(Rect bounds) {
Winson Chungcd99cd32015-04-29 11:03:24 -0700536 if (LOGD) {
537 Log.d(TAG, "onAllAppsBoundsChanged(Rect): " + bounds);
538 }
Winson Chung94804152015-05-08 13:06:44 -0700539 mAppsView.setFixedBounds(bounds);
540 mWidgetsView.setFixedBounds(bounds);
Winson Chung0f785722015-04-08 10:27:49 -0700541 }
542
543 @Override
544 public void dismissAllApps() {
Winson Chung83f59ab2015-05-05 17:21:58 -0700545 if (!DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
546 // Dismiss All Apps if we aren't already paused/invisible
547 if (!mPaused) {
548 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true,
549 null /* onCompleteRunnable */, false /* notifyLauncherCallbacks */);
550 }
Winson Chungcd99cd32015-04-29 11:03:24 -0700551 }
Winson Chung0f785722015-04-08 10:27:49 -0700552 }
553 });
Adam Cohen9211d422014-10-07 18:14:53 -0700554 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700555 }
556
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700557 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700558 public void onLauncherProviderChange() {
559 if (mLauncherCallbacks != null) {
560 mLauncherCallbacks.onLauncherProviderChange();
561 }
562 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700563
Adam Cohen9211d422014-10-07 18:14:53 -0700564 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700565 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700566 if (mLauncherCallbacks != null) {
567 return mLauncherCallbacks.hasCustomContentToLeft();
568 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700569 return false;
570 }
571
Dave Hawkeya8881582013-09-17 15:55:33 -0600572 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500573 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600574 * {@link #addToCustomContentPage}. This will only be invoked if
575 * {@link #hasCustomContentToLeft()} is {@code true}.
576 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500577 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700578 if (mLauncherCallbacks != null) {
579 mLauncherCallbacks.populateCustomContentContainer();
580 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600581 }
582
583 /**
584 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
585 * ensure the custom content page is added or removed if necessary.
586 */
587 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600588 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600589 // Not bound yet, wait for bindScreens to be called.
590 return;
591 }
592
593 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
594 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500595 mWorkspace.createCustomContentContainer();
596 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600597 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
598 mWorkspace.removeCustomContentPage();
599 }
600 }
601
Adam Cohen091440a2015-03-18 14:16:05 -0700602 @Thunk void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700603 if (sLocaleConfiguration == null) {
604 new AsyncTask<Void, Void, LocaleConfiguration>() {
605 @Override
606 protected LocaleConfiguration doInBackground(Void... unused) {
607 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
608 readConfiguration(Launcher.this, localeConfiguration);
609 return localeConfiguration;
610 }
611
612 @Override
613 protected void onPostExecute(LocaleConfiguration result) {
614 sLocaleConfiguration = result;
615 checkForLocaleChange(); // recursive, but now with a locale configuration
616 }
617 }.execute();
618 return;
619 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700620
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800621 final Configuration configuration = getResources().getConfiguration();
622
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700623 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800624 final String locale = configuration.locale.toString();
625
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700626 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800627 final int mcc = configuration.mcc;
628
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700629 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 final int mnc = configuration.mnc;
631
Romain Guy84f296c2009-11-04 15:00:44 -0800632 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633
Romain Guy84f296c2009-11-04 15:00:44 -0800634 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700635 sLocaleConfiguration.locale = locale;
636 sLocaleConfiguration.mcc = mcc;
637 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700638
Joe Onorato0589f0f2010-02-08 13:44:00 -0800639 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700640
641 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100642 new AsyncTask<Void, Void, Void>() {
643 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700644 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100645 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700646 }
Michael Jurka43467462013-11-14 12:03:58 +0100647 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700648 }
649 }
650
Adam Cohen091440a2015-03-18 14:16:05 -0700651 @Thunk static class LocaleConfiguration {
Romain Guy98d01652009-06-30 16:21:04 -0700652 public String locale;
653 public int mcc = -1;
654 public int mnc = -1;
655 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700656
Adam Cohen091440a2015-03-18 14:16:05 -0700657 @Thunk static void readConfiguration(Context context, LocaleConfiguration configuration) {
Romain Guy98d01652009-06-30 16:21:04 -0700658 DataInputStream in = null;
659 try {
Helena Josol28db2802014-10-09 17:04:09 +0100660 in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
Romain Guy98d01652009-06-30 16:21:04 -0700661 configuration.locale = in.readUTF();
662 configuration.mcc = in.readInt();
663 configuration.mnc = in.readInt();
664 } catch (FileNotFoundException e) {
665 // Ignore
666 } catch (IOException e) {
667 // Ignore
668 } finally {
669 if (in != null) {
670 try {
671 in.close();
672 } catch (IOException e) {
673 // Ignore
674 }
675 }
676 }
677 }
678
Adam Cohen091440a2015-03-18 14:16:05 -0700679 @Thunk static void writeConfiguration(Context context, LocaleConfiguration configuration) {
Romain Guy98d01652009-06-30 16:21:04 -0700680 DataOutputStream out = null;
681 try {
Helena Josol4fbbb3e2014-10-06 16:06:46 +0100682 out = new DataOutputStream(context.openFileOutput(
Helena Josol28db2802014-10-09 17:04:09 +0100683 LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE));
Romain Guy98d01652009-06-30 16:21:04 -0700684 out.writeUTF(configuration.locale);
685 out.writeInt(configuration.mcc);
686 out.writeInt(configuration.mnc);
687 out.flush();
688 } catch (FileNotFoundException e) {
689 // Ignore
690 } catch (IOException e) {
691 //noinspection ResultOfMethodCallIgnored
Helena Josol28db2802014-10-09 17:04:09 +0100692 context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete();
Romain Guy98d01652009-06-30 16:21:04 -0700693 } finally {
694 if (out != null) {
695 try {
696 out.close();
697 } catch (IOException e) {
698 // Ignore
699 }
700 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800701 }
702 }
703
Anton Hanssona2f665f2013-09-26 12:18:32 +0100704 public Stats getStats() {
705 return mStats;
706 }
707
Bjorn Bringertc459e522013-06-07 19:36:01 +0100708 public LayoutInflater getInflater() {
709 return mInflater;
710 }
711
Hyunyoung Song3f471442015-04-08 19:01:34 -0700712 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700713 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
714 // that is subsequently removed from the workspace in startBinding().
715 return !mModel.isLoadingWorkspace();
716 }
717
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800718 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000719 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100720 if (Build.VERSION.SDK_INT >= 17) {
721 return View.generateViewId();
722 } else {
723 // View.generateViewId() is not available. The following fallback logic is a copy
724 // of its implementation.
725 for (;;) {
726 final int result = sNextGeneratedId.get();
727 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
728 int newValue = result + 1;
729 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
730 if (sNextGeneratedId.compareAndSet(result, newValue)) {
731 return result;
732 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000733 }
734 }
735 }
736
737 public int getViewIdForItem(ItemInfo info) {
738 // This cast is safe given the > 2B range for int.
739 int itemId = (int) info.id;
740 if (mItemIdToViewId.containsKey(itemId)) {
741 return mItemIdToViewId.get(itemId);
742 }
743 int viewId = generateViewId();
744 mItemIdToViewId.put(itemId, viewId);
745 return viewId;
746 }
747
748 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700749 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
750 * a configuration step, this allows the proper animations to run after other transitions.
751 */
Adam Cohendb364c32014-05-20 14:23:40 -0700752 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700753 long screenId = args.screenId;
754 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
755 // When the screen id represents an actual screen (as opposed to a rank) we make sure
756 // that the drop page actually exists.
757 screenId = ensurePendingDropLayoutExists(args.screenId);
758 }
Adam Cohendb364c32014-05-20 14:23:40 -0700759
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800760 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800761 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700762 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700763 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700764 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800765 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700766 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700767 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700768 case REQUEST_RECONFIGURE_APPWIDGET:
769 completeRestoreAppWidget(args.appWidgetId);
770 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800771 }
Michael Jurka27614d22012-04-02 06:40:22 -0700772 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
773 // if you turned the screen off and then back while in All Apps, Launcher would not
774 // return to the workspace. Clearing mAddInfo.container here fixes this issue
775 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700776 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800777 }
778
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800779 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700780 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700781 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700782 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700783 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800784 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700785
Adam Cohenad4e15c2013-10-17 16:21:35 -0700786 Runnable exitSpringLoaded = new Runnable() {
787 @Override
788 public void run() {
789 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
790 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
791 }
792 };
793
Michael Jurka8b805b12012-04-18 14:23:14 -0700794 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700795 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700796 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
797 if (resultCode == RESULT_CANCELED) {
798 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700799 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700800 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700801 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800802 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700803 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700804 }
805 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200806 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
807 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -0700808 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200809 }
810 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700811 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200812
Adam Cohened66b2b2012-01-23 17:28:51 -0800813 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700814 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700815
Adam Cohendb364c32014-05-20 14:23:40 -0700816 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800817 // We have special handling for widgets
818 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800819 final int appWidgetId;
820 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
821 : -1;
822 if (widgetId < 0) {
823 appWidgetId = pendingAddWidgetId;
824 } else {
825 appWidgetId = widgetId;
826 }
827
Adam Cohenad4e15c2013-10-17 16:21:35 -0700828 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800829 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700830 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
831 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700832 result = RESULT_CANCELED;
833 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700834 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700835 @Override
836 public void run() {
837 exitSpringLoadedDragModeDelayed(false, 0, null);
838 }
839 };
Adam Cohendb364c32014-05-20 14:23:40 -0700840 if (workspaceLocked) {
841 // No need to remove the empty screen if we're mid-binding, as the
842 // the bind will not add the empty screen.
843 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
844 } else {
845 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
846 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
847 }
Winson Chung5aaab772012-04-27 15:24:02 -0700848 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700849 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700850 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
851 // When the screen id represents an actual screen (as opposed to a rank)
852 // we make sure that the drop page actually exists.
853 mPendingAddInfo.screenId =
854 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
855 }
Adam Cohendb364c32014-05-20 14:23:40 -0700856 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
857
858 dropLayout.setDropPending(true);
859 final Runnable onComplete = new Runnable() {
860 @Override
861 public void run() {
862 completeTwoStageWidgetDrop(resultCode, appWidgetId);
863 dropLayout.setDropPending(false);
864 }
865 };
866 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
867 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
868 } else {
869 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
870 mPendingAddInfo);
871 sPendingAddItem = args;
872 }
Winson Chung5aaab772012-04-27 15:24:02 -0700873 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800874 return;
875 }
876
Sunny Goyalff572272014-07-23 13:58:07 -0700877 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
878 if (resultCode == RESULT_OK) {
879 // Update the widget view.
880 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
881 pendingAddWidgetId, mPendingAddInfo);
882 if (workspaceLocked) {
883 sPendingAddItem = args;
884 } else {
885 completeAdd(args);
886 }
887 }
888 // Leave the widget in the pending state if the user canceled the configure.
889 return;
890 }
891
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800892 // The pattern used here is that a user PICKs a specific application,
893 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700894
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800895 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
896 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700897 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700898 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
899 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800900 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700901 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800902 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700903 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700904 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
905 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800906 }
Adam Cohen00074722013-10-11 17:46:09 -0700907 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700908 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700909 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800910 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800911 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800912
913 }
914
915 @Override
916 protected void onActivityResult(
917 final int requestCode, final int resultCode, final Intent data) {
918 handleActivityResult(requestCode, resultCode, data);
919 if (mLauncherCallbacks != null) {
920 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
921 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800922 }
923
Adam Cohendb364c32014-05-20 14:23:40 -0700924 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
925 appWidgetId, ItemInfo info) {
926 PendingAddArguments args = new PendingAddArguments();
927 args.requestCode = requestCode;
928 args.intent = data;
929 args.container = info.container;
930 args.screenId = info.screenId;
931 args.cellX = info.cellX;
932 args.cellY = info.cellY;
933 args.appWidgetId = appWidgetId;
934 return args;
935 }
936
937 /**
938 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
939 *
940 * @param screenId the screen id to check
941 * @return the new screen, or screenId if it exists
942 */
943 private long ensurePendingDropLayoutExists(long screenId) {
944 CellLayout dropLayout =
945 (CellLayout) mWorkspace.getScreenWithId(screenId);
946 if (dropLayout == null) {
947 // it's possible that the add screen was removed because it was
948 // empty and a re-bind occurred
949 mWorkspace.addExtraEmptyScreen();
950 return mWorkspace.commitExtraEmptyScreen();
951 } else {
952 return screenId;
953 }
954 }
955
Adam Cohen091440a2015-03-18 14:16:05 -0700956 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700957 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700958 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800959 Runnable onCompleteRunnable = null;
960 int animationType = 0;
961
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700962 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800963 if (resultCode == RESULT_OK) {
964 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
965 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700966 mPendingAddWidgetInfo);
967 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800968 onCompleteRunnable = new Runnable() {
969 @Override
970 public void run() {
971 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700972 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700973 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
974 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800975 }
976 };
977 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800978 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800979 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800980 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700981 if (mDragLayer.getAnimatedView() != null) {
982 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
983 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
984 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700985 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700986 // The animated view may be null in the case of a rotation during widget configuration
987 onCompleteRunnable.run();
988 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 }
990
991 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700992 protected void onStop() {
993 super.onStop();
994 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700995
996 if (mLauncherCallbacks != null) {
997 mLauncherCallbacks.onStop();
998 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700999 }
1000
1001 @Override
1002 protected void onStart() {
1003 super.onStart();
1004 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -07001005
1006 if (mLauncherCallbacks != null) {
1007 mLauncherCallbacks.onStart();
1008 }
Michael Jurkacd496d72013-04-11 11:32:45 -07001009 }
1010
1011 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +02001013 long startTime = 0;
1014 if (DEBUG_RESUME_TIME) {
1015 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -04001016 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +02001017 }
Adam Cohen9211d422014-10-07 18:14:53 -07001018
1019 if (mLauncherCallbacks != null) {
1020 mLauncherCallbacks.preOnResume();
1021 }
1022
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001024
Winson Chung4a2afa32012-07-19 14:53:05 -07001025 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001026 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001027 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001028 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001029 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001030 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001031 // view after launching an app, as they may be depending on the UI to be static to
1032 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -07001033 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung13eb5272015-05-11 16:30:13 -07001034 !launchedFromApp /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08001035 } else if (mOnResumeState == State.WIDGETS) {
1036 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001037 }
1038 mOnResumeState = State.NONE;
1039
Winson Chungcd99cd32015-04-29 11:03:24 -07001040 // Restore the apps state if we are in all apps
Winson Chung4ac30062015-05-08 17:34:17 -07001041 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
1042 // Otherwise, notify the callbacks if we are in all apps mode
1043 if (mState == State.APPS) {
1044 if (mLauncherCallbacks != null) {
1045 mLauncherCallbacks.onAllAppsShown();
1046 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001047 }
1048 }
1049
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001050 // Background was set to gradient in onPause(), restore to transparent if in all apps.
1051 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_TRANSPARENT
1052 : WORKSPACE_BACKGROUND_GRADIENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001053
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001054 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001055 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001056 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001057 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001058 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001059 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001061 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001062 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1063 // execute them here
1064 long startTimeCallbacks = 0;
1065 if (DEBUG_RESUME_TIME) {
1066 startTimeCallbacks = System.currentTimeMillis();
1067 }
1068
Michael Jurka1e2f4652013-07-08 18:03:46 -07001069 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1070 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001071 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001072 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001073 if (DEBUG_RESUME_TIME) {
1074 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1075 (System.currentTimeMillis() - startTimeCallbacks));
1076 }
Michael Jurka447bf842013-05-15 14:52:15 +02001077 }
Michael Jurka54554252013-08-01 12:52:23 +02001078 if (mOnResumeCallbacks.size() > 0) {
1079 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1080 mOnResumeCallbacks.get(i).run();
1081 }
1082 mOnResumeCallbacks.clear();
1083 }
Winson Chunge4e50662012-01-23 14:45:13 -08001084
1085 // Reset the pressed state of icons that were locked in the press state while activities
1086 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001087 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001088 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001089 mWaitingForResume.setStayPressed(false);
1090 }
Winson Chung82963d52013-10-09 11:20:57 -07001091
Adam Cohen06dff352012-06-01 17:17:08 -07001092 // It is possible that widgets can receive updates while launcher is not in the foreground.
1093 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1094 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1095 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001096 getWorkspace().reinflateWidgetsIfNecessary();
Sunny Goyal22235bc2015-04-03 09:23:43 -07001097 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001098
Michael Jurka447bf842013-05-15 14:52:15 +02001099 if (DEBUG_RESUME_TIME) {
1100 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1101 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001102
1103 if (mWorkspace.getCustomContentCallbacks() != null) {
1104 // If we are resuming and the custom content is the current page, we call onShow().
1105 // It is also poassible that onShow will instead be called slightly after first layout
1106 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1107 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001108 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001109 }
1110 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001111 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001112 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001113
Sunny Goyal756adbc2015-04-16 15:20:51 -07001114 if (!isWorkspaceLoading()) {
1115 // Process any items that were added while Launcher was away.
1116 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1117 }
Adam Cohen9211d422014-10-07 18:14:53 -07001118
1119 if (mLauncherCallbacks != null) {
1120 mLauncherCallbacks.onResume();
1121 }
Adam Cohen06dff352012-06-01 17:17:08 -07001122 }
1123
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001124 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001125 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001126 // Ensure that items added to Launcher are queued until Launcher returns
1127 InstallShortcutReceiver.enableInstallQueue();
1128
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001129 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001130 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001131 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001132 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001133
1134 // We call onHide() aggressively. The custom content callbacks should be able to
1135 // debounce excess onHide calls.
1136 if (mWorkspace.getCustomContentCallbacks() != null) {
1137 mWorkspace.getCustomContentCallbacks().onHide();
1138 }
Romain Guycbb89e42009-06-08 15:52:54 -07001139
Adam Cohen9211d422014-10-07 18:14:53 -07001140 if (mLauncherCallbacks != null) {
1141 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001142 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001143 }
1144
1145 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001146 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1147 // by a onResume or by scrolling otherwise.
1148 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001149
1150 // Custom content is completely hidden
1151 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001152
1153 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1154 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001155
1156 // Indicates whether the user is allowed to scroll away from the custom content.
1157 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001158 }
1159
Adam Cohenc2d6e892014-10-16 09:49:24 -07001160 public interface LauncherOverlay {
1161
1162 /**
1163 * Touch interaction leading to overscroll has begun
1164 */
1165 public void onScrollInteractionBegin();
1166
1167 /**
1168 * Touch interaction related to overscroll has ended
1169 */
1170 public void onScrollInteractionEnd();
1171
1172 /**
1173 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1174 * screen (or in the case of RTL, the rightmost screen).
1175 */
1176 public void onScrollChange(int progress, boolean rtl);
1177
1178 /**
1179 * Screen has stopped scrolling
1180 */
1181 public void onScrollSettled();
1182
1183 /**
1184 * This method can be called by the Launcher in order to force the LauncherOverlay
1185 * to exit fully immersive mode.
1186 */
1187 public void forceExitFullImmersion();
1188 }
1189
Winson Chung0f785722015-04-08 10:27:49 -07001190 public interface LauncherAppsCallbacks {
1191 /**
1192 * Updates launcher to the available space that AllApps can take so as not to overlap with
1193 * any other views.
1194 */
1195 public void onAllAppsBoundsChanged(Rect bounds);
1196
1197 /**
1198 * Called to dismiss all apps if it is showing.
1199 */
1200 public void dismissAllApps();
1201 }
1202
Adam Cohenc2d6e892014-10-16 09:49:24 -07001203 public interface LauncherOverlayCallbacks {
1204 /**
1205 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1206 * however it doesn't modify any state within the launcher.
1207 */
1208 public boolean canEnterFullImmersion();
1209
1210 /**
1211 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1212 * eg. by occupying the full screen and handling all touch events.
1213 *
1214 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1215 * case, Launcher will modify any necessary state and assumes the overlay is
1216 * handling all interaction. If false, the LauncherOverlay should cancel any
1217 *
1218 */
1219 public boolean enterFullImmersion();
1220
1221 /**
1222 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1223 * full control over UI and state.
1224 */
1225 public void exitFullImmersion();
1226 }
1227
1228 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1229
1230 @Override
1231 public boolean canEnterFullImmersion() {
1232 return mState == State.WORKSPACE;
1233 }
1234
1235 @Override
1236 public boolean enterFullImmersion() {
1237 if (mState == State.WORKSPACE) {
1238 // When fully immersed, disregard any touches which fall through.
1239 mDragLayer.setBlockTouch(true);
1240 return true;
1241 }
1242 return false;
1243 }
1244
1245 @Override
1246 public void exitFullImmersion() {
1247 mDragLayer.setBlockTouch(false);
1248 }
1249 }
1250
Jorim Jaggid017f882014-01-14 17:08:48 -08001251 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001252 if (mLauncherCallbacks != null) {
1253 return mLauncherCallbacks.hasSettings();
1254 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001255 return false;
1256 }
1257
Adam Cohen9211d422014-10-07 18:14:53 -07001258 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001259 CustomContentCallbacks callbacks, String description) {
1260 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001261 }
1262
Adam Cohenedb40762013-07-18 16:45:45 -07001263 // The custom content needs to offset its content to account for the QSB
1264 public int getTopOffsetForCustomContent() {
1265 return mWorkspace.getPaddingTop();
1266 }
1267
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001268 @Override
1269 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001270 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001271 if (mModel.isCurrentCallbacks(this)) {
1272 mModel.stopLoader();
1273 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001274 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1275
Romain Guy13c2e7b2010-03-10 19:45:00 -08001276 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001277 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001278
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001279 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001280 @Override
1281 public void onWindowFocusChanged(boolean hasFocus) {
1282 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001283 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001284
1285 if (mLauncherCallbacks != null) {
1286 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1287 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001288 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001289
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290 private boolean acceptFilter() {
1291 final InputMethodManager inputManager = (InputMethodManager)
1292 getSystemService(Context.INPUT_METHOD_SERVICE);
1293 return !inputManager.isFullscreenMode();
1294 }
1295
1296 @Override
1297 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001298 final int uniChar = event.getUnicodeChar();
1299 final boolean handled = super.onKeyDown(keyCode, event);
1300 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1301 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1303 keyCode, event);
1304 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001305 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001306 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001307 // showSearchDialog()
1308 // If there are multiple keystrokes before the search dialog takes focus,
1309 // onSearchRequested() will be called for every keystroke,
1310 // but it is idempotent, so it's fine.
1311 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001312 }
1313 }
1314
Joe Onorato8a9625e2010-01-28 15:55:35 -08001315 // Eat the long press event so the keyboard doesn't come up.
1316 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1317 return true;
1318 }
1319
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001320 return handled;
1321 }
1322
Karl Rosaen138a0412009-04-23 19:00:21 -07001323 private String getTypedText() {
1324 return mDefaultKeySsb.toString();
1325 }
1326
1327 private void clearTypedText() {
1328 mDefaultKeySsb.clear();
1329 mDefaultKeySsb.clearSpans();
1330 Selection.setSelection(mDefaultKeySsb, 0);
1331 }
1332
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001334 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1335 * State
1336 */
1337 private static State intToState(int stateOrdinal) {
1338 State state = State.WORKSPACE;
1339 final State[] stateValues = State.values();
1340 for (int i = 0; i < stateValues.length; i++) {
1341 if (stateValues[i].ordinal() == stateOrdinal) {
1342 state = stateValues[i];
1343 break;
1344 }
1345 }
1346 return state;
1347 }
1348
1349 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 * Restores the previous state, if it exists.
1351 *
1352 * @param savedState The previous state.
1353 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001354 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 private void restoreState(Bundle savedState) {
1356 if (savedState == null) {
1357 return;
1358 }
1359
Michael Jurka883f55b2010-10-21 15:47:14 -07001360 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001361 if (state == State.APPS || state == State.WIDGETS) {
1362 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001363 }
1364
Adam Cohen21cd0022013-10-09 18:57:02 -07001365 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1366 PagedView.INVALID_RESTORE_PAGE);
1367 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001368 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 }
1370
Winson Chung3d503fb2011-07-13 17:25:49 -07001371 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001372 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001373
Winson Chung3d503fb2011-07-13 17:25:49 -07001374 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1375 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001376 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1378 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001379 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1380 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Adam Cohenb823ae42015-03-27 18:07:52 -07001381 AppWidgetProviderInfo info = savedState.getParcelable(
1382 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001383 mPendingAddWidgetInfo = info == null ?
1384 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1385
Adam Cohen4637b5a2013-11-04 18:21:24 -08001386 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001387 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 mRestoring = true;
1389 }
1390
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001391 mItemIdToViewId = (HashMap<Integer, Integer>)
1392 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 }
1394
1395 /**
1396 * Finds all the views we need and configure them properly.
1397 */
1398 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001399 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001400
Craig Mautner360310b2012-10-26 15:13:08 -07001401 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001402 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001403 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1404 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001405 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001406 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001407
John Spurlock77e1f472013-09-11 10:09:51 -04001408 mLauncherView.setSystemUiVisibility(
1409 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001410 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001411
Winson Chung4c98d922011-05-31 16:50:48 -07001412 // Setup the drag layer
1413 mDragLayer.setup(this, dragController);
1414
Winson Chung3d503fb2011-07-13 17:25:49 -07001415 // Setup the hotseat
1416 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1417 if (mHotseat != null) {
1418 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001419 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001420 }
1421
Jorim Jaggid017f882014-01-14 17:08:48 -08001422 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001423 View widgetButton = findViewById(R.id.widget_button);
1424 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001425 @Override
1426 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001427 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001428 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001429 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001430 }
1431 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001432 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1433
1434 View wallpaperButton = findViewById(R.id.wallpaper_button);
1435 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001436 @Override
1437 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001438 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001439 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001440 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001441 }
1442 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001443 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1444
1445 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001446 if (hasSettings()) {
1447 settingsButton.setOnClickListener(new OnClickListener() {
1448 @Override
1449 public void onClick(View arg0) {
1450 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001451 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001452 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001453 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001454 });
1455 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1456 } else {
1457 settingsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001458 }
1459
Adam Cohendbdff6b2013-09-18 19:09:15 -07001460 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001461
Winson Chung4c98d922011-05-31 16:50:48 -07001462 // Setup the workspace
1463 mWorkspace.setHapticFeedbackEnabled(false);
1464 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001465 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001466 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001467
Winson Chungf0ea4d32011-06-06 14:27:16 -07001468 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001469 mSearchDropTargetBar = (SearchDropTargetBar)
1470 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001471
Winson Chungb745afb2015-03-02 11:51:23 -08001472 // Setup Apps
1473 mAppsView = (AppsContainerView) findViewById(R.id.apps_view);
Winson Chung83f59ab2015-05-05 17:21:58 -07001474 if (isAllAppsSearchOverridden()) {
1475 mAppsView.hideHeaderBar();
Winson Chung0f785722015-04-08 10:27:49 -07001476 }
Winson Chungb745afb2015-03-02 11:51:23 -08001477
Winson Chungf0ea4d32011-06-06 14:27:16 -07001478 // Setup AppsCustomize
Hyunyoung Song3f471442015-04-08 19:01:34 -07001479 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001480
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001482 dragController.setDragScoller(mWorkspace);
1483 dragController.setScrollView(mDragLayer);
1484 dragController.setMoveTarget(mWorkspace);
1485 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001486 if (mSearchDropTargetBar != null) {
1487 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001488 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001489 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001490
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001491 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001492 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001493 mWeightWatcher = new WeightWatcher(this);
1494 mWeightWatcher.setAlpha(0.5f);
1495 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001496 new FrameLayout.LayoutParams(
1497 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001498 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001499 Gravity.BOTTOM)
1500 );
Adam Cohen39a06042013-07-19 14:30:12 -07001501
1502 boolean show = shouldShowWeightWatcher();
1503 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001504 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 }
1506
1507 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001508 * Sets the all apps button. This method is called from {@link Hotseat}.
1509 */
1510 public void setAllAppsButton(View allAppsButton) {
1511 mAllAppsButton = allAppsButton;
1512 }
1513
1514 public View getAllAppsButton() {
1515 return mAllAppsButton;
1516 }
1517
1518 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 * Creates a view representing a shortcut.
1520 *
1521 * @param info The data structure describing the shortcut.
1522 *
1523 * @return A View inflated from R.layout.application.
1524 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001525 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001526 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527 }
1528
1529 /**
1530 * Creates a view representing a shortcut inflated from the specified resource.
1531 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001532 * @param parent The group the shortcut belongs to.
1533 * @param info The data structure describing the shortcut.
1534 *
1535 * @return A View inflated from layoutResId.
1536 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001537 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
1538 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(R.layout.application,
1539 parent, false);
1540 favorite.applyFromShortcutInfo(info, mIconCache);
1541 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001543 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 return favorite;
1545 }
1546
1547 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001548 * Add a shortcut to the workspace.
1549 *
1550 * @param data The intent describing the shortcut.
1551 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001553 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001554 int cellY) {
1555 int[] cellXY = mTmpAddItemCellCoordinates;
1556 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001557 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001558
Sunny Goyal5c97f512015-05-19 16:03:28 -07001559 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(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
Sunny Goyal5c97f512015-05-19 16:03:28 -07001565 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001566 // First we check if we already know the exact location where we want to add this item.
1567 if (cellX >= 0 && cellY >= 0) {
1568 cellXY[0] = cellX;
1569 cellXY[1] = cellY;
1570 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001571
1572 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001573 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001574 true, null,null)) {
1575 return;
1576 }
1577 DragObject dragObject = new DragObject();
1578 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001579 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1580 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001581 return;
1582 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001583 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001584 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001585 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001586 foundCellSpan = (result != null);
1587 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001588 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001589 }
1590
1591 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001592 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001593 return;
1594 }
1595
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001596 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597
1598 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001599 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001600 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 }
1602 }
1603
Adam Cohen2f093b62012-04-30 18:59:53 -07001604 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1605 int minHeight) {
1606 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001607 // We want to account for the extra amount of padding that we are adding to the widget
1608 // to ensure that it gets the full amount of space that it has requested
1609 int requiredWidth = minWidth + padding.left + padding.right;
1610 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001611 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001612 }
1613
Adam Cohen2f093b62012-04-30 18:59:53 -07001614 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1615 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001616 }
1617
Adam Cohen2f093b62012-04-30 18:59:53 -07001618 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1619 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001620 }
1621
Adam Cohen2f093b62012-04-30 18:59:53 -07001622 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1623 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001624 }
1625
Adam Cohen2f093b62012-04-30 18:59:53 -07001626 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1627 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001628 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001629 }
1630
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001631 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001632 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001634 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001635 */
Adam Cohen091440a2015-03-18 14:16:05 -07001636 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001637 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1638
1639 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001640 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001641 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1642 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001643 }
Romain Guycbb89e42009-06-08 15:52:54 -07001644
Adam Cohen59400422014-03-05 18:07:04 -08001645 if (appWidgetInfo.isCustomWidget) {
1646 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001647 }
1648
Adam Cohen59400422014-03-05 18:07:04 -08001649 LauncherAppWidgetInfo launcherInfo;
1650 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1651 launcherInfo.spanX = info.spanX;
1652 launcherInfo.spanY = info.spanY;
1653 launcherInfo.minSpanX = info.minSpanX;
1654 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001655 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001656
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001657 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001658 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001659
1660 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001661 if (hostView == null) {
1662 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001663 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1664 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001665 } else {
1666 // The AppWidgetHostView has already been inflated and instantiated
1667 launcherInfo.hostView = hostView;
1668 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001669 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001670 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001671 launcherInfo.notifyWidgetSizeChanged(this);
1672
Adam Cohen59400422014-03-05 18:07:04 -08001673 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
1674 info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001675
1676 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001677 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001678 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001679 }
Romain Guycbb89e42009-06-08 15:52:54 -07001680
Adam Cohended9f8d2010-11-03 13:25:16 -07001681 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1682 @Override
1683 public void onReceive(Context context, Intent intent) {
1684 final String action = intent.getAction();
1685 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1686 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001687 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001688 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001689
Winson Chungc100e8e2011-08-09 16:02:43 -07001690 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001691 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001692 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001693 mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001694 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001695 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001696 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1697 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001698 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001699 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1700 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001701 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001702 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1703 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1704 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001705 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001706 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1707 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001708 }
1709 }
1710 };
1711
1712 @Override
1713 public void onAttachedToWindow() {
1714 super.onAttachedToWindow();
1715
1716 // Listen for broadcasts related to user-presence
1717 final IntentFilter filter = new IntentFilter();
1718 filter.addAction(Intent.ACTION_SCREEN_OFF);
1719 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001720 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001721 if (ENABLE_DEBUG_INTENTS) {
1722 filter.addAction(DebugIntents.DELETE_DATABASE);
1723 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1724 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001725 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001726 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001727 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001728 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001729 mVisible = true;
1730 }
1731
Adam Cohen0b395352014-06-09 22:54:36 +00001732 /**
1733 * Sets up transparent navigation and status bars in LMP.
1734 * This method is a no-op for other platform versions.
1735 */
Sunny Goyald0091012015-01-20 15:55:34 -08001736 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Adam Cohen0b395352014-06-09 22:54:36 +00001737 private void setupTransparentSystemBarsForLmp() {
Kenny Guyd794a3f2014-09-16 15:17:58 +01001738 if (Utilities.isLmpOrAbove()) {
Sunny Goyald0091012015-01-20 15:55:34 -08001739 Window window = getWindow();
1740 window.getAttributes().systemUiVisibility |=
1741 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1742 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1743 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1744 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1745 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1746 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
1747 window.setStatusBarColor(Color.TRANSPARENT);
1748 window.setNavigationBarColor(Color.TRANSPARENT);
Adam Cohen0b395352014-06-09 22:54:36 +00001749 }
1750 }
1751
Adam Cohended9f8d2010-11-03 13:25:16 -07001752 @Override
1753 public void onDetachedFromWindow() {
1754 super.onDetachedFromWindow();
1755 mVisible = false;
1756
Adam Cohend113e0c2010-11-11 10:48:05 -08001757 if (mAttached) {
1758 unregisterReceiver(mReceiver);
1759 mAttached = false;
1760 }
Winson Chungb745afb2015-03-02 11:51:23 -08001761 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001762 }
1763
1764 public void onWindowVisibilityChanged(int visibility) {
1765 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001766 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001767 // The following code used to be in onResume, but it turns out onResume is called when
1768 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1769 // is a more appropriate event to handle
1770 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001771 if (!mWorkspaceLoading) {
1772 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001773 // We want to let Launcher draw itself at least once before we force it to build
1774 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001775 // apps is nice and speedy.
1776 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001777 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001778 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001779 if (mStarted) return;
1780 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001781 // We delay the layer building a bit in order to give
1782 // other message processing a time to run. In particular
1783 // this avoids a delay in hiding the IME if it was
1784 // currently shown, because doing that may involve
1785 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001786 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001787 final ViewTreeObserver.OnDrawListener listener = this;
1788 mWorkspace.post(new Runnable() {
1789 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001790 if (mWorkspace != null &&
1791 mWorkspace.getViewTreeObserver() != null) {
1792 mWorkspace.getViewTreeObserver().
1793 removeOnDrawListener(listener);
1794 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001795 }
1796 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001797 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001798 }
1799 });
1800 }
1801 clearTypedText();
1802 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001803 }
1804
Adam Cohen091440a2015-03-18 14:16:05 -07001805 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001806 mHandler.removeMessages(ADVANCE_MSG);
1807 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1808 mHandler.sendMessageDelayed(msg, delay);
1809 mAutoAdvanceSentTime = System.currentTimeMillis();
1810 }
1811
Adam Cohen091440a2015-03-18 14:16:05 -07001812 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001813 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1814 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1815 mAutoAdvanceRunning = autoAdvanceRunning;
1816 if (autoAdvanceRunning) {
1817 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1818 sendAdvanceMessage(delay);
1819 } else {
1820 if (!mWidgetsToAdvance.isEmpty()) {
1821 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1822 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1823 }
1824 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001825 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001826 }
1827 }
1828 }
1829
1830 private final Handler mHandler = new Handler() {
1831 @Override
1832 public void handleMessage(Message msg) {
1833 if (msg.what == ADVANCE_MSG) {
1834 int i = 0;
1835 for (View key: mWidgetsToAdvance.keySet()) {
1836 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1837 final int delay = mAdvanceStagger * i;
1838 if (v instanceof Advanceable) {
1839 postDelayed(new Runnable() {
1840 public void run() {
1841 ((Advanceable) v).advance();
1842 }
1843 }, delay);
1844 }
1845 i++;
1846 }
1847 sendAdvanceMessage(mAdvanceInterval);
1848 }
1849 }
1850 };
1851
1852 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001853 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001854 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1855 if (v instanceof Advanceable) {
1856 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001857 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001858 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001859 }
1860 }
1861
1862 void removeWidgetToAutoAdvance(View hostView) {
1863 if (mWidgetsToAdvance.containsKey(hostView)) {
1864 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001865 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001866 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001867 }
1868
Joe Onorato9c1289c2009-08-17 11:03:03 -04001869 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001870 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001871 launcherInfo.hostView = null;
1872 }
1873
Hyunyoung Song3f471442015-04-08 19:01:34 -07001874 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001875 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1876 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001877 }
1878
Winson Chunga6945242014-01-08 14:04:34 -08001879 public DragLayer getDragLayer() {
1880 return mDragLayer;
1881 }
1882
Winson Chungb745afb2015-03-02 11:51:23 -08001883 public AppsContainerView getAppsView() {
1884 return mAppsView;
1885 }
1886
Hyunyoung Song3f471442015-04-08 19:01:34 -07001887 public WidgetsContainerView getWidgetsView() {
1888 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001889 }
1890
Winson Chunga6945242014-01-08 14:04:34 -08001891 public Workspace getWorkspace() {
1892 return mWorkspace;
1893 }
1894
1895 public Hotseat getHotseat() {
1896 return mHotseat;
1897 }
1898
Jorim Jaggid017f882014-01-14 17:08:48 -08001899 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001900 return mOverviewPanel;
1901 }
1902
1903 public SearchDropTargetBar getSearchBar() {
1904 return mSearchDropTargetBar;
1905 }
1906
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001907 public LauncherAppWidgetHost getAppWidgetHost() {
1908 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 }
Romain Guycbb89e42009-06-08 15:52:54 -07001910
Winson Chunga9abd0e2010-10-27 17:18:37 -07001911 public LauncherModel getModel() {
1912 return mModel;
1913 }
1914
Winson Chunga6945242014-01-08 14:04:34 -08001915 protected SharedPreferences getSharedPrefs() {
1916 return mSharedPrefs;
1917 }
1918
Bjorn Bringertc459e522013-06-07 19:36:01 +01001919 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001920 getWindow().closeAllPanels();
1921
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001922 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001923 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001924 }
1925
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 @Override
1927 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001928 long startTime = 0;
1929 if (DEBUG_RESUME_TIME) {
1930 startTime = System.currentTimeMillis();
1931 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 super.onNewIntent(intent);
1933
1934 // Close the menu
1935 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001936 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001937 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001938
Adam Cohened307df2013-10-02 09:37:31 -07001939 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1940 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1941 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001942
Adam Cohen6fecd412013-10-02 17:41:50 -07001943 if (mWorkspace == null) {
1944 // Can be cases where mWorkspace is null, this prevents a NPE
1945 return;
1946 }
1947 Folder openFolder = mWorkspace.getOpenFolder();
1948 // In all these cases, only animate if we're already on home
1949 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001950
1951 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1952 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Adam Cohen6fecd412013-10-02 17:41:50 -07001953 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Cohen9211d422014-10-07 18:14:53 -07001954 openFolder == null && moveToDefaultScreen) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001955 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001956 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001957
Adam Cohen6fecd412013-10-02 17:41:50 -07001958 closeFolder();
1959 exitSpringLoadedDragMode();
1960
1961 // If we are already on home, then just animate back to the workspace,
1962 // otherwise, just wait until onResume to set the state back to Workspace
1963 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001964 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001965 } else {
1966 mOnResumeState = State.WORKSPACE;
1967 }
1968
1969 final View v = getWindow().peekDecorView();
1970 if (v != null && v.getWindowToken() != null) {
1971 InputMethodManager imm = (InputMethodManager)getSystemService(
1972 INPUT_METHOD_SERVICE);
1973 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1974 }
1975
Winson Chungb745afb2015-03-02 11:51:23 -08001976 // Reset the apps view
1977 if (!alreadyOnHome && mAppsView != null) {
1978 mAppsView.scrollToTop();
1979 }
1980
Hyunyoung Song3f471442015-04-08 19:01:34 -07001981 // Reset the widgets view
1982 if (!alreadyOnHome && mWidgetsView != null) {
1983 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001984 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001985
Adam Cohen9211d422014-10-07 18:14:53 -07001986 if (mLauncherCallbacks != null) {
1987 mLauncherCallbacks.onHomeIntent();
1988 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 }
Adam Cohened307df2013-10-02 09:37:31 -07001990
Michael Jurka447bf842013-05-15 14:52:15 +02001991 if (DEBUG_RESUME_TIME) {
1992 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1993 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994
Adam Cohen9211d422014-10-07 18:14:53 -07001995 if (mLauncherCallbacks != null) {
1996 mLauncherCallbacks.onNewIntent(intent);
1997 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001998 }
1999
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002000 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07002001 public void onRestoreInstanceState(Bundle state) {
2002 super.onRestoreInstanceState(state);
2003 for (int page: mSynchronouslyBoundPages) {
2004 mWorkspace.restoreInstanceStateForChild(page);
2005 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 }
2007
2008 @Override
2009 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07002010 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08002011 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
2012 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07002013 }
Adam Cohen95bb8002011-07-03 23:40:28 -07002014 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002015
Michael Jurka883f55b2010-10-21 15:47:14 -07002016 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07002017 // We close any open folder since it will not be re-opened, and we need to make sure
2018 // this state is reflected.
2019 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020
Adam Cohendcd297f2013-06-18 13:13:40 -07002021 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07002022 mWaitingForResult) {
2023 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07002024 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07002025 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2026 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002027 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2028 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2029 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08002030 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 }
2032
Hyunyoung Song3f471442015-04-08 19:01:34 -07002033 // Save the current widgets tray?
2034 // TODO(hyunyoungs)
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002035 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
Adam Cohen9211d422014-10-07 18:14:53 -07002036
2037 if (mLauncherCallbacks != null) {
2038 mLauncherCallbacks.onSaveInstanceState(outState);
2039 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 }
2041
2042 @Override
2043 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002045
Winson Chunge7a03942011-08-05 15:05:12 -07002046 // Remove all pending runnables
2047 mHandler.removeMessages(ADVANCE_MSG);
2048 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002049 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002050
Winson Chungcd2b0142011-06-08 16:02:26 -07002051 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002052 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07002053
2054 // It's possible to receive onDestroy after a new Launcher activity has
2055 // been created. In this case, don't interfere with the new Launcher.
2056 if (mModel.isCurrentCallbacks(this)) {
2057 mModel.stopLoader();
2058 app.setLauncher(null);
2059 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002060
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002062 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002064 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002066 mAppWidgetHost = null;
2067
2068 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069
2070 TextKeyListener.getInstance().release();
2071
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002072 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002073 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002074
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002075 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002076 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002077 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002078 mWorkspace = null;
2079 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002080
Michael Jurka2ecf9952012-06-18 12:52:28 -07002081 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002082
2083 if (mLauncherCallbacks != null) {
2084 mLauncherCallbacks.onDestroy();
2085 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002086 }
2087
Adam Cohena9cf38f2011-05-02 15:36:58 -07002088 public DragController getDragController() {
2089 return mDragController;
2090 }
2091
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002092 @Override
2093 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002094 onStartForResult(requestCode);
2095 super.startActivityForResult(intent, requestCode);
2096 }
2097
2098 @Override
2099 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2100 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2101 onStartForResult(requestCode);
2102 try {
2103 super.startIntentSenderForResult(intent, requestCode,
2104 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2105 } catch (IntentSender.SendIntentException e) {
2106 throw new ActivityNotFoundException();
2107 }
2108 }
2109
2110 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002111 if (requestCode >= 0) {
2112 setWaitingForResult(true);
2113 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002114 }
2115
Winson Chung70d72102011-08-12 11:24:35 -07002116 /**
2117 * Indicates that we want global search for this activity by setting the globalSearch
2118 * argument for {@link #startSearch} to true.
2119 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002121 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002122 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002123
Karl Rosaen138a0412009-04-23 19:00:21 -07002124 if (initialQuery == null) {
2125 // Use any text typed in the launcher as the initial query
2126 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002127 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 if (appSearchData == null) {
2129 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002130 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 }
Winson Chungadf0c182012-08-23 14:59:07 -07002132 Rect sourceBounds = new Rect();
2133 if (mSearchDropTargetBar != null) {
2134 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2135 }
Romain Guycbb89e42009-06-08 15:52:54 -07002136
Ian Parkinson047036e2014-09-01 15:40:53 +01002137 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002138 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002139 if (clearTextImmediately) {
2140 clearTypedText();
2141 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002142
2143 // We need to show the workspace after starting the search
2144 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002145 }
2146
Ian Parkinson047036e2014-09-01 15:40:53 +01002147 /**
2148 * Start a text search.
2149 *
2150 * @return {@code true} if the search will start immediately, so any further keypresses
2151 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2152 * to buffer keypresses.
2153 */
2154 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002155 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002156 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2157 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2158 sourceBounds);
2159 }
2160
Michael Jurkaa33411c2012-06-14 16:18:21 -07002161 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002162 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002163 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002164 }
2165
2166 /**
2167 * Starts the global search activity. This code is a copied from SearchManager
2168 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002169 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002170 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002171 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002172 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2173 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2174 if (globalSearchActivity == null) {
2175 Log.w(TAG, "No global search activity found.");
2176 return;
2177 }
2178 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2179 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2180 intent.setComponent(globalSearchActivity);
2181 // Make sure that we have a Bundle to put source in
2182 if (appSearchData == null) {
2183 appSearchData = new Bundle();
2184 } else {
2185 appSearchData = new Bundle(appSearchData);
2186 }
Adam Cohen9211d422014-10-07 18:14:53 -07002187 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002188 if (!appSearchData.containsKey("source")) {
2189 appSearchData.putString("source", getPackageName());
2190 }
2191 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2192 if (!TextUtils.isEmpty(initialQuery)) {
2193 intent.putExtra(SearchManager.QUERY, initialQuery);
2194 }
2195 if (selectInitialQuery) {
2196 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2197 }
2198 intent.setSourceBounds(sourceBounds);
2199 try {
2200 startActivity(intent);
2201 } catch (ActivityNotFoundException ex) {
2202 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2203 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 }
2205
Yura4f93ec62014-02-04 14:15:21 +00002206 public boolean isOnCustomContent() {
2207 return mWorkspace.isOnOrMovingToCustomContent();
2208 }
2209
Winson Chung70d72102011-08-12 11:24:35 -07002210 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002211 public boolean onPrepareOptionsMenu(Menu menu) {
2212 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002213 if (!isOnCustomContent()) {
2214 // Close any open folders
2215 closeFolder();
2216 // Stop resizing any widgets
2217 mWorkspace.exitWidgetResizeMode();
2218 if (!mWorkspace.isInOverviewMode()) {
2219 // Show the overview mode
2220 showOverviewMode(true);
2221 } else {
2222 showWorkspace(true);
2223 }
Winson Chunge0298742014-01-17 12:03:00 -08002224 }
Adam Cohen9211d422014-10-07 18:14:53 -07002225 if (mLauncherCallbacks != null) {
2226 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2227 }
2228
Michael Jurkab94f3f82013-09-11 18:08:54 +02002229 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002230 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002232 @Override
2233 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002234 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002235 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002236 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002237 }
2238
Joe Onorato9c1289c2009-08-17 11:03:03 -04002239 public boolean isWorkspaceLocked() {
2240 return mWorkspaceLoading || mWaitingForResult;
2241 }
2242
Adam Cohen517a7f52014-03-01 12:12:59 -08002243 public boolean isWorkspaceLoading() {
2244 return mWorkspaceLoading;
2245 }
2246
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002247 private void setWorkspaceLoading(boolean value) {
2248 boolean isLocked = isWorkspaceLocked();
2249 mWorkspaceLoading = value;
2250 if (isLocked != isWorkspaceLocked()) {
2251 onWorkspaceLockedChanged();
2252 }
2253 }
2254
2255 private void setWaitingForResult(boolean value) {
2256 boolean isLocked = isWorkspaceLocked();
2257 mWaitingForResult = value;
2258 if (isLocked != isWorkspaceLocked()) {
2259 onWorkspaceLockedChanged();
2260 }
2261 }
2262
Adam Cohen9211d422014-10-07 18:14:53 -07002263 protected void onWorkspaceLockedChanged() {
2264 if (mLauncherCallbacks != null) {
2265 mLauncherCallbacks.onWorkspaceLockedChanged();
2266 }
2267 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002268
Michael Jurka0280c3b2010-09-17 15:00:07 -07002269 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002270 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002271 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002272 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2273 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002274 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002275 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002276 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002277
Sunny Goyale6b63a32015-01-16 16:14:29 -08002278 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002279 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Adam Cohenad4e15c2013-10-17 16:21:35 -07002280 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2281 }
2282
Sunny Goyale6b63a32015-01-16 16:14:29 -08002283 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002284 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2285 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002286 if (appWidgetInfo.configure != null) {
2287 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002288 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002289
Bjorn Bringert7984c942009-12-09 15:38:25 +00002290 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002291 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2292 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2293
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002294 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002295 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002296 Runnable onComplete = new Runnable() {
2297 @Override
2298 public void run() {
2299 // Exit spring loaded mode if necessary after adding the widget
2300 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2301 null);
2302 }
2303 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002304 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002305 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002306 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002307 }
2308 }
Romain Guycbb89e42009-06-08 15:52:54 -07002309
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002310 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002311 // Close any folders that may be open.
2312 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002313 mWorkspace.moveToCustomContentScreen(animate);
2314 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002315
2316 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2317 int[] cell, int spanX, int spanY) {
2318 switch (info.itemType) {
2319 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2320 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2321 int span[] = new int[2];
2322 span[0] = spanX;
2323 span[1] = spanY;
2324 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2325 container, screenId, cell, span);
2326 break;
2327 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2328 processShortcutFromDrop(info.componentName, container, screenId, cell);
2329 break;
2330 default:
2331 throw new IllegalStateException("Unknown item type: " + info.itemType);
2332 }
2333 }
2334
Adam Cohenfbba09b2011-07-18 21:43:05 -07002335 /**
2336 * Process a shortcut drop.
2337 *
2338 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002339 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002340 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002341 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002342 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2343 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002344 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002345 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002346 mPendingAddInfo.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002347 mPendingAddInfo.dropPos = null;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002348
2349 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002350 mPendingAddInfo.cellX = cell[0];
2351 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002352 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002353
2354 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2355 createShortcutIntent.setComponent(componentName);
2356 processShortcut(createShortcutIntent);
2357 }
2358
Adam Cohenfbba09b2011-07-18 21:43:05 -07002359 /**
2360 * Process a widget drop.
2361 *
2362 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002363 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002364 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002365 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002366 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2367 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002368 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002369 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002370 mPendingAddInfo.screenId = info.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002371 mPendingAddInfo.dropPos = null;
Adam Cohend41fbf52012-02-16 23:53:59 -08002372 mPendingAddInfo.minSpanX = info.minSpanX;
2373 mPendingAddInfo.minSpanY = info.minSpanY;
2374
Adam Cohenfbba09b2011-07-18 21:43:05 -07002375 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002376 mPendingAddInfo.cellX = cell[0];
2377 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002378 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002379 if (span != null) {
2380 mPendingAddInfo.spanX = span[0];
2381 mPendingAddInfo.spanY = span[1];
2382 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002383
Adam Cohened66b2b2012-01-23 17:28:51 -08002384 AppWidgetHostView hostView = info.boundWidget;
2385 int appWidgetId;
2386 if (hostView != null) {
2387 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002388 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002389 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002390 // In this case, we either need to start an activity to get permission to bind
2391 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002392 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002393 Bundle options = info.bindOptions;
2394
Sunny Goyalffe83f12014-08-14 17:39:34 -07002395 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2396 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002397 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002398 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002399 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002400 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002401 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2402 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2403 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002404 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2405 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002406 // TODO: we need to make sure that this accounts for the options bundle.
2407 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002408 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2409 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002410 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002411 }
2412
Joe Onoratodeb98af2010-02-19 14:59:39 -08002413 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002414 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002415 }
2416
Winson Chung24ab2f12010-09-16 14:10:47 -07002417 void processWallpaper(Intent intent) {
2418 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2419 }
2420
Adam Cohendcd297f2013-06-18 13:13:40 -07002421 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002422 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002423 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002424 folderInfo.title = getText(R.string.folder_name);
2425
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002426 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002427 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2428 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002429 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430
2431 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002432 FolderIcon newFolder =
2433 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002434 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002435 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002436 // Force measure the new folder icon
2437 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2438 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002439 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002440 }
Romain Guycbb89e42009-06-08 15:52:54 -07002441
Joe Onorato9c1289c2009-08-17 11:03:03 -04002442 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002443 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002444 }
2445
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002446 /**
2447 * Registers various content observers. The current implementation registers
2448 * only a favorites observer to keep track of the favorites applications.
2449 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002450 private void registerContentObservers() {
2451 ContentResolver resolver = getContentResolver();
2452 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2453 true, mWidgetObserver);
2454 }
2455
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002456 @Override
2457 public boolean dispatchKeyEvent(KeyEvent event) {
2458 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2459 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002460 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002461 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002462 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002463 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002464 dumpState();
2465 return true;
2466 }
2467 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002468 }
2469 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2470 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002471 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002472 return true;
2473 }
2474 }
2475
2476 return super.dispatchKeyEvent(event);
2477 }
2478
Joe Onorato88ec0992009-11-19 13:16:06 -08002479 @Override
2480 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002481 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2482 return;
2483 }
2484
Winson Chung3d9490a2015-03-24 17:38:42 -07002485 LauncherAccessibilityDelegate delegate =
2486 LauncherAppState.getInstance().getAccessibilityDelegate();
2487 if (delegate != null && delegate.onBackPressed()) {
Adam Cohenc9735cf2015-01-23 16:11:55 -08002488 return;
2489 }
2490
Winson Chungb745afb2015-03-02 11:51:23 -08002491 if (isAppsViewVisible()) {
2492 showWorkspace(true);
2493 } else if (isWidgetsViewVisible()) {
2494 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002495 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002496 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002497 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002498 Folder openFolder = mWorkspace.getOpenFolder();
2499 if (openFolder.isEditingName()) {
2500 openFolder.dismissEditingName();
2501 } else {
2502 closeFolder();
2503 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002504 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002505 mWorkspace.exitWidgetResizeMode();
2506
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002507 // Back button is a no-op here, but give at least some feedback for the button press
2508 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002509 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002510 }
2511
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002512 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002513 * Re-listen when widgets are reset.
2514 */
Adam Cohen091440a2015-03-18 14:16:05 -07002515 @Thunk void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002516 if (mAppWidgetHost != null) {
2517 mAppWidgetHost.startListening();
2518 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002519 }
2520
2521 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002522 * Launches the intent referred by the clicked shortcut.
2523 *
2524 * @param v The view representing the clicked shortcut.
2525 */
2526 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002527 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2528 // view has detached (it's possible for this to happen if the view is removed mid touch).
2529 if (v.getWindowToken() == null) {
2530 return;
2531 }
2532
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002533 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002534 return;
2535 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002536
Adam Cohen1697b792013-09-17 19:08:21 -07002537 if (v instanceof Workspace) {
2538 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002539 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002540 }
2541 return;
2542 }
2543
2544 if (v instanceof CellLayout) {
2545 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002546 showWorkspace(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002547 }
2548 }
2549
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002550 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002551 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002552 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002553 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002554 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002555 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002556 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002557 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002558 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002559 } else if (tag instanceof AppInfo) {
2560 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002561 } else if (tag instanceof LauncherAppWidgetInfo) {
2562 if (v instanceof PendingAppWidgetHostView) {
2563 onClickPendingWidget((PendingAppWidgetHostView) v);
2564 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002565 }
2566 }
2567
Sunny Goyal508da152014-08-14 10:53:27 -07002568 public void onClickPagedViewIcon(View v) {
2569 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002570 if (mLauncherCallbacks != null) {
2571 mLauncherCallbacks.onClickPagedViewIcon(v);
2572 }
Sunny Goyal508da152014-08-14 10:53:27 -07002573 }
2574
Sunny Goyal70660032015-05-14 00:07:08 -07002575 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002576 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002577 return false;
2578 }
2579
Michael Jurkaaf442092010-06-10 17:01:57 -07002580 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002581 * Event handler for the app widget view which has not fully restored.
2582 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002583 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002584 if (mIsSafeModeEnabled) {
2585 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2586 return;
2587 }
2588
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002589 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002590 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002591 int widgetId = info.appWidgetId;
2592 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2593 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002594 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2595 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002596 mPendingAddInfo.copyFrom(info);
2597 mPendingAddWidgetId = widgetId;
2598
Sunny Goyalffe83f12014-08-14 17:39:34 -07002599 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2600 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002601 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002602 } else if (info.installProgress < 0) {
2603 // The install has not been queued
2604 final String packageName = info.providerName.getPackageName();
2605 showBrokenAppInstallDialog(packageName,
2606 new DialogInterface.OnClickListener() {
2607 public void onClick(DialogInterface dialog, int id) {
2608 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2609 }
2610 });
2611 } else {
2612 // Download has started.
2613 final String packageName = info.providerName.getPackageName();
2614 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002615 }
2616 }
2617
2618 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002619 * Event handler for the "grid" button that appears on the home screen, which
2620 * enters all apps mode.
2621 *
2622 * @param v The view that was clicked.
2623 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002624 protected void onClickAllAppsButton(View v) {
2625 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chungb745afb2015-03-02 11:51:23 -08002626 if (isAppsViewVisible()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002627 showWorkspace(true);
2628 } else {
Winson Chung4ac30062015-05-08 17:34:17 -07002629 // Try and refresh the set of predicted apps before we enter launcher
2630 showAppsView(true /* animated */, false /* resetListToTop */,
2631 true /* updatePredictedApps */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002632 }
2633 }
2634
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002635 private void showBrokenAppInstallDialog(final String packageName,
2636 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002637 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002638 .setTitle(R.string.abandoned_promises_title)
2639 .setMessage(R.string.abandoned_promise_explanation)
2640 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2641 .setNeutralButton(R.string.abandoned_clean_this,
2642 new DialogInterface.OnClickListener() {
2643 public void onClick(DialogInterface dialog, int id) {
2644 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2645 mWorkspace.removeAbandonedPromise(packageName, user);
2646 }
2647 })
2648 .create().show();
2649 return;
2650 }
2651
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002652 /**
2653 * Event handler for an app shortcut click.
2654 *
2655 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2656 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002657 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002658 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2659 Object tag = v.getTag();
2660 if (!(tag instanceof ShortcutInfo)) {
2661 throw new IllegalArgumentException("Input must be a Shortcut");
2662 }
2663
2664 // Open shortcut
2665 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002666
2667 if (shortcut.isDisabled != 0) {
2668 int error = R.string.activity_not_available;
2669 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2670 error = R.string.safemode_shortcut_error;
2671 }
2672 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2673 return;
2674 }
2675
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002676 final Intent intent = shortcut.intent;
2677
2678 // Check for special shortcuts
2679 if (intent.getComponent() != null) {
2680 final String shortcutClass = intent.getComponent().getClassName();
2681
2682 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2683 MemoryDumpActivity.startDump(this);
2684 return;
2685 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2686 toggleShowWeightWatcher();
2687 return;
2688 }
2689 }
2690
Chris Wren40c5ed32014-06-24 18:24:23 -04002691 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002692 if ((v instanceof BubbleTextView)
2693 && shortcut.isPromise()
2694 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002695 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002696 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002697 new DialogInterface.OnClickListener() {
2698 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002699 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002700 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002701 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002702 return;
2703 }
2704
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002705 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002706 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002707
2708 if (mLauncherCallbacks != null) {
2709 mLauncherCallbacks.onClickAppShortcut(v);
2710 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002711 }
2712
Adam Cohen091440a2015-03-18 14:16:05 -07002713 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002714 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002715 final ShortcutInfo shortcut;
2716 final Intent intent;
2717 if (tag instanceof ShortcutInfo) {
2718 shortcut = (ShortcutInfo) tag;
2719 intent = shortcut.intent;
2720 int[] pos = new int[2];
2721 v.getLocationOnScreen(pos);
2722 intent.setSourceBounds(new Rect(pos[0], pos[1],
2723 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002724
Sunny Goyal508da152014-08-14 10:53:27 -07002725 } else if (tag instanceof AppInfo) {
2726 shortcut = null;
2727 intent = ((AppInfo) tag).intent;
2728 } else {
2729 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2730 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002731
2732 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002733 mStats.recordLaunch(intent, shortcut);
2734
2735 if (success && v instanceof BubbleTextView) {
2736 mWaitingForResume = (BubbleTextView) v;
2737 mWaitingForResume.setStayPressed(true);
2738 }
2739 }
2740
2741 /**
2742 * Event handler for a folder icon click.
2743 *
2744 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2745 */
2746 protected void onClickFolderIcon(View v) {
2747 if (LOGD) Log.d(TAG, "onClickFolder");
2748 if (!(v instanceof FolderIcon)){
2749 throw new IllegalArgumentException("Input must be a FolderIcon");
2750 }
2751
2752 FolderIcon folderIcon = (FolderIcon) v;
2753 final FolderInfo info = folderIcon.getFolderInfo();
2754 Folder openFolder = mWorkspace.getFolderForTag(info);
2755
2756 // If the folder info reports that the associated folder is open, then verify that
2757 // it is actually opened. There have been a few instances where this gets out of sync.
2758 if (info.opened && openFolder == null) {
2759 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2760 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2761 info.opened = false;
2762 }
2763
2764 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2765 // Close any open folder
2766 closeFolder();
2767 // Open the requested folder
2768 openFolder(folderIcon);
2769 } else {
2770 // Find the open folder...
2771 int folderScreen;
2772 if (openFolder != null) {
2773 folderScreen = mWorkspace.getPageForView(openFolder);
2774 // .. and close it
2775 closeFolder(openFolder);
2776 if (folderScreen != mWorkspace.getCurrentPage()) {
2777 // Close any folder open on the current screen
2778 closeFolder();
2779 // Pull the folder onto this screen
2780 openFolder(folderIcon);
2781 }
2782 }
2783 }
Adam Cohen9211d422014-10-07 18:14:53 -07002784
2785 if (mLauncherCallbacks != null) {
2786 mLauncherCallbacks.onClickFolderIcon(v);
2787 }
Michael Jurka5130e402011-10-13 04:55:35 -07002788 }
2789
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002790 /**
2791 * Event handler for the (Add) Widgets button that appears after a long press
2792 * on the home screen.
2793 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002794 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002795 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002796 if (mIsSafeModeEnabled) {
2797 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2798 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002799 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002800 if (mLauncherCallbacks != null) {
2801 mLauncherCallbacks.onClickAddWidgetButton(view);
2802 }
Adam Cohen9211d422014-10-07 18:14:53 -07002803 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002804 }
2805
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002806 /**
2807 * Event handler for the wallpaper picker button that appears after a long press
2808 * on the home screen.
2809 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002810 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002811 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002812 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName()),
2813 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002814
2815 if (mLauncherCallbacks != null) {
2816 mLauncherCallbacks.onClickWallpaperPicker(v);
2817 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002818 }
2819
2820 /**
2821 * Event handler for a click on the settings button that appears after a long press
2822 * on the home screen.
2823 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002824 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002825 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002826 if (mLauncherCallbacks != null) {
2827 mLauncherCallbacks.onClickSettingsButton(v);
2828 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002829 }
2830
Michael Jurka5130e402011-10-13 04:55:35 -07002831 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002832 // Provide the same haptic feedback that the system offers for virtual keys.
2833 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002834 }
2835
Adam Cohen61f560d2013-09-30 15:58:20 -07002836 public void performHapticFeedbackOnTouchDown(View v) {
2837 // Provide the same haptic feedback that the system offers for virtual keys.
2838 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2839 }
2840
2841 public View.OnTouchListener getHapticFeedbackTouchListener() {
2842 if (mHapticFeedbackTouchListener == null) {
2843 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002844 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002845 @Override
2846 public boolean onTouch(View v, MotionEvent event) {
2847 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2848 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2849 }
2850 return false;
2851 }
2852 };
2853 }
2854 return mHapticFeedbackTouchListener;
2855 }
2856
Adam Cohen9211d422014-10-07 18:14:53 -07002857 public void onDragStarted(View view) {
2858 if (isOnCustomContent()) {
2859 // Custom content screen doesn't participate in drag and drop. If on custom
2860 // content screen, move to default.
2861 moveWorkspaceToDefaultScreen();
2862 }
2863
2864 if (mLauncherCallbacks != null) {
2865 mLauncherCallbacks.onDragStarted(view);
2866 }
2867 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002868
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002869 /**
2870 * Called when the user stops interacting with the launcher.
2871 * This implies that the user is now on the homescreen and is not doing housekeeping.
2872 */
Adam Cohen9211d422014-10-07 18:14:53 -07002873 protected void onInteractionEnd() {
2874 if (mLauncherCallbacks != null) {
2875 mLauncherCallbacks.onInteractionEnd();
2876 }
2877 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002878
2879 /**
2880 * Called when the user starts interacting with the launcher.
2881 * The possible interactions are:
2882 * - open all apps
2883 * - reorder an app shortcut, or a widget
2884 * - open the overview mode.
2885 * This is a good time to stop doing things that only make sense
2886 * when the user is on the homescreen and not doing housekeeping.
2887 */
Adam Cohen9211d422014-10-07 18:14:53 -07002888 protected void onInteractionBegin() {
2889 if (mLauncherCallbacks != null) {
2890 mLauncherCallbacks.onInteractionBegin();
2891 }
2892 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002893
Winson Chungcd99cd32015-04-29 11:03:24 -07002894 /** Updates the interaction state. */
2895 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002896 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002897 // overlay
Winson Chung83f59ab2015-05-05 17:21:58 -07002898 boolean fromStateWithOverlay;
2899 boolean toStateWithOverlay;
2900 if (Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
2901 fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2902 toStateWithOverlay = toState != Workspace.State.NORMAL;
2903 } else {
2904 fromStateWithOverlay = fromState != Workspace.State.NORMAL &&
2905 fromState != Workspace.State.NORMAL_HIDDEN;
2906 toStateWithOverlay = toState != Workspace.State.NORMAL &&
2907 toState != Workspace.State.NORMAL_HIDDEN;
2908 }
2909 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002910 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002911 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002912 onInteractionEnd();
2913 }
2914 }
2915
Kenny Guyf07af7b2014-07-31 11:39:16 +01002916 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002917 try {
2918 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002919 launcherApps.showAppDetailsForProfile(componentName, user);
2920 } catch (SecurityException e) {
2921 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2922 Log.e(TAG, "Launcher does not have permission to launch settings");
2923 } catch (ActivityNotFoundException e) {
2924 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2925 Log.e(TAG, "Unable to launch settings");
2926 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002927 }
2928
Michael Jurka1e2f4652013-07-08 18:03:46 -07002929 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002930 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2931 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002932 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002933 // System applications cannot be installed. For now, show a toast explaining that.
2934 // We may give them the option of disabling apps this way.
2935 int messageId = R.string.uninstall_system_app_text;
2936 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002937 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002938 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002939 String packageName = componentName.getPackageName();
2940 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002941 Intent intent = new Intent(
2942 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002943 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2944 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002945 if (user != null) {
2946 user.addToIntent(intent, Intent.EXTRA_USER);
2947 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002948 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002949 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002950 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002951 }
2952
Michael Jurka86a720e2012-05-09 11:23:23 -07002953 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002954 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002955 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002956 // Only launch using the new animation if the shortcut has not opted out (this is a
2957 // private contract between launcher and may be ignored in the future).
2958 boolean useLaunchAnimation = (v != null) &&
2959 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002960 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2961 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002962
Kenny Guy1317e2d2014-05-08 18:52:50 +01002963 UserHandleCompat user = null;
2964 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2965 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2966 user = userManager.getUserForSerialNumber(serialNumber);
2967 }
2968
2969 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002970 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002971 ActivityOptions opts = null;
2972 if (sClipRevealMethod != null) {
2973 // TODO: call method directly when Launcher3 can depend on M APIs
2974 int left = 0, top = 0;
2975 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2976 if (v instanceof TextView) {
2977 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002978 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2979 if (icon != null) {
2980 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002981 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002982 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002983 width = bounds.width();
2984 height = bounds.height();
2985 }
2986 }
2987 try {
2988 opts = (ActivityOptions) sClipRevealMethod.invoke(null, v,
2989 left, top, width, height);
2990 } catch (IllegalAccessException e) {
2991 Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
2992 sClipRevealMethod = null;
2993 } catch (InvocationTargetException e) {
2994 Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
2995 sClipRevealMethod = null;
2996 }
2997 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002998 if (opts == null && !Utilities.isLmpOrAbove()) {
2999 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08003000 v.getMeasuredWidth(), v.getMeasuredHeight());
3001 }
Adam Cohen2e52c902015-04-06 13:11:28 -07003002 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07003003 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01003004
3005 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
3006 // Could be launching some bookkeeping activity
3007 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07003008 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07003009 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01003010 launcherApps.startActivityForProfile(intent.getComponent(), user,
3011 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07003012 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08003013 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003014 } catch (SecurityException e) {
3015 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08003016 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003017 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07003018 "or use the exported attribute for this activity. "
3019 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003020 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08003021 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003022 }
Winson Chungaafa03c2010-06-11 17:34:16 -07003023
Michael Jurka86a720e2012-05-09 11:23:23 -07003024 boolean startActivitySafely(View v, Intent intent, Object tag) {
3025 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07003026 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
3027 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
3028 return false;
3029 }
Michael Jurka86a720e2012-05-09 11:23:23 -07003030 try {
3031 success = startActivity(v, intent, tag);
3032 } catch (ActivityNotFoundException e) {
3033 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
3034 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
3035 }
3036 return success;
3037 }
3038
Adam Cohen268c4752012-06-06 17:47:33 -07003039 /**
3040 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
3041 * in the DragLayer in the exact absolute location of the original FolderIcon.
3042 */
3043 private void copyFolderIconToImage(FolderIcon fi) {
3044 final int width = fi.getMeasuredWidth();
3045 final int height = fi.getMeasuredHeight();
3046
3047 // Lazy load ImageView, Bitmap and Canvas
3048 if (mFolderIconImageView == null) {
3049 mFolderIconImageView = new ImageView(this);
3050 }
3051 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3052 mFolderIconBitmap.getHeight() != height) {
3053 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3054 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3055 }
3056
3057 DragLayer.LayoutParams lp;
3058 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3059 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3060 } else {
3061 lp = new DragLayer.LayoutParams(width, height);
3062 }
3063
Adam Cohen307fe232012-08-16 17:55:58 -07003064 // The layout from which the folder is being opened may be scaled, adjust the starting
3065 // view size by this scale factor.
3066 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003067 lp.customPosition = true;
3068 lp.x = mRectForFolderAnimation.left;
3069 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003070 lp.width = (int) (scale * width);
3071 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003072
3073 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3074 fi.draw(mFolderIconCanvas);
3075 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003076 if (fi.getFolder() != null) {
3077 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3078 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003079 }
Adam Cohen268c4752012-06-06 17:47:33 -07003080 // Just in case this image view is still in the drag layer from a previous animation,
3081 // we remove it and re-add it.
3082 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3083 mDragLayer.removeView(mFolderIconImageView);
3084 }
3085 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003086 if (fi.getFolder() != null) {
3087 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003088 }
Adam Cohen268c4752012-06-06 17:47:33 -07003089 }
3090
Adam Cohen2801caf2011-05-13 20:57:39 -07003091 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003092 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003093 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
3094 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
3095 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
3096
Adam Cohenc51934b2011-07-26 21:07:43 -07003097 FolderInfo info = (FolderInfo) fi.getTag();
3098 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3099 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003100 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3101 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003102 }
3103
Adam Cohen268c4752012-06-06 17:47:33 -07003104 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3105 copyFolderIconToImage(fi);
3106 fi.setVisibility(View.INVISIBLE);
3107
Michael Jurka2ecf9952012-06-18 12:52:28 -07003108 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003109 scaleX, scaleY);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003110 if (Utilities.isLmpOrAbove()) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003111 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3112 }
3113 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003114 oa.start();
3115 }
3116
Adam Cohen268c4752012-06-06 17:47:33 -07003117 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003118 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003119 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3120 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3121 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3122
Adam Cohen268c4752012-06-06 17:47:33 -07003123 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003124
Adam Cohen268c4752012-06-06 17:47:33 -07003125 // We remove and re-draw the FolderIcon in-case it has changed
3126 mDragLayer.removeView(mFolderIconImageView);
3127 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003128 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003129 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003130 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003131 oa.addListener(new AnimatorListenerAdapter() {
3132 @Override
3133 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003134 if (cl != null) {
3135 cl.clearFolderLeaveBehind();
3136 // Remove the ImageView copy of the FolderIcon and make the original visible.
3137 mDragLayer.removeView(mFolderIconImageView);
3138 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003139 }
3140 }
3141 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003142 oa.start();
3143 }
3144
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003145 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003146 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003147 * is animated relative to the specified View. If the View is null, no animation
3148 * is played.
3149 *
3150 * @param folderInfo The FolderInfo describing the folder to open.
3151 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003152 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003153 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003154 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3155 if (openFolder != null && openFolder != folder) {
3156 // Close any open folder before opening a folder.
3157 closeFolder();
3158 }
3159
Adam Cohena9cf38f2011-05-02 15:36:58 -07003160 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003161
Adam Cohena9cf38f2011-05-02 15:36:58 -07003162 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003163
Sunny Goyalf4066152015-04-15 09:42:19 -07003164 // While the folder is open, the position of the icon cannot change.
3165 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3166
Adam Cohen4554ee12011-08-03 16:13:21 -07003167 // Just verify that the folder hasn't already been added to the DragLayer.
3168 // There was a one-off crash where the folder had a parent already.
3169 if (folder.getParent() == null) {
3170 mDragLayer.addView(folder);
3171 mDragController.addDropTarget((DropTarget) folder);
3172 } else {
3173 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3174 folder.getParent() + ").");
3175 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003176 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003177 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003178
3179 // Notify the accessibility manager that this folder "window" has appeared and occluded
3180 // the workspace items
3181 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3182 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003183 }
3184
3185 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003186 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003187 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003188 if (folder.isEditingName()) {
3189 folder.dismissEditingName();
3190 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003191 closeFolder(folder);
3192 }
3193 }
3194
Sunny Goyal83a8f042015-05-19 12:52:12 -07003195 public void closeFolder(Folder folder) {
Adam Cohen4554ee12011-08-03 16:13:21 -07003196 folder.getInfo().opened = false;
3197
3198 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3199 if (parent != null) {
3200 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3201 shrinkAndFadeInFolderIcon(fi);
Sunny Goyalf4066152015-04-15 09:42:19 -07003202 if (fi != null) {
3203 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3204 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003205 }
3206 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003207
3208 // Notify the accessibility manager that this folder "window" has disappeard and no
3209 // longer occludeds the workspace items
3210 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003211 }
3212
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003213 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003214 if (!isDraggingEnabled()) return false;
3215 if (isWorkspaceLocked()) return false;
3216 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003217
Adam Cohen1697b792013-09-17 19:08:21 -07003218 if (v instanceof Workspace) {
3219 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003220 if (!mWorkspace.isTouchActive()) {
3221 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003222 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3223 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3224 return true;
3225 } else {
3226 return false;
3227 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003228 } else {
3229 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003230 }
Adam Cohen1697b792013-09-17 19:08:21 -07003231 }
3232
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003233 CellLayout.CellInfo longClickCellInfo = null;
3234 View itemUnderLongClick = null;
3235 if (v.getTag() instanceof ItemInfo) {
3236 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003237 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003238 itemUnderLongClick = longClickCellInfo.cell;
3239 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003240 }
3241
Winson Chung3d503fb2011-07-13 17:25:49 -07003242 // The hotseat touch handling does not go through Workspace, and we always allow long press
3243 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003244 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003245 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003246 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003247 // User long pressed on empty space
3248 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3249 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003250 if (mWorkspace.isInOverviewMode()) {
3251 mWorkspace.startReordering(v);
3252 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003253 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003254 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003255 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003256 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3257 mHotseat.getOrderInHotseat(
3258 longClickCellInfo.cellX,
3259 longClickCellInfo.cellY));
3260 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003261 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003262 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003263 }
3264 }
3265 }
3266 return true;
3267 }
3268
Winson Chung3d503fb2011-07-13 17:25:49 -07003269 boolean isHotseatLayout(View layout) {
3270 return mHotseat != null && layout != null &&
3271 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3272 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003273
Winson Chung3d503fb2011-07-13 17:25:49 -07003274 /**
3275 * Returns the CellLayout of the specified container at the specified screen.
3276 */
Sunny Goyal92820592015-03-02 11:31:35 -08003277 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003278 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3279 if (mHotseat != null) {
3280 return mHotseat.getLayout();
3281 } else {
3282 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003283 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003284 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003285 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003286 }
3287 }
3288
Winson Chungb745afb2015-03-02 11:51:23 -08003289 /**
3290 * For overridden classes.
3291 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003292 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003293 return isAppsViewVisible();
3294 }
3295
3296 public boolean isAppsViewVisible() {
3297 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3298 }
3299
3300 public boolean isWidgetsViewVisible() {
3301 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003302 }
3303
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003304 private void setWorkspaceBackground(int background) {
3305 switch (background) {
3306 case WORKSPACE_BACKGROUND_TRANSPARENT:
3307 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3308 break;
3309 case WORKSPACE_BACKGROUND_BLACK:
3310 getWindow().setBackgroundDrawable(null);
3311 break;
3312 default:
3313 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3314 }
Craig Mautner360310b2012-10-26 15:13:08 -07003315 }
3316
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003317 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003318 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3319 int curflags = getWindow().getAttributes().flags
3320 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3321 if (wpflags != curflags) {
3322 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3323 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003324 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003325 }
3326
Michael Jurkae326f182011-11-21 14:05:46 -08003327 @Override
3328 public void onTrimMemory(int level) {
3329 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003330 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3331 // The widget preview db can result in holding onto over
3332 // 3MB of memory for caching which isn't necessary.
3333 SQLiteDatabase.releaseMemory();
3334
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003335 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003336 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003337 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003338 if (mLauncherCallbacks != null) {
3339 mLauncherCallbacks.onTrimMemory(level);
3340 }
Michael Jurkae326f182011-11-21 14:05:46 -08003341 }
3342
Winson Chungb745afb2015-03-02 11:51:23 -08003343 @Override
3344 public void onStateTransitionHideSearchBar() {
3345 // Hide the search bar
3346 if (mSearchDropTargetBar != null) {
3347 mSearchDropTargetBar.hideSearchBar(false /* animated */);
3348 }
Adam Cohened66b2b2012-01-23 17:28:51 -08003349 }
3350
Winson Chungb745afb2015-03-02 11:51:23 -08003351 protected void showWorkspace(boolean animated) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003352 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated, null,
3353 true);
Adam Cohened307df2013-10-02 09:37:31 -07003354 }
3355
Sunny Goyal83a8f042015-05-19 12:52:12 -07003356 public void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003357 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
3358 onCompleteRunnable, true);
3359 }
3360
3361 protected void showWorkspace(int snapToPage, boolean animated) {
3362 showWorkspace(snapToPage, animated, null, true);
3363 }
3364
3365 void showWorkspace(int snapToPage, boolean animated, Runnable onCompleteRunnable,
3366 boolean notifyLauncherCallbacks) {
Winson Chung0f785722015-04-08 10:27:49 -07003367 boolean changed = mState != State.WORKSPACE ||
3368 mWorkspace.getState() != Workspace.State.NORMAL;
3369 if (changed) {
Winson Chung2d75f122013-09-23 16:53:31 -07003370 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003371 mWorkspace.setVisibility(View.VISIBLE);
Winson Chungb745afb2015-03-02 11:51:23 -08003372 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.NORMAL,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003373 snapToPage, animated, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003374
Winson Chungc7d2b602012-05-16 17:02:20 -07003375 // Show the search bar (only animate if we were showing the drop target bar in spring
3376 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003377 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003378 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003379 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003380
Michael Jurkab3e22d92011-10-31 15:58:33 -07003381 // Set focus to the AppsCustomize button
3382 if (mAllAppsButton != null) {
3383 mAllAppsButton.requestFocus();
3384 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003385 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003386
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003387 // Change the state *after* we've called all the transition code
3388 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003389
Winson Chung5fb63472011-02-02 17:03:37 -08003390 // Resume the auto-advance of widgets
3391 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003392 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003393
Winson Chung0f785722015-04-08 10:27:49 -07003394 if (changed) {
3395 // Send an accessibility event to announce the context change
3396 getWindow().getDecorView()
3397 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chungcd99cd32015-04-29 11:03:24 -07003398 if (notifyLauncherCallbacks) {
3399 // Dismiss all apps when the workspace is shown
Winson Chung83f59ab2015-05-05 17:21:58 -07003400 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003401 mLauncherCallbacks.onAllAppsHidden();
3402 }
3403 }
Winson Chung0f785722015-04-08 10:27:49 -07003404 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01003405 }
3406
Adam Cohened307df2013-10-02 09:37:31 -07003407 void showOverviewMode(boolean animated) {
3408 mWorkspace.setVisibility(View.VISIBLE);
Winson Chungb745afb2015-03-02 11:51:23 -08003409 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.OVERVIEW,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003410 WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
3411 null /* onCompleteRunnable */);
Adam Cohened307df2013-10-02 09:37:31 -07003412 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003413 }
3414
Winson Chungb745afb2015-03-02 11:51:23 -08003415 /**
3416 * Shows the apps view.
3417 */
Winson Chung4ac30062015-05-08 17:34:17 -07003418 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps) {
Winson Chungb745afb2015-03-02 11:51:23 -08003419 if (resetListToTop) {
3420 mAppsView.scrollToTop();
3421 }
Winson Chung4ac30062015-05-08 17:34:17 -07003422 if (updatePredictedApps) {
3423 tryAndUpdatePredictedApps();
3424 }
Winson Chungb745afb2015-03-02 11:51:23 -08003425 showAppsOrWidgets(animated, State.APPS);
3426 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003427
Winson Chungb745afb2015-03-02 11:51:23 -08003428 /**
3429 * Shows the widgets view.
3430 */
3431 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003432 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003433 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003434 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003435 }
Winson Chungb745afb2015-03-02 11:51:23 -08003436 showAppsOrWidgets(animated, State.WIDGETS);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003437
3438 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003439 @Override
3440 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003441 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003442 }
3443 });
Winson Chungb745afb2015-03-02 11:51:23 -08003444 }
3445
3446 /**
3447 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003448 *
3449 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003450 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003451 // TODO: calling method should use the return value so that when {@code false} is returned
3452 // the workspace transition doesn't fall into invalid state.
3453 private boolean showAppsOrWidgets(boolean animated, State toState) {
3454 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3455 mState != State.WIDGETS_SPRING_LOADED) {
3456 return false;
3457 }
3458 if (toState != State.APPS && toState != State.WIDGETS) {
3459 return false;
3460 }
Winson Chungb745afb2015-03-02 11:51:23 -08003461
3462 if (toState == State.APPS) {
3463 mStateTransitionAnimation.startAnimationToAllApps(animated);
Winson Chung83f59ab2015-05-05 17:21:58 -07003464 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chung0f785722015-04-08 10:27:49 -07003465 mLauncherCallbacks.onAllAppsShown();
3466 }
Winson Chungb745afb2015-03-02 11:51:23 -08003467 } else {
3468 mStateTransitionAnimation.startAnimationToWidgets(animated);
3469 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003470
Michael Jurkab3e22d92011-10-31 15:58:33 -07003471 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003472 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003473
3474 // Pause the auto-advance of widgets until we are out of AllApps
3475 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003476 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003477 closeFolder();
3478
3479 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003480 getWindow().getDecorView()
3481 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003482 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003483 }
3484
Winson Chungcd99cd32015-04-29 11:03:24 -07003485 /**
3486 * Updates the workspace and interaction state on state change, and return the animation to this
3487 * new state.
3488 */
3489 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState, int toPage,
3490 boolean animated, HashMap<View, Integer> layerViews) {
3491 Workspace.State fromState = mWorkspace.getState();
3492 Animator anim = mWorkspace.setStateWithAnimation(toState, toPage, animated, layerViews);
3493 updateInteraction(fromState, toState);
3494 return anim;
3495 }
3496
Hyunyoung Song3f471442015-04-08 19:01:34 -07003497 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003498 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Winson Chungb745afb2015-03-02 11:51:23 -08003499 if (mState == State.WORKSPACE || mState == State.APPS_SPRING_LOADED ||
3500 mState == State.WIDGETS_SPRING_LOADED) {
3501 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003502 }
Winson Chungb745afb2015-03-02 11:51:23 -08003503
3504 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.SPRING_LOADED,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003505 WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true /* animated */,
3506 null /* onCompleteRunnable */);
Winson Chungb745afb2015-03-02 11:51:23 -08003507 mState = isAppsViewVisible() ? State.APPS_SPRING_LOADED : State.WIDGETS_SPRING_LOADED;
Michael Jurkad3ef3062010-11-23 16:23:58 -08003508 }
Adam Cohen7777d962011-08-18 18:58:38 -07003509
Hyunyoung Song3f471442015-04-08 19:01:34 -07003510 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003511 final Runnable onCompleteRunnable) {
Winson Chungb745afb2015-03-02 11:51:23 -08003512 if (mState != State.APPS_SPRING_LOADED && mState != State.WIDGETS_SPRING_LOADED) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003513
Winson Chungcd99cd32015-04-29 11:03:24 -07003514 if (successfulDrop) {
3515 // We need to trigger all apps hidden to notify search to update itself before the
3516 // delayed call to showWorkspace below
Winson Chung83f59ab2015-05-05 17:21:58 -07003517 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003518 mLauncherCallbacks.onAllAppsHidden();
3519 }
3520 }
3521
Winson Chunge7a03942011-08-05 15:05:12 -07003522 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003523 @Override
3524 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003525 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003526 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3527 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003528 // Before we show workspace, hide all apps again because
3529 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3530 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003531 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003532 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003533 } else {
3534 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003535 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003536 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003537 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003538 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003539
Michael Jurkad3ef3062010-11-23 16:23:58 -08003540 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003541 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003542 showAppsView(true /* animated */, false /* resetListToTop */,
3543 false /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08003544 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003545 showWidgetsView(true, false);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003546 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003547 }
3548
Winson Chung4ac30062015-05-08 17:34:17 -07003549 /**
3550 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3551 * resumed.
3552 */
3553 private void tryAndUpdatePredictedApps() {
3554 if (mLauncherCallbacks != null) {
3555 List<ComponentName> apps = mLauncherCallbacks.getPredictedApps();
3556 if (!apps.isEmpty()) {
3557 mAppsView.setPredictedApps(apps);
3558 }
3559 }
3560 }
3561
Michael Jurkab3e22d92011-10-31 15:58:33 -07003562 void lockAllApps() {
3563 // TODO
3564 }
3565
3566 void unlockAllApps() {
3567 // TODO
3568 }
3569
Sunny Goyal594d76d2014-11-06 10:12:54 -08003570 protected void disableVoiceButtonProxy(boolean disable) {
3571 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003572 }
3573
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003574 public View getOrCreateQsbBar() {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003575 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
3576 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003577 }
3578
Adam Cohen24ce0b32014-01-14 16:18:14 -08003579 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003580 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3581 if (searchProvider == null) {
3582 return null;
3583 }
3584
3585 Bundle opts = new Bundle();
3586 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003587 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003588
3589 SharedPreferences sp = getSharedPreferences(
3590 LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
3591 int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003592 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003593 if (!searchProvider.provider.flattenToString().equals(
3594 sp.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003595 || (widgetInfo == null)
3596 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003597 // A valid widget is not already bound.
3598 if (widgetId > -1) {
3599 mAppWidgetHost.deleteAppWidgetId(widgetId);
3600 widgetId = -1;
3601 }
3602
3603 // Try to bind a new widget
3604 widgetId = mAppWidgetHost.allocateAppWidgetId();
3605
3606 if (!AppWidgetManagerCompat.getInstance(this)
3607 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3608 mAppWidgetHost.deleteAppWidgetId(widgetId);
3609 widgetId = -1;
3610 }
3611
3612 sp.edit()
3613 .putInt(QSB_WIDGET_ID, widgetId)
3614 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
3615 .commit();
3616 }
3617
3618 if (widgetId != -1) {
3619 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
3620 mQsb.updateAppWidgetOptions(opts);
3621 mQsb.setPadding(0, 0, 0, 0);
3622 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003623 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003624 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003625 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003626 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003627 }
3628
Sunny Goyal22235bc2015-04-03 09:23:43 -07003629 private void reinflateQSBIfNecessary() {
3630 if (mQsb instanceof LauncherAppWidgetHostView &&
3631 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3632 mSearchDropTargetBar.removeView(mQsb);
3633 mQsb = null;
3634 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3635 }
3636 }
3637
Michael Jurkad7c28052012-04-27 15:43:36 -07003638 @Override
3639 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003640 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003641 final List<CharSequence> text = event.getText();
3642 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003643 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003644 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003645 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003646 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003647 text.add(getString(R.string.widget_button_text));
alanv1d4fde62012-10-17 13:15:47 -07003648 } else {
3649 text.add(getString(R.string.all_apps_home_button_label));
3650 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003651 return result;
3652 }
3653
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003654 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003655 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003656 */
Adam Cohen091440a2015-03-18 14:16:05 -07003657 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003658 @Override
3659 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003660 closeSystemDialogs();
3661 }
3662 }
3663
3664 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003665 * Receives notifications whenever the appwidgets are reset.
3666 */
3667 private class AppWidgetResetObserver extends ContentObserver {
3668 public AppWidgetResetObserver() {
3669 super(new Handler());
3670 }
3671
3672 @Override
3673 public void onChange(boolean selfChange) {
3674 onAppWidgetReset();
3675 }
3676 }
3677
3678 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003679 * If the activity is currently paused, signal that we need to run the passed Runnable
3680 * in onResume.
3681 *
3682 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003683 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3684 * wrong when we're not running, and if the activity comes back to what the configuration was
3685 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003686 *
3687 * Implementation of the method from LauncherModel.Callbacks.
3688 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003689 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003690 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003691 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003692 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003693 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003694 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003695 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003696 }
3697 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003698 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003699 return true;
3700 } else {
3701 return false;
3702 }
3703 }
3704
Michael Jurkac402cd92013-05-20 15:49:32 +02003705 private boolean waitUntilResume(Runnable run) {
3706 return waitUntilResume(run, false);
3707 }
3708
Michael Jurka1e2f4652013-07-08 18:03:46 -07003709 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003710 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003711 }
3712
Michael Jurka7607c2f2013-04-03 14:33:19 -07003713 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003714 * If the activity is currently paused, signal that we need to re-run the loader
3715 * in onResume.
3716 *
3717 * This needs to be called from incoming places where resources might have been loaded
3718 * while we are paused. That is becaues the Configuration might be wrong
3719 * when we're not running, and if it comes back to what it was when we
3720 * were paused, we are not restarted.
3721 *
3722 * Implementation of the method from LauncherModel.Callbacks.
3723 *
3724 * @return true if we are currently paused. The caller might be able to
3725 * skip some work in that case since we will come back again.
3726 */
3727 public boolean setLoadOnResume() {
3728 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003729 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003730 mOnResumeNeedsLoad = true;
3731 return true;
3732 } else {
3733 return false;
3734 }
3735 }
3736
3737 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003738 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003739 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003740 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003741 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003742 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003743 } else {
3744 return SCREEN_COUNT / 2;
3745 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003746 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003747
Joe Onorato9c1289c2009-08-17 11:03:03 -04003748 /**
3749 * Refreshes the shortcuts shown on the workspace.
3750 *
3751 * Implementation of the method from LauncherModel.Callbacks.
3752 */
3753 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003754 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003755
Michael Jurka7607c2f2013-04-03 14:33:19 -07003756 // If we're starting binding all over again, clear any bind calls we'd postponed in
3757 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3758 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003759 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003760
Winson Chungd64d1762013-08-20 14:37:16 -07003761 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003762 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003763 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003764
Michael Jurka05bf6442011-11-30 20:28:53 -08003765 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003766 if (mHotseat != null) {
3767 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003768 }
3769 }
3770
Adam Cohendcd297f2013-06-18 13:13:40 -07003771 @Override
3772 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003773 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003774
Adam Cohen5084cba2013-09-03 12:01:16 -07003775 // If there are no screens, we need to have an empty screen
3776 if (orderedScreenIds.size() == 0) {
3777 mWorkspace.addExtraEmptyScreen();
3778 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003779
3780 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003781 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003782 if (hasCustomContentToLeft()) {
3783 mWorkspace.createCustomContentContainer();
3784 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003785 }
Winson Chung64359a52013-07-08 17:17:08 -07003786 }
3787
3788 @Override
3789 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003790 // Log to disk
3791 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3792 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3793 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003794 int count = orderedScreenIds.size();
3795 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003796 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003797 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003798 }
3799
Adam Cohen39a06042013-07-19 14:30:12 -07003800 private boolean shouldShowWeightWatcher() {
3801 String spKey = LauncherAppState.getSharedPreferencesKey();
3802 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003803 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003804
3805 return show;
3806 }
3807
3808 private void toggleShowWeightWatcher() {
3809 String spKey = LauncherAppState.getSharedPreferencesKey();
3810 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3811 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3812
3813 show = !show;
3814
3815 SharedPreferences.Editor editor = sp.edit();
3816 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3817 editor.commit();
3818
3819 if (mWeightWatcher != null) {
3820 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3821 }
3822 }
3823
Winson Chungd64d1762013-08-20 14:37:16 -07003824 public void bindAppsAdded(final ArrayList<Long> newScreens,
3825 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003826 final ArrayList<ItemInfo> addAnimated,
3827 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003828 Runnable r = new Runnable() {
3829 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003830 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003831 }
3832 };
3833 if (waitUntilResume(r)) {
3834 return;
3835 }
3836
Winson Chungd64d1762013-08-20 14:37:16 -07003837 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003838 if (newScreens != null) {
3839 bindAddScreens(newScreens);
3840 }
Winson Chungd64d1762013-08-20 14:37:16 -07003841
3842 // We add the items without animation on non-visible pages, and with
3843 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003844 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003845 bindItems(addNotAnimated, 0,
3846 addNotAnimated.size(), false);
3847 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003848 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003849 bindItems(addAnimated, 0,
3850 addAnimated.size(), true);
3851 }
Winson Chungc58497e2013-09-03 17:48:37 -07003852
Winson Chung87412982013-10-03 18:34:14 -07003853 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003854 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003855
Winson Chungb745afb2015-03-02 11:51:23 -08003856 if (addedApps != null && mAppsView != null) {
3857 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003858 }
Winson Chungd64d1762013-08-20 14:37:16 -07003859 }
3860
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003861 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003862 * Bind the items start-end from the list.
3863 *
3864 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003865 */
Winson Chung64359a52013-07-08 17:17:08 -07003866 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3867 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003868 Runnable r = new Runnable() {
3869 public void run() {
3870 bindItems(shortcuts, start, end, forceAnimateIcons);
3871 }
3872 };
3873 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003874 return;
3875 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003876
Winson Chungf0c6ae02012-03-21 16:10:31 -07003877 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003878 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3879 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003880 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003881 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003882 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003883 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003884 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003885
3886 // Short circuit if we are loading dock items for a configuration which has no dock
3887 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3888 mHotseat == null) {
3889 continue;
3890 }
3891
Joe Onorato9c1289c2009-08-17 11:03:03 -04003892 switch (item.itemType) {
3893 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3894 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003895 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003896 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003897
Winson Chung64359a52013-07-08 17:17:08 -07003898 /*
3899 * TODO: FIX collision case
3900 */
Winson Chungce376632013-07-11 16:12:41 -07003901 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3902 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3903 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003904 View v = cl.getChildAt(item.cellX, item.cellY);
3905 Object tag = v.getTag();
3906 String desc = "Collision while binding workspace item: " + item
3907 + ". Collides with " + tag;
3908 if (LauncherAppState.isDogfoodBuild()) {
3909 throw (new RuntimeException(desc));
3910 } else {
3911 Log.d(TAG, desc);
3912 }
Winson Chungce376632013-07-11 16:12:41 -07003913 }
Winson Chung64359a52013-07-08 17:17:08 -07003914 }
3915
Adam Cohendcd297f2013-06-18 13:13:40 -07003916 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3917 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003918 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003919 // Animate all the applications up now
3920 shortcut.setAlpha(0f);
3921 shortcut.setScaleX(0f);
3922 shortcut.setScaleY(0f);
3923 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003924 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003925 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003926 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003927 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003928 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003929 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003930 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003931 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3932 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003933 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003934 default:
3935 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003936 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003937 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003938
Winson Chung997a9232013-07-24 15:33:46 -07003939 if (animateIcons) {
3940 // Animate to the correct page
3941 if (newShortcutsScreenId > -1) {
3942 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003943 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003944 final Runnable startBounceAnimRunnable = new Runnable() {
3945 public void run() {
3946 anim.playTogether(bounceAnims);
3947 anim.start();
3948 }
3949 };
Winson Chung997a9232013-07-24 15:33:46 -07003950 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003951 // We post the animation slightly delayed to prevent slowdowns
3952 // when we are loading right after we return to launcher.
3953 mWorkspace.postDelayed(new Runnable() {
3954 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003955 if (mWorkspace != null) {
3956 mWorkspace.snapToPage(newScreenIndex);
3957 mWorkspace.postDelayed(startBounceAnimRunnable,
3958 NEW_APPS_ANIMATION_DELAY);
3959 }
Winson Chung94d67682013-09-25 16:29:40 -07003960 }
3961 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003962 } else {
3963 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003964 }
3965 }
Winson Chung64359a52013-07-08 17:17:08 -07003966 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003967 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003968 }
3969
Joe Onorato9c1289c2009-08-17 11:03:03 -04003970 /**
3971 * Implementation of the method from LauncherModel.Callbacks.
3972 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003973 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003974 Runnable r = new Runnable() {
3975 public void run() {
3976 bindFolders(folders);
3977 }
3978 };
3979 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003980 return;
3981 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003982 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003983 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003984
3985 /**
3986 * Add the views for a widget to the workspace.
3987 *
3988 * Implementation of the method from LauncherModel.Callbacks.
3989 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003990 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003991 Runnable r = new Runnable() {
3992 public void run() {
3993 bindAppWidget(item);
3994 }
3995 };
3996 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003997 return;
3998 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003999
Daniel Sandler843e8602010-06-07 14:59:01 -04004000 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4001 if (DEBUG_WIDGETS) {
4002 Log.d(TAG, "bindAppWidget: " + item);
4003 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004004 final Workspace workspace = mWorkspace;
4005
Adam Cohen59400422014-03-05 18:07:04 -08004006 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00004007 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08004008
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004009 if (!mIsSafeModeEnabled
4010 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
4011 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
Sunny Goyalff572272014-07-23 13:58:07 -07004012 if (appWidgetInfo == null) {
4013 if (DEBUG_WIDGETS) {
4014 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4015 + " belongs to component " + item.providerName
4016 + ", as the povider is null");
4017 }
4018 LauncherModel.deleteItemFromDatabase(this, item);
4019 return;
4020 }
4021 // Note: This assumes that the id remap broadcast is received before this step.
4022 // If that is not the case, the id remap will be ignored and user may see the
4023 // click to setup view.
Adam Cohen59400422014-03-05 18:07:04 -08004024 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null);
Sunny Goyalff572272014-07-23 13:58:07 -07004025 pendingInfo.spanX = item.spanX;
4026 pendingInfo.spanY = item.spanY;
4027 pendingInfo.minSpanX = item.minSpanX;
4028 pendingInfo.minSpanY = item.minSpanY;
Hyunyoung Song3f471442015-04-08 19:01:34 -07004029 Bundle options = null;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -07004030 WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004031
Sunny Goyalff572272014-07-23 13:58:07 -07004032 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004033 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4034 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004035
4036 // TODO consider showing a permission dialog when the widget is clicked.
4037 if (!success) {
4038 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4039 if (DEBUG_WIDGETS) {
4040 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4041 + " belongs to component " + item.providerName
4042 + ", as the launcher is unable to bing a new widget id");
4043 }
4044 LauncherModel.deleteItemFromDatabase(this, item);
4045 return;
4046 }
4047
4048 item.appWidgetId = newWidgetId;
4049
4050 // If the widget has a configure activity, it is still needs to set it up, otherwise
4051 // the widget is ready to go.
4052 item.restoreStatus = (appWidgetInfo.configure == null)
4053 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4054 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4055
4056 LauncherModel.updateItemInDatabase(this, item);
4057 }
4058
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004059 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004060 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004061 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004062 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4063 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004064 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004065
Sunny Goyal651077b2014-06-30 14:15:31 -07004066 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4067 } else {
4068 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004069 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4070 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004071 view.updateIcon(mIconCache);
4072 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004073 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004074 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004075 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004076
Joe Onorato9c1289c2009-08-17 11:03:03 -04004077 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004078 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004079
Adam Cohendcd297f2013-06-18 13:13:40 -07004080 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004081 item.cellY, item.spanX, item.spanY, false);
Adam Cohen59400422014-03-05 18:07:04 -08004082 if (!item.isCustomWidget()) {
4083 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4084 }
Adam Cohended9f8d2010-11-03 13:25:16 -07004085
Joe Onorato9c1289c2009-08-17 11:03:03 -04004086 workspace.requestLayout();
4087
Daniel Sandler843e8602010-06-07 14:59:01 -04004088 if (DEBUG_WIDGETS) {
4089 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4090 + (SystemClock.uptimeMillis()-start) + "ms");
4091 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004092 }
4093
Sunny Goyalff572272014-07-23 13:58:07 -07004094 /**
4095 * Restores a pending widget.
4096 *
4097 * @param appWidgetId The app widget id
4098 * @param cellInfo The position on screen where to create the widget.
4099 */
4100 private void completeRestoreAppWidget(final int appWidgetId) {
4101 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4102 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4103 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4104 return;
4105 }
4106
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004107 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004108 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4109
4110 mWorkspace.reinflateWidgetsIfNecessary();
4111 LauncherModel.updateItemInDatabase(this, info);
4112 }
4113
Adam Cohen1462de32012-07-24 22:34:36 -07004114 public void onPageBoundSynchronously(int page) {
4115 mSynchronouslyBoundPages.add(page);
4116 }
4117
Joe Onorato9c1289c2009-08-17 11:03:03 -04004118 /**
4119 * Callback saying that there aren't any more items to bind.
4120 *
4121 * Implementation of the method from LauncherModel.Callbacks.
4122 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004123 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004124 Runnable r = new Runnable() {
4125 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004126 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004127 }
4128 };
4129 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004130 return;
4131 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004132 if (mSavedState != null) {
4133 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004134 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004135 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004136 mSavedState = null;
4137 }
4138
Adam Cohen1462de32012-07-24 22:34:36 -07004139 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004140
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004141 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004142 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004143
4144 // If we received the result of any pending adds while the loader was running (e.g. the
4145 // widget configuration forced an orientation change), process them now.
4146 if (sPendingAddItem != null) {
4147 final long screenId = completeAdd(sPendingAddItem);
4148
4149 // TODO: this moves the user to the page where the pending item was added. Ideally,
4150 // the screen would be guaranteed to exist after bind, and the page would be set through
4151 // the workspace restore process.
4152 mWorkspace.post(new Runnable() {
4153 @Override
4154 public void run() {
4155 mWorkspace.snapToScreenId(screenId);
4156 }
4157 });
4158 sPendingAddItem = null;
4159 }
4160
Sunny Goyal756adbc2015-04-16 15:20:51 -07004161 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004162
4163 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004164 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004165 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004166 }
4167
Adam Cohen3ed316a2014-07-23 18:21:20 -07004168 private void sendLoadingCompleteBroadcastIfNecessary() {
4169 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4170 String permission =
4171 getResources().getString(R.string.receive_first_load_broadcast_permission);
4172 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4173 sendBroadcast(intent, permission);
4174 SharedPreferences.Editor editor = mSharedPrefs.edit();
4175 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4176 editor.apply();
4177 }
4178 }
4179
Winson Chunga0b7e862013-09-05 16:03:15 -07004180 public boolean isAllAppsButtonRank(int rank) {
4181 if (mHotseat != null) {
4182 return mHotseat.isAllAppsButtonRank(rank);
4183 }
4184 return false;
4185 }
4186
Winson Chunga2413752012-04-03 14:22:34 -07004187 private boolean canRunNewAppsAnimation() {
4188 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4189 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4190 }
4191
Winson Chungc9168342013-06-26 14:54:55 -07004192 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4193 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4194 PropertyValuesHolder.ofFloat("alpha", 1f),
4195 PropertyValuesHolder.ofFloat("scaleX", 1f),
4196 PropertyValuesHolder.ofFloat("scaleY", 1f));
4197 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4198 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4199 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4200 return bounceAnim;
4201 }
4202
Adam Cohen27772732013-11-11 14:00:56 +00004203 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004204 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004205 }
4206
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004207 protected Rect getSearchBarBounds() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004208 return mDeviceProfile.getSearchBarBounds();
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004209 }
4210
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004211 public void bindSearchablesChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004212 if (mSearchDropTargetBar == null) {
4213 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004214 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004215 if (mQsb != null) {
4216 mSearchDropTargetBar.removeView(mQsb);
4217 mQsb = null;
4218 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004219 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004220 }
4221
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004222 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004223 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4224 * multiple calls to bind the same list.)
4225 */
4226 @Thunk ArrayList<AppInfo> mTmpAppsList;
4227 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4228 public void run() {
4229 bindAllApplications(mTmpAppsList);
4230 mTmpAppsList = null;
4231 }
4232 };
4233
4234 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004235 * Add the icons for all apps.
4236 *
4237 * Implementation of the method from LauncherModel.Callbacks.
4238 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004239 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004240 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4241 mTmpAppsList = apps;
4242 return;
4243 }
4244
Winson Chungb745afb2015-03-02 11:51:23 -08004245 if (mAppsView != null) {
4246 mAppsView.setApps(apps);
4247 }
Adam Cohen9211d422014-10-07 18:14:53 -07004248 if (mLauncherCallbacks != null) {
4249 mLauncherCallbacks.bindAllApplications(apps);
4250 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004251 }
4252
4253 /**
4254 * A package was updated.
4255 *
4256 * Implementation of the method from LauncherModel.Callbacks.
4257 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004258 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004259 Runnable r = new Runnable() {
4260 public void run() {
4261 bindAppsUpdated(apps);
4262 }
4263 };
4264 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004265 return;
4266 }
4267
Winson Chungb745afb2015-03-02 11:51:23 -08004268 if (mAppsView != null) {
4269 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004270 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004271 }
4272
Sunny Goyal4390ace2014-10-13 11:33:11 -07004273 @Override
4274 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4275 Runnable r = new Runnable() {
4276 public void run() {
4277 bindWidgetsRestored(widgets);
4278 }
4279 };
4280 if (waitUntilResume(r)) {
4281 return;
4282 }
4283 mWorkspace.widgetsRestored(widgets);
4284 }
4285
Joe Onorato9c1289c2009-08-17 11:03:03 -04004286 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004287 * Some shortcuts were updated in the background.
4288 *
4289 * Implementation of the method from LauncherModel.Callbacks.
4290 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004291 @Override
4292 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4293 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004294 Runnable r = new Runnable() {
4295 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004296 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004297 }
4298 };
4299 if (waitUntilResume(r)) {
4300 return;
4301 }
4302
Sunny Goyal4390ace2014-10-13 11:33:11 -07004303 if (!updated.isEmpty()) {
4304 mWorkspace.updateShortcuts(updated);
4305 }
4306
4307 if (!removed.isEmpty()) {
4308 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4309 for (ShortcutInfo si : removed) {
4310 removedComponents.add(si.getTargetComponent());
4311 }
4312 mWorkspace.removeItemsByComponentName(removedComponents, user);
4313 // Notify the drag controller
4314 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004315 }
4316 }
4317
4318 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004319 * Update the state of a package, typically related to install state.
4320 *
4321 * Implementation of the method from LauncherModel.Callbacks.
4322 */
Sunny Goyale755d462014-07-22 13:48:29 -07004323 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004324 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4325 Runnable r = new Runnable() {
4326 public void run() {
4327 bindRestoreItemsChange(updates);
4328 }
4329 };
4330 if (waitUntilResume(r)) {
4331 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004332 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004333
Sunny Goyal756adbc2015-04-16 15:20:51 -07004334 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004335 }
4336
4337 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004338 * A package was uninstalled. We take both the super set of packageNames
4339 * in addition to specific applications to remove, the reason being that
4340 * this can be called when a package is updated as well. In that scenario,
4341 * we only remove specific components from the workspace, where as
4342 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004343 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004344 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004345 * Implementation of the method from LauncherModel.Callbacks.
4346 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004347 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004348 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004349 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004350 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004351 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004352 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004353 }
Winson Chungd64d1762013-08-20 14:37:16 -07004354 };
4355 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004356 return;
4357 }
4358
Sunny Goyal1a745e82014-10-02 15:58:31 -07004359 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004360 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4361 for (AppInfo info : appInfos) {
4362 removedComponents.add(info.componentName);
4363 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004364 if (!packageNames.isEmpty()) {
4365 mWorkspace.removeItemsByPackageName(packageNames, user);
4366 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004367 if (!removedComponents.isEmpty()) {
4368 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004369 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004370 // Notify the drag controller
4371 mDragController.onAppsRemoved(packageNames, removedComponents);
4372
Sunny Goyal1a745e82014-10-02 15:58:31 -07004373 } else {
4374 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004375 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004376
Winson Chungdf95eb12013-10-16 14:57:07 -07004377 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004378 if (mAppsView != null) {
4379 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004380 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004381 }
Joe Onoratobe386092009-11-17 17:32:16 -08004382
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 Song2bd3d7d2015-05-21 13:04:53 -07004385 bindAllPackages(mWidgetsModel);
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
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004390 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004391 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004392 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004393 return;
4394 }
4395
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004396 if (mWidgetsView != null && model != null) {
4397 mWidgetsView.addWidgets(model);
4398 mWidgetsModel = 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}