blob: 6dfe0ebea90748bdb7731b040cd9722029c8d800 [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;
Sunny Goyal5a1f53b2015-05-27 10:24:24 -070091import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.Advanceable;
94import android.widget.FrameLayout;
95import android.widget.ImageView;
Chet Haasea8f996d2015-02-17 12:56:04 -080096import android.widget.TextView;
Adam Cohen96d30a12013-07-16 18:13:21 -070097import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -070098
Sunny Goyal651077b2014-06-30 14:15:31 -070099import com.android.launcher3.DropTarget.DragObject;
100import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyal83a8f042015-05-19 12:52:12 -0700101import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700102import com.android.launcher3.allapps.AllAppsContainerView;
Sunny Goyal5683f872015-05-29 14:54:40 -0700103import com.android.launcher3.allapps.AppSearchManager;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700104import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100105import com.android.launcher3.compat.LauncherActivityInfoCompat;
106import com.android.launcher3.compat.LauncherAppsCompat;
107import com.android.launcher3.compat.UserHandleCompat;
108import com.android.launcher3.compat.UserManagerCompat;
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700109import com.android.launcher3.model.WidgetsModel;
Sunny Goyale2df0622015-04-24 11:27:00 -0700110import com.android.launcher3.util.LongArrayMap;
Adam Cohen091440a2015-03-18 14:16:05 -0700111import com.android.launcher3.util.Thunk;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700112import com.android.launcher3.widget.PendingAddWidgetInfo;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -0700113import com.android.launcher3.widget.WidgetHostViewLoader;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700114import com.android.launcher3.widget.WidgetsContainerView;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700115
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700117import java.io.FileDescriptor;
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
Sunny Goyal5a1f53b2015-05-27 10:24:24 -0700165 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
166
Mathew Inwood876a8462013-06-14 14:12:41 +0100167 /**
168 * IntentStarter uses request codes starting with this. This must be greater than all activity
169 * request codes used internally.
170 */
171 protected static final int REQUEST_LAST = 100;
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. */
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700222 enum State { NONE, WORKSPACE, APPS, APPS_SPRING_LOADED, WIDGETS, WIDGETS_SPRING_LOADED }
223
Adam Cohen091440a2015-03-18 14:16:05 -0700224 @Thunk State mState = State.WORKSPACE;
Adam Cohen091440a2015-03-18 14:16:05 -0700225 @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700226
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700227 private boolean mIsSafeModeEnabled;
228
Adam Cohenc2d6e892014-10-16 09:49:24 -0700229 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
230 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700231 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700232
Joe Onorato9c1289c2009-08-17 11:03:03 -0400233 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700234 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
235 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700236 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000238 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
239 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
240
Winson Chunga2413752012-04-03 14:22:34 -0700241 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700242 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
243 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Adam Cohen091440a2015-03-18 14:16:05 -0700244 @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700245
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800246 private final BroadcastReceiver mCloseSystemDialogsReceiver
247 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800248 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
249
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 private LayoutInflater mInflater;
251
Adam Cohen091440a2015-03-18 14:16:05 -0700252 @Thunk Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700253 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800254 private View mPageIndicators;
Adam Cohen091440a2015-03-18 14:16:05 -0700255 @Thunk DragLayer mDragLayer;
Michael Jurkab737ee62011-11-15 15:57:22 -0800256 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700257 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700258
Sunny Goyalffe83f12014-08-14 17:39:34 -0700259 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700261
Adam Cohen091440a2015-03-18 14:16:05 -0700262 @Thunk ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800263 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800264 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700265
Michael Jurka0280c3b2010-09-17 15:00:07 -0700266 private int[] mTmpAddItemCellCoordinates = new int[2];
267
Sunny Goyal316490e2015-06-02 09:38:28 -0700268 @Thunk Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800269 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700270
Michael Jurka838a4ca2011-02-07 13:33:06 -0800271 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700272
Winson Chungc51db6a2011-10-05 11:44:49 -0700273 private SearchDropTargetBar mSearchDropTargetBar;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700274
275 // Main container view for the all apps screen.
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700276 @Thunk AllAppsContainerView mAppsView;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700277
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -0700278 // Main container view and the model for the widget tray screen.
279 @Thunk WidgetsContainerView mWidgetsView;
280 @Thunk WidgetsModel mWidgetsModel;
Hyunyoung Song3f471442015-04-08 19:01:34 -0700281
Winson Chungf0ea4d32011-06-06 14:27:16 -0700282 private boolean mAutoAdvanceRunning = false;
Sunny Goyal594d76d2014-11-06 10:12:54 -0800283 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700286 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
287 // scroll issues (because the workspace may not have been measured yet) and extra work.
288 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
289 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290
291 private SpannableStringBuilder mDefaultKeySsb = null;
292
Adam Cohen091440a2015-03-18 14:16:05 -0700293 @Thunk boolean mWorkspaceLoading = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400294
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800295 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296 private boolean mRestoring;
297 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700298 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800299
Michael Jurka1e2f4652013-07-08 18:03:46 -0700300 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700301 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
302
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800303 private Bundle mSavedInstanceState;
304
Joe Onorato9c1289c2009-08-17 11:03:03 -0400305 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800306 private IconCache mIconCache;
Adam Cohen091440a2015-03-18 14:16:05 -0700307 @Thunk boolean mUserPresent = true;
Adam Cohend113e0c2010-11-11 10:48:05 -0800308 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700309 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800310 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400311
Sunny Goyale2df0622015-04-24 11:27:00 -0700312 private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
Romain Guycbb89e42009-06-08 15:52:54 -0700313
Adam Cohen61f560d2013-09-30 15:58:20 -0700314 private View.OnTouchListener mHapticFeedbackTouchListener;
315
Adam Cohended9f8d2010-11-03 13:25:16 -0700316 // Related to the auto-advancing of widgets
317 private final int ADVANCE_MSG = 1;
318 private final int mAdvanceInterval = 20000;
319 private final int mAdvanceStagger = 250;
320 private long mAutoAdvanceSentTime;
321 private long mAutoAdvanceTimeLeft = -1;
Adam Cohen091440a2015-03-18 14:16:05 -0700322 @Thunk HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
Adam Cohended9f8d2010-11-03 13:25:16 -0700323 new HashMap<View, AppWidgetProviderInfo>();
324
Winson Chung400438b2011-01-16 17:53:48 -0800325 // Determines how long to wait after a rotation before restoring the screen orientation to
326 // match the sensor state.
327 private final int mRestoreScreenOrientationDelay = 500;
328
Adam Cohen091440a2015-03-18 14:16:05 -0700329 @Thunk Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700330
Adam Cohen1462de32012-07-24 22:34:36 -0700331 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700332 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700333
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700334 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700335 static Date sDateStamp = new Date();
336 static DateFormat sDateFormat =
337 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
338 static long sRunStart = System.currentTimeMillis();
339 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700340
Winson Chung46353de2012-02-16 14:05:10 -0800341 // We only want to get the SharedPreferences once since it does an FS stat each time we get
342 // it from the context.
343 private SharedPreferences mSharedPrefs;
344
Winson Chungf0c6ae02012-03-21 16:10:31 -0700345 // Holds the page that we need to animate to, and the icon views that we need to animate up
346 // when we scroll to that page on resume.
Adam Cohen091440a2015-03-18 14:16:05 -0700347 @Thunk ImageView mFolderIconImageView;
Adam Cohen268c4752012-06-06 17:47:33 -0700348 private Bitmap mFolderIconBitmap;
349 private Canvas mFolderIconCanvas;
350 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700351
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700352 private DeviceProfile mDeviceProfile;
353
Winson Chung13eb5272015-05-11 16:30:13 -0700354 // This is set to the view that launched the activity that navigated the user away from
355 // launcher. Since there is no callback for when the activity has finished launching, enable
356 // the press state and keep this reference to reset the press state when we return to launcher.
Michael Jurkaddd62e92011-02-16 17:49:14 -0800357 private BubbleTextView mWaitingForResume;
358
Adam Cohen59400422014-03-05 18:07:04 -0800359 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
360 new HashMap<String, CustomAppWidget>();
361
362 private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
363 static {
364 if (ENABLE_CUSTOM_WIDGET_TEST) {
365 sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
366 }
367 }
368
Chet Haasea8f996d2015-02-17 12:56:04 -0800369 // TODO: remove this field and call method directly when Launcher3 can depend on M APIs
370 private static Method sClipRevealMethod = null;
371 static {
372 Class<?> activityOptionsClass = ActivityOptions.class;
373 try {
374 sClipRevealMethod = activityOptionsClass.getDeclaredMethod("makeClipRevealAnimation",
375 View.class, int.class, int.class, int.class, int.class);
376 } catch (Exception e) {
377 // Earlier version
378 }
379 }
380
Adam Cohen091440a2015-03-18 14:16:05 -0700381 @Thunk Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700382 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700383 if (mWorkspace != null) {
384 mWorkspace.buildPageHardwareLayers();
385 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700386 }
387 };
388
Adam Cohendb364c32014-05-20 14:23:40 -0700389 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800390
Adam Cohen091440a2015-03-18 14:16:05 -0700391 @Thunk static class PendingAddArguments {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800392 int requestCode;
393 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700394 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700395 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800396 int cellX;
397 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700398 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800399 }
400
Daniel Sandlerff02d492013-08-05 02:12:05 -0400401 private Stats mStats;
402
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700403 FocusIndicatorView mFocusHandler;
404
Sunny Goyal316490e2015-06-02 09:38:28 -0700405 @Thunk boolean mRotationEnabled = false;
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400406 private boolean mScreenOrientationSettingReceiverRegistered = false;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700407
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400408 final private BroadcastReceiver mScreenOrientationSettingReceiver =
409 new BroadcastReceiver() {
410 @Thunk Runnable mUpdateOrientationRunnable = new Runnable() {
411 public void run() {
412 setOrientation();
413 }
414 };
415
416 @Override
417 public void onReceive(Context context, Intent intent) {
418 mRotationEnabled = intent.getBooleanExtra(
419 Utilities.SCREEN_ROTATION_SETTING_EXTRA, false);
420 if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
421 setOrientation();
422 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700423 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400424 };
425
426 @Thunk void setOrientation() {
427 if (mRotationEnabled) {
428 unlockScreenOrientation(true);
429 } else {
430 setRequestedOrientation(
431 ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700432 }
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400433 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700434
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 @Override
436 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700437 if (DEBUG_STRICT_MODE) {
438 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
439 .detectDiskReads()
440 .detectDiskWrites()
441 .detectNetwork() // or .detectAll() for all detectable problems
442 .penaltyLog()
443 .build());
444 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
445 .detectLeakedSqlLiteObjects()
446 .detectLeakedClosableObjects()
447 .penaltyLog()
448 .penaltyDeath()
449 .build());
450 }
451
Adam Cohen9211d422014-10-07 18:14:53 -0700452 if (mLauncherCallbacks != null) {
453 mLauncherCallbacks.preOnCreate();
454 }
455
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400457
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400458 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400459 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700460 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700461
Adam Cohen2e6da152015-05-06 11:42:25 -0700462 // Load configuration-specific DeviceProfile
Sunny Goyalc6205602015-05-21 20:46:33 -0700463 mDeviceProfile = getResources().getConfiguration().orientation
464 == Configuration.ORIENTATION_LANDSCAPE ?
465 app.getInvariantDeviceProfile().landscapeProfile
466 : app.getInvariantDeviceProfile().portraitProfile;
467
Winson Chung5f8afe62013-08-12 16:19:28 -0700468 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400469 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700470 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700471 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800472 mModel = app.setLauncher(this);
473 mIconCache = app.getIconCache();
Adam Cohen2e6da152015-05-06 11:42:25 -0700474
Joe Onorato41a12d22009-10-31 18:30:00 -0400475 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800476 mInflater = getLayoutInflater();
Winson Chungb745afb2015-03-02 11:51:23 -0800477 mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);
Romain Guycbb89e42009-06-08 15:52:54 -0700478
Daniel Sandlerff02d492013-08-05 02:12:05 -0400479 mStats = new Stats(this);
480
Sunny Goyalffe83f12014-08-14 17:39:34 -0700481 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700482
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700483 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
484 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700485
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700486 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
487 // this also ensures that any synchronous binding below doesn't re-trigger another
488 // LauncherModel load.
489 mPaused = false;
490
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800491 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200492 android.os.Debug.startMethodTracing(
493 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800494 }
495
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800496 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700497
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800498 setupViews();
Sunny Goyaldfaccf62015-05-11 16:30:44 -0700499 mDeviceProfile.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800500
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800501 registerContentObservers();
502
Joe Onorato7c312c12009-08-13 21:36:53 -0700503 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700504
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800505 mSavedState = savedInstanceState;
506 restoreState(mSavedState);
507
508 if (PROFILE_STARTUP) {
509 android.os.Debug.stopMethodTracing();
510 }
511
512 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700513 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700514 // If the user leaves launcher, then we should just load items asynchronously when
515 // they return.
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700516 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700517 } else {
518 // We only load the page synchronously if the user rotates (or triggers a
519 // configuration change) while launcher is in the foreground
Sunny Goyal2bba4c32015-05-18 15:42:48 -0700520 mModel.startLoader(mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700521 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800522 }
523
524 // For handling default keys
525 mDefaultKeySsb = new SpannableStringBuilder();
526 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800527
528 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
529 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800530
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700531 mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
532 // In case we are on a device with locked rotation, we should look at preferences to check
533 // if the user has specifically allowed rotation.
534 if (!mRotationEnabled) {
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400535 String updateOrientationBroadcastPermission = getResources().getString(
536 R.string.receive_update_orientation_broadcasts_permission);
537 registerReceiver(mScreenOrientationSettingReceiver,
538 new IntentFilter(Utilities.SCREEN_ROTATION_SETTING_INTENT),
539 updateOrientationBroadcastPermission, null);
540 mScreenOrientationSettingReceiverRegistered = true;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -0700541 mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
542 }
543
544 // On large interfaces, or on devices that a user has specifically enabled screen rotation,
545 // we want the screen to auto-rotate based on the current orientation
Rahul Chaturvedi799aa042015-06-01 21:26:41 -0400546 setOrientation();
Winson Chungaf40f202013-09-18 18:26:31 -0700547
Adam Cohen9211d422014-10-07 18:14:53 -0700548 if (mLauncherCallbacks != null) {
549 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700550 if (mLauncherCallbacks.hasLauncherOverlay()) {
551 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700552 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
553 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
554 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700555 mWorkspace.setLauncherOverlay(mLauncherOverlay);
556 }
Adam Cohen9211d422014-10-07 18:14:53 -0700557 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700558
559 if (shouldShowIntroScreen()) {
560 showIntroScreen();
561 } else {
562 showFirstRunActivity();
563 showFirstRunClings();
564 }
Adam Cohen9211d422014-10-07 18:14:53 -0700565 }
566
567 private LauncherCallbacks mLauncherCallbacks;
568
569 public void onPostCreate(Bundle savedInstanceState) {
570 super.onPostCreate(savedInstanceState);
571 if (mLauncherCallbacks != null) {
572 mLauncherCallbacks.onPostCreate(savedInstanceState);
573 }
574 }
575
576 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
577 mLauncherCallbacks = callbacks;
Winson Chung0f785722015-04-08 10:27:49 -0700578 mLauncherCallbacks.setLauncherAppsCallback(new Launcher.LauncherAppsCallbacks() {
579 @Override
580 public void onAllAppsBoundsChanged(Rect bounds) {
Winson Chungcd99cd32015-04-29 11:03:24 -0700581 if (LOGD) {
582 Log.d(TAG, "onAllAppsBoundsChanged(Rect): " + bounds);
583 }
Winson Chung94804152015-05-08 13:06:44 -0700584 mAppsView.setFixedBounds(bounds);
585 mWidgetsView.setFixedBounds(bounds);
Winson Chung0f785722015-04-08 10:27:49 -0700586 }
587
588 @Override
589 public void dismissAllApps() {
Winson Chung83f59ab2015-05-05 17:21:58 -0700590 if (!DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
591 // Dismiss All Apps if we aren't already paused/invisible
592 if (!mPaused) {
593 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true,
594 null /* onCompleteRunnable */, false /* notifyLauncherCallbacks */);
595 }
Winson Chungcd99cd32015-04-29 11:03:24 -0700596 }
Winson Chung0f785722015-04-08 10:27:49 -0700597 }
Sunny Goyal5683f872015-05-29 14:54:40 -0700598
599 @Override
600 public void setSearchManager(AppSearchManager manager) {
601 mAppsView.setSearchManager(manager);
602 }
Winson Chung0f785722015-04-08 10:27:49 -0700603 });
Jun Mukai8af0cd82015-05-12 12:32:12 -0700604 mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() {
605 private boolean mImportanceStored = false;
606 private int mWorkspaceImportanceForAccessibility =
607 View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
608 private int mHotseatImportanceForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
609
610 @Override
611 public void onSearchOverlayOpened() {
612 if (mImportanceStored) {
613 return;
614 }
615 // The underlying workspace and hotseat are temporarily suppressed by the search
616 // overlay. So they sholudn't be accessible.
617 mWorkspaceImportanceForAccessibility = mWorkspace.getImportantForAccessibility();
618 mHotseatImportanceForAccessibility = mHotseat.getImportantForAccessibility();
619 mWorkspace.setImportantForAccessibility(
620 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
621 mHotseat.setImportantForAccessibility(
622 View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
623 mImportanceStored = true;
624 }
625
626 @Override
627 public void onSearchOverlayClosed() {
628 mWorkspace.setImportantForAccessibility(mWorkspaceImportanceForAccessibility);
629 mHotseat.setImportantForAccessibility(mHotseatImportanceForAccessibility);
630 mImportanceStored = false;
631 }
632 });
Adam Cohen9211d422014-10-07 18:14:53 -0700633 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700634 }
635
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700636 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700637 public void onLauncherProviderChange() {
638 if (mLauncherCallbacks != null) {
639 mLauncherCallbacks.onLauncherProviderChange();
640 }
641 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700642
Adam Cohen9211d422014-10-07 18:14:53 -0700643 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700644 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700645 if (mLauncherCallbacks != null) {
646 return mLauncherCallbacks.hasCustomContentToLeft();
647 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700648 return false;
649 }
650
Dave Hawkeya8881582013-09-17 15:55:33 -0600651 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500652 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600653 * {@link #addToCustomContentPage}. This will only be invoked if
654 * {@link #hasCustomContentToLeft()} is {@code true}.
655 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500656 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700657 if (mLauncherCallbacks != null) {
658 mLauncherCallbacks.populateCustomContentContainer();
659 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600660 }
661
662 /**
663 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
664 * ensure the custom content page is added or removed if necessary.
665 */
666 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600667 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600668 // Not bound yet, wait for bindScreens to be called.
669 return;
670 }
671
672 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
673 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500674 mWorkspace.createCustomContentContainer();
675 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600676 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
677 mWorkspace.removeCustomContentPage();
678 }
679 }
680
Anton Hanssona2f665f2013-09-26 12:18:32 +0100681 public Stats getStats() {
682 return mStats;
683 }
684
Bjorn Bringertc459e522013-06-07 19:36:01 +0100685 public LayoutInflater getInflater() {
686 return mInflater;
687 }
688
Hyunyoung Song3f471442015-04-08 19:01:34 -0700689 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700690 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
691 // that is subsequently removed from the workspace in startBinding().
692 return !mModel.isLoadingWorkspace();
693 }
694
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800695 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000696 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100697 if (Build.VERSION.SDK_INT >= 17) {
698 return View.generateViewId();
699 } else {
700 // View.generateViewId() is not available. The following fallback logic is a copy
701 // of its implementation.
702 for (;;) {
703 final int result = sNextGeneratedId.get();
704 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
705 int newValue = result + 1;
706 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
707 if (sNextGeneratedId.compareAndSet(result, newValue)) {
708 return result;
709 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000710 }
711 }
712 }
713
714 public int getViewIdForItem(ItemInfo info) {
715 // This cast is safe given the > 2B range for int.
716 int itemId = (int) info.id;
717 if (mItemIdToViewId.containsKey(itemId)) {
718 return mItemIdToViewId.get(itemId);
719 }
720 int viewId = generateViewId();
721 mItemIdToViewId.put(itemId, viewId);
722 return viewId;
723 }
724
725 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700726 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
727 * a configuration step, this allows the proper animations to run after other transitions.
728 */
Adam Cohendb364c32014-05-20 14:23:40 -0700729 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700730 long screenId = args.screenId;
731 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
732 // When the screen id represents an actual screen (as opposed to a rank) we make sure
733 // that the drop page actually exists.
734 screenId = ensurePendingDropLayoutExists(args.screenId);
735 }
Adam Cohendb364c32014-05-20 14:23:40 -0700736
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700739 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700740 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700741 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700743 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700744 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700745 case REQUEST_RECONFIGURE_APPWIDGET:
746 completeRestoreAppWidget(args.appWidgetId);
747 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 }
Michael Jurka27614d22012-04-02 06:40:22 -0700749 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
750 // if you turned the screen off and then back while in All Apps, Launcher would not
751 // return to the workspace. Clearing mAddInfo.container here fixes this issue
752 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700753 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800754 }
755
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800756 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700757 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700758 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700759 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700760 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800761 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700762
Adam Cohenad4e15c2013-10-17 16:21:35 -0700763 Runnable exitSpringLoaded = new Runnable() {
764 @Override
765 public void run() {
766 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
767 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
768 }
769 };
770
Michael Jurka8b805b12012-04-18 14:23:14 -0700771 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700772 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700773 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
774 if (resultCode == RESULT_CANCELED) {
775 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700776 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700777 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 } else if (resultCode == RESULT_OK) {
Sunny Goyale6b63a32015-01-16 16:14:29 -0800779 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 }
782 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200783 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
784 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -0700785 showWorkspace(false);
Michael Jurka336fd4f2013-09-12 00:05:02 +0200786 }
787 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700788 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200789
Adam Cohened66b2b2012-01-23 17:28:51 -0800790 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
Sunny Goyal5c97f512015-05-19 16:03:28 -0700791 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700792
Adam Cohendb364c32014-05-20 14:23:40 -0700793 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800794 // We have special handling for widgets
795 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800796 final int appWidgetId;
797 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
798 : -1;
799 if (widgetId < 0) {
800 appWidgetId = pendingAddWidgetId;
801 } else {
802 appWidgetId = widgetId;
803 }
804
Adam Cohenad4e15c2013-10-17 16:21:35 -0700805 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800806 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700807 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
808 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700809 result = RESULT_CANCELED;
810 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700811 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700812 @Override
813 public void run() {
814 exitSpringLoadedDragModeDelayed(false, 0, null);
815 }
816 };
Adam Cohendb364c32014-05-20 14:23:40 -0700817 if (workspaceLocked) {
818 // No need to remove the empty screen if we're mid-binding, as the
819 // the bind will not add the empty screen.
820 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
821 } else {
822 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
823 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
824 }
Winson Chung5aaab772012-04-27 15:24:02 -0700825 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700826 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700827 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
828 // When the screen id represents an actual screen (as opposed to a rank)
829 // we make sure that the drop page actually exists.
830 mPendingAddInfo.screenId =
831 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
832 }
Adam Cohendb364c32014-05-20 14:23:40 -0700833 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
834
835 dropLayout.setDropPending(true);
836 final Runnable onComplete = new Runnable() {
837 @Override
838 public void run() {
839 completeTwoStageWidgetDrop(resultCode, appWidgetId);
840 dropLayout.setDropPending(false);
841 }
842 };
843 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
844 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
845 } else {
846 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
847 mPendingAddInfo);
848 sPendingAddItem = args;
849 }
Winson Chung5aaab772012-04-27 15:24:02 -0700850 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800851 return;
852 }
853
Sunny Goyalff572272014-07-23 13:58:07 -0700854 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
855 if (resultCode == RESULT_OK) {
856 // Update the widget view.
857 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
858 pendingAddWidgetId, mPendingAddInfo);
859 if (workspaceLocked) {
860 sPendingAddItem = args;
861 } else {
862 completeAdd(args);
863 }
864 }
865 // Leave the widget in the pending state if the user canceled the configure.
866 return;
867 }
868
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800869 // The pattern used here is that a user PICKs a specific application,
870 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700871
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
873 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700874 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700875 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
876 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800877 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700878 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800879 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700880 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700881 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
882 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 }
Adam Cohen00074722013-10-11 17:46:09 -0700884 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700885 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700886 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800887 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800888 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800889
890 }
891
892 @Override
893 protected void onActivityResult(
894 final int requestCode, final int resultCode, final Intent data) {
895 handleActivityResult(requestCode, resultCode, data);
896 if (mLauncherCallbacks != null) {
897 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
898 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800899 }
900
Adam Cohendb364c32014-05-20 14:23:40 -0700901 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
902 appWidgetId, ItemInfo info) {
903 PendingAddArguments args = new PendingAddArguments();
904 args.requestCode = requestCode;
905 args.intent = data;
906 args.container = info.container;
907 args.screenId = info.screenId;
908 args.cellX = info.cellX;
909 args.cellY = info.cellY;
910 args.appWidgetId = appWidgetId;
911 return args;
912 }
913
914 /**
915 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
916 *
917 * @param screenId the screen id to check
918 * @return the new screen, or screenId if it exists
919 */
920 private long ensurePendingDropLayoutExists(long screenId) {
921 CellLayout dropLayout =
922 (CellLayout) mWorkspace.getScreenWithId(screenId);
923 if (dropLayout == null) {
924 // it's possible that the add screen was removed because it was
925 // empty and a re-bind occurred
926 mWorkspace.addExtraEmptyScreen();
927 return mWorkspace.commitExtraEmptyScreen();
928 } else {
929 return screenId;
930 }
931 }
932
Adam Cohen091440a2015-03-18 14:16:05 -0700933 @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700934 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700935 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800936 Runnable onCompleteRunnable = null;
937 int animationType = 0;
938
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700939 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800940 if (resultCode == RESULT_OK) {
941 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
942 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700943 mPendingAddWidgetInfo);
944 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800945 onCompleteRunnable = new Runnable() {
946 @Override
947 public void run() {
948 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700949 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700950 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
951 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800952 }
953 };
954 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800955 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800956 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800957 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700958 if (mDragLayer.getAnimatedView() != null) {
959 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
960 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
961 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700962 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700963 // The animated view may be null in the case of a rotation during widget configuration
964 onCompleteRunnable.run();
965 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800966 }
967
968 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700969 protected void onStop() {
970 super.onStop();
971 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700972
973 if (mLauncherCallbacks != null) {
974 mLauncherCallbacks.onStop();
975 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700976 }
977
978 @Override
979 protected void onStart() {
980 super.onStart();
981 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700982
983 if (mLauncherCallbacks != null) {
984 mLauncherCallbacks.onStart();
985 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700986 }
987
988 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200990 long startTime = 0;
991 if (DEBUG_RESUME_TIME) {
992 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400993 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200994 }
Adam Cohen9211d422014-10-07 18:14:53 -0700995
996 if (mLauncherCallbacks != null) {
997 mLauncherCallbacks.preOnResume();
998 }
999
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001000 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -07001001
Winson Chung4a2afa32012-07-19 14:53:05 -07001002 // Restore the previous launcher state
Winson Chung75cc8252015-04-10 10:19:58 -07001003 if (mOnResumeState == State.WORKSPACE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001004 showWorkspace(false);
Winson Chungb745afb2015-03-02 11:51:23 -08001005 } else if (mOnResumeState == State.APPS) {
Winson Chung13eb5272015-05-11 16:30:13 -07001006 boolean launchedFromApp = (mWaitingForResume != null);
Winson Chung4ac30062015-05-08 17:34:17 -07001007 // Don't update the predicted apps if the user is returning to launcher in the apps
Winson Chung13eb5272015-05-11 16:30:13 -07001008 // view after launching an app, as they may be depending on the UI to be static to
1009 // switch to another app, otherwise, if it was
Winson Chung4ac30062015-05-08 17:34:17 -07001010 showAppsView(false /* animated */, false /* resetListToTop */,
Winson Chung13eb5272015-05-11 16:30:13 -07001011 !launchedFromApp /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08001012 } else if (mOnResumeState == State.WIDGETS) {
1013 showWidgetsView(false, false);
Winson Chung4a2afa32012-07-19 14:53:05 -07001014 }
1015 mOnResumeState = State.NONE;
1016
Winson Chungcd99cd32015-04-29 11:03:24 -07001017 // Restore the apps state if we are in all apps
Winson Chung4ac30062015-05-08 17:34:17 -07001018 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
1019 // Otherwise, notify the callbacks if we are in all apps mode
1020 if (mState == State.APPS) {
1021 if (mLauncherCallbacks != null) {
1022 mLauncherCallbacks.onAllAppsShown();
1023 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001024 }
1025 }
1026
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07001027 // Background was set to gradient in onPause(), restore to transparent if in all apps.
Sunny Goyald70ad0d2015-05-26 17:20:07 -07001028 setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
1029 : WORKSPACE_BACKGROUND_TRANSPARENT);
Craig Mautner360310b2012-10-26 15:13:08 -07001030
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001031 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001032 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001033 setWorkspaceLoading(true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001034 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001035 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001036 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001038 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001039 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1040 // execute them here
1041 long startTimeCallbacks = 0;
1042 if (DEBUG_RESUME_TIME) {
1043 startTimeCallbacks = System.currentTimeMillis();
1044 }
1045
Michael Jurka1e2f4652013-07-08 18:03:46 -07001046 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1047 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001048 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001049 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001050 if (DEBUG_RESUME_TIME) {
1051 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1052 (System.currentTimeMillis() - startTimeCallbacks));
1053 }
Michael Jurka447bf842013-05-15 14:52:15 +02001054 }
Michael Jurka54554252013-08-01 12:52:23 +02001055 if (mOnResumeCallbacks.size() > 0) {
1056 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1057 mOnResumeCallbacks.get(i).run();
1058 }
1059 mOnResumeCallbacks.clear();
1060 }
Winson Chunge4e50662012-01-23 14:45:13 -08001061
1062 // Reset the pressed state of icons that were locked in the press state while activities
1063 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001064 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001065 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001066 mWaitingForResume.setStayPressed(false);
1067 }
Winson Chung82963d52013-10-09 11:20:57 -07001068
Adam Cohen06dff352012-06-01 17:17:08 -07001069 // It is possible that widgets can receive updates while launcher is not in the foreground.
1070 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1071 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1072 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001073 getWorkspace().reinflateWidgetsIfNecessary();
Sunny Goyal22235bc2015-04-03 09:23:43 -07001074 reinflateQSBIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001075
Michael Jurka447bf842013-05-15 14:52:15 +02001076 if (DEBUG_RESUME_TIME) {
1077 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1078 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001079
1080 if (mWorkspace.getCustomContentCallbacks() != null) {
1081 // If we are resuming and the custom content is the current page, we call onShow().
1082 // It is also poassible that onShow will instead be called slightly after first layout
1083 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1084 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001085 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001086 }
1087 }
Winson Chungcd99cd32015-04-29 11:03:24 -07001088 updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
Adam Cohen53805212013-10-01 10:39:23 -07001089 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001090
Sunny Goyal756adbc2015-04-16 15:20:51 -07001091 if (!isWorkspaceLoading()) {
1092 // Process any items that were added while Launcher was away.
1093 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1094 }
Adam Cohen9211d422014-10-07 18:14:53 -07001095
1096 if (mLauncherCallbacks != null) {
1097 mLauncherCallbacks.onResume();
1098 }
Adam Cohen06dff352012-06-01 17:17:08 -07001099 }
1100
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001102 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001103 // Ensure that items added to Launcher are queued until Launcher returns
1104 InstallShortcutReceiver.enableInstallQueue();
1105
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001106 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001107 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001108 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001109 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001110
1111 // We call onHide() aggressively. The custom content callbacks should be able to
1112 // debounce excess onHide calls.
1113 if (mWorkspace.getCustomContentCallbacks() != null) {
1114 mWorkspace.getCustomContentCallbacks().onHide();
1115 }
Romain Guycbb89e42009-06-08 15:52:54 -07001116
Adam Cohen9211d422014-10-07 18:14:53 -07001117 if (mLauncherCallbacks != null) {
1118 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001119 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001120 }
1121
1122 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001123 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1124 // by a onResume or by scrolling otherwise.
1125 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001126
1127 // Custom content is completely hidden
1128 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001129
1130 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1131 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001132
1133 // Indicates whether the user is allowed to scroll away from the custom content.
1134 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001135 }
1136
Adam Cohenc2d6e892014-10-16 09:49:24 -07001137 public interface LauncherOverlay {
1138
1139 /**
1140 * Touch interaction leading to overscroll has begun
1141 */
1142 public void onScrollInteractionBegin();
1143
1144 /**
1145 * Touch interaction related to overscroll has ended
1146 */
1147 public void onScrollInteractionEnd();
1148
1149 /**
1150 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1151 * screen (or in the case of RTL, the rightmost screen).
1152 */
1153 public void onScrollChange(int progress, boolean rtl);
1154
1155 /**
1156 * Screen has stopped scrolling
1157 */
1158 public void onScrollSettled();
1159
1160 /**
1161 * This method can be called by the Launcher in order to force the LauncherOverlay
1162 * to exit fully immersive mode.
1163 */
1164 public void forceExitFullImmersion();
1165 }
1166
Winson Chung0f785722015-04-08 10:27:49 -07001167 public interface LauncherAppsCallbacks {
1168 /**
1169 * Updates launcher to the available space that AllApps can take so as not to overlap with
1170 * any other views.
1171 */
1172 public void onAllAppsBoundsChanged(Rect bounds);
1173
1174 /**
1175 * Called to dismiss all apps if it is showing.
1176 */
1177 public void dismissAllApps();
Sunny Goyal5683f872015-05-29 14:54:40 -07001178
1179 /**
1180 * Sets the search manager to be used for app search.
1181 */
1182 public void setSearchManager(AppSearchManager manager);
Winson Chung0f785722015-04-08 10:27:49 -07001183 }
1184
Jun Mukai8af0cd82015-05-12 12:32:12 -07001185 public interface LauncherSearchCallbacks {
1186 /**
1187 * Called when the search overlay is shown.
1188 */
1189 public void onSearchOverlayOpened();
1190
1191 /**
1192 * Called when the search overlay is dismissed.
1193 */
1194 public void onSearchOverlayClosed();
1195 }
1196
Adam Cohenc2d6e892014-10-16 09:49:24 -07001197 public interface LauncherOverlayCallbacks {
1198 /**
1199 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1200 * however it doesn't modify any state within the launcher.
1201 */
1202 public boolean canEnterFullImmersion();
1203
1204 /**
1205 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1206 * eg. by occupying the full screen and handling all touch events.
1207 *
1208 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1209 * case, Launcher will modify any necessary state and assumes the overlay is
1210 * handling all interaction. If false, the LauncherOverlay should cancel any
1211 *
1212 */
1213 public boolean enterFullImmersion();
1214
1215 /**
1216 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1217 * full control over UI and state.
1218 */
1219 public void exitFullImmersion();
1220 }
1221
1222 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1223
1224 @Override
1225 public boolean canEnterFullImmersion() {
1226 return mState == State.WORKSPACE;
1227 }
1228
1229 @Override
1230 public boolean enterFullImmersion() {
1231 if (mState == State.WORKSPACE) {
1232 // When fully immersed, disregard any touches which fall through.
1233 mDragLayer.setBlockTouch(true);
1234 return true;
1235 }
1236 return false;
1237 }
1238
1239 @Override
1240 public void exitFullImmersion() {
1241 mDragLayer.setBlockTouch(false);
1242 }
1243 }
1244
Jorim Jaggid017f882014-01-14 17:08:48 -08001245 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001246 if (mLauncherCallbacks != null) {
1247 return mLauncherCallbacks.hasSettings();
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07001248 } else {
1249 // On devices with a locked orientation, we will at least have the allow rotation
1250 // setting.
1251 return !Utilities.isRotationAllowedForDevice(this);
Adam Cohen9211d422014-10-07 18:14:53 -07001252 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001253 }
1254
Adam Cohen9211d422014-10-07 18:14:53 -07001255 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001256 CustomContentCallbacks callbacks, String description) {
1257 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001258 }
1259
Adam Cohenedb40762013-07-18 16:45:45 -07001260 // The custom content needs to offset its content to account for the QSB
1261 public int getTopOffsetForCustomContent() {
1262 return mWorkspace.getPaddingTop();
1263 }
1264
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001265 @Override
1266 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001267 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001268 if (mModel.isCurrentCallbacks(this)) {
1269 mModel.stopLoader();
1270 }
Hyunyoung Song3f471442015-04-08 19:01:34 -07001271 //TODO(hyunyoungs): stop the widgets loader when there is a rotation.
1272
Romain Guy13c2e7b2010-03-10 19:45:00 -08001273 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001274 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001275
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001276 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001277 @Override
1278 public void onWindowFocusChanged(boolean hasFocus) {
1279 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001280 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001281
1282 if (mLauncherCallbacks != null) {
1283 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1284 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001285 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001286
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287 private boolean acceptFilter() {
1288 final InputMethodManager inputManager = (InputMethodManager)
1289 getSystemService(Context.INPUT_METHOD_SERVICE);
1290 return !inputManager.isFullscreenMode();
1291 }
1292
1293 @Override
1294 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001295 final int uniChar = event.getUnicodeChar();
1296 final boolean handled = super.onKeyDown(keyCode, event);
1297 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1298 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001299 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1300 keyCode, event);
1301 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001302 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001303 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001304 // showSearchDialog()
1305 // If there are multiple keystrokes before the search dialog takes focus,
1306 // onSearchRequested() will be called for every keystroke,
1307 // but it is idempotent, so it's fine.
1308 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 }
1310 }
1311
Joe Onorato8a9625e2010-01-28 15:55:35 -08001312 // Eat the long press event so the keyboard doesn't come up.
1313 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1314 return true;
1315 }
1316
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 return handled;
1318 }
1319
Karl Rosaen138a0412009-04-23 19:00:21 -07001320 private String getTypedText() {
1321 return mDefaultKeySsb.toString();
1322 }
1323
1324 private void clearTypedText() {
1325 mDefaultKeySsb.clear();
1326 mDefaultKeySsb.clearSpans();
1327 Selection.setSelection(mDefaultKeySsb, 0);
1328 }
1329
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001331 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1332 * State
1333 */
1334 private static State intToState(int stateOrdinal) {
1335 State state = State.WORKSPACE;
1336 final State[] stateValues = State.values();
1337 for (int i = 0; i < stateValues.length; i++) {
1338 if (stateValues[i].ordinal() == stateOrdinal) {
1339 state = stateValues[i];
1340 break;
1341 }
1342 }
1343 return state;
1344 }
1345
1346 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001347 * Restores the previous state, if it exists.
1348 *
1349 * @param savedState The previous state.
1350 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001351 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001352 private void restoreState(Bundle savedState) {
1353 if (savedState == null) {
1354 return;
1355 }
1356
Michael Jurka883f55b2010-10-21 15:47:14 -07001357 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungb745afb2015-03-02 11:51:23 -08001358 if (state == State.APPS || state == State.WIDGETS) {
1359 mOnResumeState = state;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001360 }
1361
Adam Cohen21cd0022013-10-09 18:57:02 -07001362 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1363 PagedView.INVALID_RESTORE_PAGE);
1364 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001365 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 }
1367
Winson Chung3d503fb2011-07-13 17:25:49 -07001368 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001369 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001370
Winson Chung3d503fb2011-07-13 17:25:49 -07001371 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1372 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001373 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001374 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1375 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001376 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1377 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Adam Cohenb823ae42015-03-27 18:07:52 -07001378 AppWidgetProviderInfo info = savedState.getParcelable(
1379 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Sunny Goyalf044bb12015-05-12 13:30:07 -07001380 mPendingAddWidgetInfo = info == null ?
1381 null : LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
1382
Adam Cohen4637b5a2013-11-04 18:21:24 -08001383 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001384 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385 mRestoring = true;
1386 }
1387
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001388 mItemIdToViewId = (HashMap<Integer, Integer>)
1389 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001390 }
1391
1392 /**
1393 * Finds all the views we need and configure them properly.
1394 */
1395 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001396 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001397
Craig Mautner360310b2012-10-26 15:13:08 -07001398 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001399 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001400 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1401 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001402 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001403 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001404
John Spurlock77e1f472013-09-11 10:09:51 -04001405 mLauncherView.setSystemUiVisibility(
1406 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001407 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408
Winson Chung4c98d922011-05-31 16:50:48 -07001409 // Setup the drag layer
1410 mDragLayer.setup(this, dragController);
1411
Winson Chung3d503fb2011-07-13 17:25:49 -07001412 // Setup the hotseat
1413 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1414 if (mHotseat != null) {
Winson Chung11a1a532013-09-13 11:14:45 -07001415 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001416 }
1417
Jorim Jaggid017f882014-01-14 17:08:48 -08001418 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001419 View widgetButton = findViewById(R.id.widget_button);
1420 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001421 @Override
1422 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001423 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001424 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001425 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001426 }
1427 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001428 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1429
1430 View wallpaperButton = findViewById(R.id.wallpaper_button);
1431 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001432 @Override
1433 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001434 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001435 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001436 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001437 }
1438 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001439 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1440
1441 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001442 if (hasSettings()) {
1443 settingsButton.setOnClickListener(new OnClickListener() {
1444 @Override
1445 public void onClick(View arg0) {
1446 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001447 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001448 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001449 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001450 });
1451 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1452 } else {
1453 settingsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001454 }
1455
Adam Cohendbdff6b2013-09-18 19:09:15 -07001456 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001457
Winson Chung4c98d922011-05-31 16:50:48 -07001458 // Setup the workspace
1459 mWorkspace.setHapticFeedbackEnabled(false);
1460 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001461 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001462 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001463
Winson Chungf0ea4d32011-06-06 14:27:16 -07001464 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001465 mSearchDropTargetBar = (SearchDropTargetBar)
1466 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001467
Winson Chungb745afb2015-03-02 11:51:23 -08001468 // Setup Apps
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001469 mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
Winson Chung83f59ab2015-05-05 17:21:58 -07001470 if (isAllAppsSearchOverridden()) {
1471 mAppsView.hideHeaderBar();
Winson Chung0f785722015-04-08 10:27:49 -07001472 }
Winson Chungb745afb2015-03-02 11:51:23 -08001473
Winson Chungf0ea4d32011-06-06 14:27:16 -07001474 // Setup AppsCustomize
Hyunyoung Song3f471442015-04-08 19:01:34 -07001475 mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
Craig Mautner360310b2012-10-26 15:13:08 -07001476
Winson Chung3d503fb2011-07-13 17:25:49 -07001477 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001478 dragController.setDragScoller(mWorkspace);
1479 dragController.setScrollView(mDragLayer);
1480 dragController.setMoveTarget(mWorkspace);
1481 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001482 if (mSearchDropTargetBar != null) {
1483 mSearchDropTargetBar.setup(this, dragController);
Adam Cohenb0df1b02015-03-18 22:21:40 -07001484 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001485 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001486
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001487 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001488 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001489 mWeightWatcher = new WeightWatcher(this);
1490 mWeightWatcher.setAlpha(0.5f);
1491 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001492 new FrameLayout.LayoutParams(
1493 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001494 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001495 Gravity.BOTTOM)
1496 );
Adam Cohen39a06042013-07-19 14:30:12 -07001497
1498 boolean show = shouldShowWeightWatcher();
1499 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001500 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 }
1502
1503 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001504 * Sets the all apps button. This method is called from {@link Hotseat}.
1505 */
1506 public void setAllAppsButton(View allAppsButton) {
1507 mAllAppsButton = allAppsButton;
1508 }
1509
1510 public View getAllAppsButton() {
1511 return mAllAppsButton;
1512 }
1513
1514 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001515 * Creates a view representing a shortcut.
1516 *
1517 * @param info The data structure describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001519 View createShortcut(ShortcutInfo info) {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001520 return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 }
1522
1523 /**
1524 * Creates a view representing a shortcut inflated from the specified resource.
1525 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001526 * @param parent The group the shortcut belongs to.
1527 * @param info The data structure describing the shortcut.
1528 *
1529 * @return A View inflated from layoutResId.
1530 */
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001531 public View createShortcut(ViewGroup parent, ShortcutInfo info) {
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001532 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(R.layout.app_icon,
Sunny Goyaldfaccf62015-05-11 16:30:44 -07001533 parent, false);
1534 favorite.applyFromShortcutInfo(info, mIconCache);
1535 favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001536 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001537 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538 return favorite;
1539 }
1540
1541 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 * Add a shortcut to the workspace.
1543 *
1544 * @param data The intent describing the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001546 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001547 int cellY) {
1548 int[] cellXY = mTmpAddItemCellCoordinates;
1549 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001550 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001551
Sunny Goyal5c97f512015-05-19 16:03:28 -07001552 ShortcutInfo info = InstallShortcutReceiver.fromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001553 if (info == null) {
1554 return;
1555 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001556 final View view = createShortcut(info);
1557
Sunny Goyal5c97f512015-05-19 16:03:28 -07001558 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001559 // First we check if we already know the exact location where we want to add this item.
1560 if (cellX >= 0 && cellY >= 0) {
1561 cellXY[0] = cellX;
1562 cellXY[1] = cellY;
1563 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001564
1565 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001566 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001567 true, null,null)) {
1568 return;
1569 }
1570 DragObject dragObject = new DragObject();
1571 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001572 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1573 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001574 return;
1575 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001576 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001577 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001578 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001579 foundCellSpan = (result != null);
1580 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001581 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001582 }
1583
1584 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001585 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001586 return;
1587 }
1588
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001589 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001590
1591 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001592 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001593 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 }
1595 }
1596
Adam Cohen2e6da152015-05-06 11:42:25 -07001597 private int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight) {
1598 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001599 // We want to account for the extra amount of padding that we are adding to the widget
1600 // to ensure that it gets the full amount of space that it has requested
1601 int requiredWidth = minWidth + padding.left + padding.right;
1602 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2e6da152015-05-06 11:42:25 -07001603 return CellLayout.rectToCell(this, requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001604 }
1605
Adam Cohen2e6da152015-05-06 11:42:25 -07001606 public int[] getSpanForWidget(AppWidgetProviderInfo info) {
1607 return getSpanForWidget(info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001608 }
1609
Adam Cohen2e6da152015-05-06 11:42:25 -07001610 public int[] getMinSpanForWidget(AppWidgetProviderInfo info) {
1611 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001612 }
1613
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001615 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001616 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001617 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001618 */
Adam Cohen091440a2015-03-18 14:16:05 -07001619 @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
Adam Cohen59400422014-03-05 18:07:04 -08001620 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1621
1622 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001623 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001624 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1625 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001626 }
Romain Guycbb89e42009-06-08 15:52:54 -07001627
Adam Cohen59400422014-03-05 18:07:04 -08001628 if (appWidgetInfo.isCustomWidget) {
1629 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001630 }
1631
Adam Cohen59400422014-03-05 18:07:04 -08001632 LauncherAppWidgetInfo launcherInfo;
1633 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1634 launcherInfo.spanX = info.spanX;
1635 launcherInfo.spanY = info.spanY;
1636 launcherInfo.minSpanX = info.minSpanX;
1637 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001638 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001639
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001640 LauncherModel.addItemToDatabase(this, launcherInfo,
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07001641 container, screenId, info.cellX, info.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001642
1643 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001644 if (hostView == null) {
1645 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001646 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1647 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001648 } else {
1649 // The AppWidgetHostView has already been inflated and instantiated
1650 launcherInfo.hostView = hostView;
1651 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001652 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001653 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001654 launcherInfo.notifyWidgetSizeChanged(this);
1655
Adam Cohen59400422014-03-05 18:07:04 -08001656 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
1657 info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001658
1659 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001660 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001661 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001662 }
Romain Guycbb89e42009-06-08 15:52:54 -07001663
Adam Cohended9f8d2010-11-03 13:25:16 -07001664 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1665 @Override
1666 public void onReceive(Context context, Intent intent) {
1667 final String action = intent.getAction();
1668 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1669 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001670 mDragLayer.clearAllResizeFrames();
Winson Chungb745afb2015-03-02 11:51:23 -08001671 updateAutoAdvanceState();
Winson Chung337cd9d2011-03-30 10:39:30 -07001672
Winson Chungc100e8e2011-08-09 16:02:43 -07001673 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001674 // processing a multi-step drop
Hyunyoung Song3f471442015-04-08 19:01:34 -07001675 if (mAppsView != null && mWidgetsView != null &&
Winson Chungb745afb2015-03-02 11:51:23 -08001676 mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001677 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001678 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001679 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1680 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08001681 updateAutoAdvanceState();
Dan Sandlerd5024042014-01-09 15:01:33 -05001682 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1683 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001684 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001685 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1686 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1687 mModel.resetLoadedState(false, true);
Sunny Goyal2bba4c32015-05-18 15:42:48 -07001688 mModel.startLoader(PagedView.INVALID_RESTORE_PAGE,
Dan Sandlerd5024042014-01-09 15:01:33 -05001689 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1690 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001691 }
1692 }
1693 };
1694
1695 @Override
1696 public void onAttachedToWindow() {
1697 super.onAttachedToWindow();
1698
1699 // Listen for broadcasts related to user-presence
1700 final IntentFilter filter = new IntentFilter();
1701 filter.addAction(Intent.ACTION_SCREEN_OFF);
1702 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001703 // For handling managed profiles
Dan Sandlerd5024042014-01-09 15:01:33 -05001704 if (ENABLE_DEBUG_INTENTS) {
1705 filter.addAction(DebugIntents.DELETE_DATABASE);
1706 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1707 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001708 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001709 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001710 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001711 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001712 mVisible = true;
1713 }
1714
Adam Cohen0b395352014-06-09 22:54:36 +00001715 /**
1716 * Sets up transparent navigation and status bars in LMP.
1717 * This method is a no-op for other platform versions.
1718 */
Sunny Goyald0091012015-01-20 15:55:34 -08001719 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Adam Cohen0b395352014-06-09 22:54:36 +00001720 private void setupTransparentSystemBarsForLmp() {
Kenny Guyd794a3f2014-09-16 15:17:58 +01001721 if (Utilities.isLmpOrAbove()) {
Sunny Goyald0091012015-01-20 15:55:34 -08001722 Window window = getWindow();
1723 window.getAttributes().systemUiVisibility |=
1724 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1725 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1726 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1727 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1728 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1729 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
1730 window.setStatusBarColor(Color.TRANSPARENT);
1731 window.setNavigationBarColor(Color.TRANSPARENT);
Adam Cohen0b395352014-06-09 22:54:36 +00001732 }
1733 }
1734
Adam Cohended9f8d2010-11-03 13:25:16 -07001735 @Override
1736 public void onDetachedFromWindow() {
1737 super.onDetachedFromWindow();
1738 mVisible = false;
1739
Adam Cohend113e0c2010-11-11 10:48:05 -08001740 if (mAttached) {
1741 unregisterReceiver(mReceiver);
1742 mAttached = false;
1743 }
Winson Chungb745afb2015-03-02 11:51:23 -08001744 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001745 }
1746
1747 public void onWindowVisibilityChanged(int visibility) {
1748 mVisible = visibility == View.VISIBLE;
Winson Chungb745afb2015-03-02 11:51:23 -08001749 updateAutoAdvanceState();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001750 // The following code used to be in onResume, but it turns out onResume is called when
1751 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1752 // is a more appropriate event to handle
1753 if (mVisible) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001754 if (!mWorkspaceLoading) {
1755 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001756 // We want to let Launcher draw itself at least once before we force it to build
1757 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001758 // apps is nice and speedy.
1759 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001760 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001761 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001762 if (mStarted) return;
1763 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001764 // We delay the layer building a bit in order to give
1765 // other message processing a time to run. In particular
1766 // this avoids a delay in hiding the IME if it was
1767 // currently shown, because doing that may involve
1768 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001769 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001770 final ViewTreeObserver.OnDrawListener listener = this;
1771 mWorkspace.post(new Runnable() {
1772 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001773 if (mWorkspace != null &&
1774 mWorkspace.getViewTreeObserver() != null) {
1775 mWorkspace.getViewTreeObserver().
1776 removeOnDrawListener(listener);
1777 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001778 }
1779 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001780 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001781 }
1782 });
1783 }
1784 clearTypedText();
1785 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001786 }
1787
Adam Cohen091440a2015-03-18 14:16:05 -07001788 @Thunk void sendAdvanceMessage(long delay) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001789 mHandler.removeMessages(ADVANCE_MSG);
1790 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1791 mHandler.sendMessageDelayed(msg, delay);
1792 mAutoAdvanceSentTime = System.currentTimeMillis();
1793 }
1794
Adam Cohen091440a2015-03-18 14:16:05 -07001795 @Thunk void updateAutoAdvanceState() {
Adam Cohended9f8d2010-11-03 13:25:16 -07001796 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1797 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1798 mAutoAdvanceRunning = autoAdvanceRunning;
1799 if (autoAdvanceRunning) {
1800 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1801 sendAdvanceMessage(delay);
1802 } else {
1803 if (!mWidgetsToAdvance.isEmpty()) {
1804 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1805 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1806 }
1807 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001808 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001809 }
1810 }
1811 }
1812
1813 private final Handler mHandler = new Handler() {
1814 @Override
1815 public void handleMessage(Message msg) {
1816 if (msg.what == ADVANCE_MSG) {
1817 int i = 0;
1818 for (View key: mWidgetsToAdvance.keySet()) {
1819 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1820 final int delay = mAdvanceStagger * i;
1821 if (v instanceof Advanceable) {
1822 postDelayed(new Runnable() {
1823 public void run() {
1824 ((Advanceable) v).advance();
1825 }
1826 }, delay);
1827 }
1828 i++;
1829 }
1830 sendAdvanceMessage(mAdvanceInterval);
1831 }
1832 }
1833 };
1834
1835 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001836 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001837 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1838 if (v instanceof Advanceable) {
1839 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001840 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Winson Chungb745afb2015-03-02 11:51:23 -08001841 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001842 }
1843 }
1844
1845 void removeWidgetToAutoAdvance(View hostView) {
1846 if (mWidgetsToAdvance.containsKey(hostView)) {
1847 mWidgetsToAdvance.remove(hostView);
Winson Chungb745afb2015-03-02 11:51:23 -08001848 updateAutoAdvanceState();
Adam Cohended9f8d2010-11-03 13:25:16 -07001849 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001850 }
1851
Joe Onorato9c1289c2009-08-17 11:03:03 -04001852 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001853 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001854 launcherInfo.hostView = null;
1855 }
1856
Hyunyoung Song3f471442015-04-08 19:01:34 -07001857 public void showOutOfSpaceMessage(boolean isHotseatLayout) {
Winson Chung93eef082012-03-23 15:59:27 -07001858 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1859 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001860 }
1861
Winson Chunga6945242014-01-08 14:04:34 -08001862 public DragLayer getDragLayer() {
1863 return mDragLayer;
1864 }
1865
Winson Chung5f4e0fd2015-05-22 11:12:27 -07001866 public AllAppsContainerView getAppsView() {
Winson Chungb745afb2015-03-02 11:51:23 -08001867 return mAppsView;
1868 }
1869
Hyunyoung Song3f471442015-04-08 19:01:34 -07001870 public WidgetsContainerView getWidgetsView() {
1871 return mWidgetsView;
Winson Chungb745afb2015-03-02 11:51:23 -08001872 }
1873
Winson Chunga6945242014-01-08 14:04:34 -08001874 public Workspace getWorkspace() {
1875 return mWorkspace;
1876 }
1877
1878 public Hotseat getHotseat() {
1879 return mHotseat;
1880 }
1881
Jorim Jaggid017f882014-01-14 17:08:48 -08001882 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001883 return mOverviewPanel;
1884 }
1885
1886 public SearchDropTargetBar getSearchBar() {
1887 return mSearchDropTargetBar;
1888 }
1889
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001890 public LauncherAppWidgetHost getAppWidgetHost() {
1891 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 }
Romain Guycbb89e42009-06-08 15:52:54 -07001893
Winson Chunga9abd0e2010-10-27 17:18:37 -07001894 public LauncherModel getModel() {
1895 return mModel;
1896 }
1897
Winson Chunga6945242014-01-08 14:04:34 -08001898 protected SharedPreferences getSharedPrefs() {
1899 return mSharedPrefs;
1900 }
1901
Adam Cohen2e6da152015-05-06 11:42:25 -07001902 public DeviceProfile getDeviceProfile() {
1903 return mDeviceProfile;
1904 }
1905
Bjorn Bringertc459e522013-06-07 19:36:01 +01001906 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001907 getWindow().closeAllPanels();
1908
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001909 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001910 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001911 }
1912
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001913 @Override
1914 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001915 long startTime = 0;
1916 if (DEBUG_RESUME_TIME) {
1917 startTime = System.currentTimeMillis();
1918 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919 super.onNewIntent(intent);
1920
1921 // Close the menu
1922 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001923 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001924 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001925
Adam Cohened307df2013-10-02 09:37:31 -07001926 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1927 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1928 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001929
Adam Cohen6fecd412013-10-02 17:41:50 -07001930 if (mWorkspace == null) {
1931 // Can be cases where mWorkspace is null, this prevents a NPE
1932 return;
1933 }
1934 Folder openFolder = mWorkspace.getOpenFolder();
1935 // In all these cases, only animate if we're already on home
1936 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001937
1938 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1939 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Adam Cohen6fecd412013-10-02 17:41:50 -07001940 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Cohen9211d422014-10-07 18:14:53 -07001941 openFolder == null && moveToDefaultScreen) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001942 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001943 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001944
Adam Cohen6fecd412013-10-02 17:41:50 -07001945 closeFolder();
1946 exitSpringLoadedDragMode();
1947
1948 // If we are already on home, then just animate back to the workspace,
1949 // otherwise, just wait until onResume to set the state back to Workspace
1950 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001951 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001952 } else {
1953 mOnResumeState = State.WORKSPACE;
1954 }
1955
1956 final View v = getWindow().peekDecorView();
1957 if (v != null && v.getWindowToken() != null) {
1958 InputMethodManager imm = (InputMethodManager)getSystemService(
1959 INPUT_METHOD_SERVICE);
1960 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1961 }
1962
Winson Chungb745afb2015-03-02 11:51:23 -08001963 // Reset the apps view
1964 if (!alreadyOnHome && mAppsView != null) {
1965 mAppsView.scrollToTop();
1966 }
1967
Hyunyoung Song3f471442015-04-08 19:01:34 -07001968 // Reset the widgets view
1969 if (!alreadyOnHome && mWidgetsView != null) {
1970 mWidgetsView.scrollToTop();
Adam Cohen6fecd412013-10-02 17:41:50 -07001971 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001972
Adam Cohen9211d422014-10-07 18:14:53 -07001973 if (mLauncherCallbacks != null) {
1974 mLauncherCallbacks.onHomeIntent();
1975 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 }
Adam Cohened307df2013-10-02 09:37:31 -07001977
Michael Jurka447bf842013-05-15 14:52:15 +02001978 if (DEBUG_RESUME_TIME) {
1979 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1980 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001981
Adam Cohen9211d422014-10-07 18:14:53 -07001982 if (mLauncherCallbacks != null) {
1983 mLauncherCallbacks.onNewIntent(intent);
1984 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001985 }
1986
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001988 public void onRestoreInstanceState(Bundle state) {
1989 super.onRestoreInstanceState(state);
1990 for (int page: mSynchronouslyBoundPages) {
1991 mWorkspace.restoreInstanceStateForChild(page);
1992 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 }
1994
1995 @Override
1996 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001997 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001998 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1999 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07002000 }
Adam Cohen95bb8002011-07-03 23:40:28 -07002001 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002
Michael Jurka883f55b2010-10-21 15:47:14 -07002003 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07002004 // We close any open folder since it will not be re-opened, and we need to make sure
2005 // this state is reflected.
2006 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007
Adam Cohendcd297f2013-06-18 13:13:40 -07002008 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07002009 mWaitingForResult) {
2010 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07002011 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07002012 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2013 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002014 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2015 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2016 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08002017 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 }
2019
Hyunyoung Song3f471442015-04-08 19:01:34 -07002020 // Save the current widgets tray?
2021 // TODO(hyunyoungs)
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002022 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
Adam Cohen9211d422014-10-07 18:14:53 -07002023
2024 if (mLauncherCallbacks != null) {
2025 mLauncherCallbacks.onSaveInstanceState(outState);
2026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028
2029 @Override
2030 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002032
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04002033 if (mScreenOrientationSettingReceiverRegistered) {
2034 unregisterReceiver(mScreenOrientationSettingReceiver);
2035 mScreenOrientationSettingReceiverRegistered = false;
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002036 }
2037
Winson Chunge7a03942011-08-05 15:05:12 -07002038 // Remove all pending runnables
2039 mHandler.removeMessages(ADVANCE_MSG);
2040 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002041 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002042
Winson Chungcd2b0142011-06-08 16:02:26 -07002043 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002044 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07002045
2046 // It's possible to receive onDestroy after a new Launcher activity has
2047 // been created. In this case, don't interfere with the new Launcher.
2048 if (mModel.isCurrentCallbacks(this)) {
2049 mModel.stopLoader();
2050 app.setLauncher(null);
2051 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002052
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002054 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002056 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002058 mAppWidgetHost = null;
2059
2060 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061
2062 TextKeyListener.getInstance().release();
2063
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002064 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002065 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002066
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002067 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002068 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002069 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002070 mWorkspace = null;
2071 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002072
Michael Jurka2ecf9952012-06-18 12:52:28 -07002073 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002074
2075 if (mLauncherCallbacks != null) {
2076 mLauncherCallbacks.onDestroy();
2077 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002078 }
2079
Adam Cohena9cf38f2011-05-02 15:36:58 -07002080 public DragController getDragController() {
2081 return mDragController;
2082 }
2083
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002084 @Override
2085 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002086 onStartForResult(requestCode);
2087 super.startActivityForResult(intent, requestCode);
2088 }
2089
2090 @Override
2091 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2092 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2093 onStartForResult(requestCode);
2094 try {
2095 super.startIntentSenderForResult(intent, requestCode,
2096 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2097 } catch (IntentSender.SendIntentException e) {
2098 throw new ActivityNotFoundException();
2099 }
2100 }
2101
2102 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002103 if (requestCode >= 0) {
2104 setWaitingForResult(true);
2105 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002106 }
2107
Winson Chung70d72102011-08-12 11:24:35 -07002108 /**
2109 * Indicates that we want global search for this activity by setting the globalSearch
2110 * argument for {@link #startSearch} to true.
2111 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002113 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002114 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002115
Karl Rosaen138a0412009-04-23 19:00:21 -07002116 if (initialQuery == null) {
2117 // Use any text typed in the launcher as the initial query
2118 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002119 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 if (appSearchData == null) {
2121 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002122 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 }
Winson Chungadf0c182012-08-23 14:59:07 -07002124 Rect sourceBounds = new Rect();
2125 if (mSearchDropTargetBar != null) {
2126 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2127 }
Romain Guycbb89e42009-06-08 15:52:54 -07002128
Ian Parkinson047036e2014-09-01 15:40:53 +01002129 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002130 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002131 if (clearTextImmediately) {
2132 clearTypedText();
2133 }
Winson Chungcd99cd32015-04-29 11:03:24 -07002134
2135 // We need to show the workspace after starting the search
2136 showWorkspace(true);
Bjorn Bringertc459e522013-06-07 19:36:01 +01002137 }
2138
Ian Parkinson047036e2014-09-01 15:40:53 +01002139 /**
2140 * Start a text search.
2141 *
2142 * @return {@code true} if the search will start immediately, so any further keypresses
2143 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2144 * to buffer keypresses.
2145 */
2146 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002147 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002148 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2149 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2150 sourceBounds);
2151 }
2152
Michael Jurkaa33411c2012-06-14 16:18:21 -07002153 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002154 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002155 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002156 }
2157
2158 /**
2159 * Starts the global search activity. This code is a copied from SearchManager
2160 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002161 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002162 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002163 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002164 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2165 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2166 if (globalSearchActivity == null) {
2167 Log.w(TAG, "No global search activity found.");
2168 return;
2169 }
2170 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2171 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2172 intent.setComponent(globalSearchActivity);
2173 // Make sure that we have a Bundle to put source in
2174 if (appSearchData == null) {
2175 appSearchData = new Bundle();
2176 } else {
2177 appSearchData = new Bundle(appSearchData);
2178 }
Adam Cohen9211d422014-10-07 18:14:53 -07002179 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002180 if (!appSearchData.containsKey("source")) {
2181 appSearchData.putString("source", getPackageName());
2182 }
2183 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2184 if (!TextUtils.isEmpty(initialQuery)) {
2185 intent.putExtra(SearchManager.QUERY, initialQuery);
2186 }
2187 if (selectInitialQuery) {
2188 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2189 }
2190 intent.setSourceBounds(sourceBounds);
2191 try {
2192 startActivity(intent);
2193 } catch (ActivityNotFoundException ex) {
2194 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2195 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002196 }
2197
Yura4f93ec62014-02-04 14:15:21 +00002198 public boolean isOnCustomContent() {
2199 return mWorkspace.isOnOrMovingToCustomContent();
2200 }
2201
Winson Chung70d72102011-08-12 11:24:35 -07002202 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002203 public boolean onPrepareOptionsMenu(Menu menu) {
2204 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002205 if (!isOnCustomContent()) {
2206 // Close any open folders
2207 closeFolder();
2208 // Stop resizing any widgets
2209 mWorkspace.exitWidgetResizeMode();
2210 if (!mWorkspace.isInOverviewMode()) {
2211 // Show the overview mode
2212 showOverviewMode(true);
2213 } else {
2214 showWorkspace(true);
2215 }
Winson Chunge0298742014-01-17 12:03:00 -08002216 }
Adam Cohen9211d422014-10-07 18:14:53 -07002217 if (mLauncherCallbacks != null) {
2218 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2219 }
2220
Michael Jurkab94f3f82013-09-11 18:08:54 +02002221 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002223
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002224 @Override
2225 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002226 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002227 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002228 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002229 }
2230
Joe Onorato9c1289c2009-08-17 11:03:03 -04002231 public boolean isWorkspaceLocked() {
2232 return mWorkspaceLoading || mWaitingForResult;
2233 }
2234
Adam Cohen517a7f52014-03-01 12:12:59 -08002235 public boolean isWorkspaceLoading() {
2236 return mWorkspaceLoading;
2237 }
2238
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002239 private void setWorkspaceLoading(boolean value) {
2240 boolean isLocked = isWorkspaceLocked();
2241 mWorkspaceLoading = value;
2242 if (isLocked != isWorkspaceLocked()) {
2243 onWorkspaceLockedChanged();
2244 }
2245 }
2246
2247 private void setWaitingForResult(boolean value) {
2248 boolean isLocked = isWorkspaceLocked();
2249 mWaitingForResult = value;
2250 if (isLocked != isWorkspaceLocked()) {
2251 onWorkspaceLockedChanged();
2252 }
2253 }
2254
Adam Cohen9211d422014-10-07 18:14:53 -07002255 protected void onWorkspaceLockedChanged() {
2256 if (mLauncherCallbacks != null) {
2257 mLauncherCallbacks.onWorkspaceLockedChanged();
2258 }
2259 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002260
Michael Jurka0280c3b2010-09-17 15:00:07 -07002261 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002262 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002263 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002264 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2265 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002266 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002267 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002268 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002269
Sunny Goyale6b63a32015-01-16 16:14:29 -08002270 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002271 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Adam Cohenad4e15c2013-10-17 16:21:35 -07002272 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2273 }
2274
Sunny Goyale6b63a32015-01-16 16:14:29 -08002275 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002276 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2277 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002278 if (appWidgetInfo.configure != null) {
2279 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002280 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002281
Bjorn Bringert7984c942009-12-09 15:38:25 +00002282 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002283 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2284 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2285
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002286 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002287 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002288 Runnable onComplete = new Runnable() {
2289 @Override
2290 public void run() {
2291 // Exit spring loaded mode if necessary after adding the widget
2292 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2293 null);
2294 }
2295 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002296 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002297 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002298 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002299 }
2300 }
Romain Guycbb89e42009-06-08 15:52:54 -07002301
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002302 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002303 // Close any folders that may be open.
2304 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002305 mWorkspace.moveToCustomContentScreen(animate);
2306 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002307
2308 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2309 int[] cell, int spanX, int spanY) {
2310 switch (info.itemType) {
2311 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2312 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2313 int span[] = new int[2];
2314 span[0] = spanX;
2315 span[1] = spanY;
2316 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2317 container, screenId, cell, span);
2318 break;
2319 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2320 processShortcutFromDrop(info.componentName, container, screenId, cell);
2321 break;
2322 default:
2323 throw new IllegalStateException("Unknown item type: " + info.itemType);
2324 }
2325 }
2326
Adam Cohenfbba09b2011-07-18 21:43:05 -07002327 /**
2328 * Process a shortcut drop.
2329 *
2330 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002331 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002332 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002333 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002334 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2335 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002336 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002337 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002338 mPendingAddInfo.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002339 mPendingAddInfo.dropPos = null;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002340
2341 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002342 mPendingAddInfo.cellX = cell[0];
2343 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002344 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002345
2346 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2347 createShortcutIntent.setComponent(componentName);
2348 processShortcut(createShortcutIntent);
2349 }
2350
Adam Cohenfbba09b2011-07-18 21:43:05 -07002351 /**
2352 * Process a widget drop.
2353 *
2354 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002355 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002356 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002357 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002358 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2359 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002360 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002361 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002362 mPendingAddInfo.screenId = info.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002363 mPendingAddInfo.dropPos = null;
Adam Cohend41fbf52012-02-16 23:53:59 -08002364 mPendingAddInfo.minSpanX = info.minSpanX;
2365 mPendingAddInfo.minSpanY = info.minSpanY;
2366
Adam Cohenfbba09b2011-07-18 21:43:05 -07002367 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002368 mPendingAddInfo.cellX = cell[0];
2369 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002370 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002371 if (span != null) {
2372 mPendingAddInfo.spanX = span[0];
2373 mPendingAddInfo.spanY = span[1];
2374 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002375
Adam Cohened66b2b2012-01-23 17:28:51 -08002376 AppWidgetHostView hostView = info.boundWidget;
2377 int appWidgetId;
2378 if (hostView != null) {
2379 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002380 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002381 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002382 // In this case, we either need to start an activity to get permission to bind
2383 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002384 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002385 Bundle options = info.bindOptions;
2386
Sunny Goyalffe83f12014-08-14 17:39:34 -07002387 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2388 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002389 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002390 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002391 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002392 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002393 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2394 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2395 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002396 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2397 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002398 // TODO: we need to make sure that this accounts for the options bundle.
2399 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002400 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2401 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002402 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002403 }
2404
Joe Onoratodeb98af2010-02-19 14:59:39 -08002405 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002406 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002407 }
2408
Winson Chung24ab2f12010-09-16 14:10:47 -07002409 void processWallpaper(Intent intent) {
2410 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2411 }
2412
Adam Cohendcd297f2013-06-18 13:13:40 -07002413 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002414 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002415 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002416 folderInfo.title = getText(R.string.folder_name);
2417
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002418 // Update the model
Sunny Goyal1d4a2df2015-03-30 11:11:46 -07002419 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
2420 cellX, cellY);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002421 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002422
2423 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002424 FolderIcon newFolder =
2425 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002426 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002427 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002428 // Force measure the new folder icon
2429 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2430 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002431 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002432 }
Romain Guycbb89e42009-06-08 15:52:54 -07002433
Joe Onorato9c1289c2009-08-17 11:03:03 -04002434 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002435 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002436 }
2437
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002438 /**
2439 * Registers various content observers. The current implementation registers
2440 * only a favorites observer to keep track of the favorites applications.
2441 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002442 private void registerContentObservers() {
2443 ContentResolver resolver = getContentResolver();
2444 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2445 true, mWidgetObserver);
2446 }
2447
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002448 @Override
2449 public boolean dispatchKeyEvent(KeyEvent event) {
2450 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2451 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002452 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002453 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002454 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002455 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002456 dumpState();
2457 return true;
2458 }
2459 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002460 }
2461 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2462 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002463 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002464 return true;
2465 }
2466 }
2467
2468 return super.dispatchKeyEvent(event);
2469 }
2470
Joe Onorato88ec0992009-11-19 13:16:06 -08002471 @Override
2472 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002473 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2474 return;
2475 }
2476
Winson Chung3d9490a2015-03-24 17:38:42 -07002477 LauncherAccessibilityDelegate delegate =
2478 LauncherAppState.getInstance().getAccessibilityDelegate();
2479 if (delegate != null && delegate.onBackPressed()) {
Adam Cohenc9735cf2015-01-23 16:11:55 -08002480 return;
2481 }
2482
Winson Chungb745afb2015-03-02 11:51:23 -08002483 if (isAppsViewVisible()) {
2484 showWorkspace(true);
2485 } else if (isWidgetsViewVisible()) {
2486 showOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002487 } else if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002488 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002489 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002490 Folder openFolder = mWorkspace.getOpenFolder();
2491 if (openFolder.isEditingName()) {
2492 openFolder.dismissEditingName();
2493 } else {
2494 closeFolder();
2495 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002496 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002497 mWorkspace.exitWidgetResizeMode();
2498
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002499 // Back button is a no-op here, but give at least some feedback for the button press
2500 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002501 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002502 }
2503
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002504 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002505 * Re-listen when widgets are reset.
2506 */
Adam Cohen091440a2015-03-18 14:16:05 -07002507 @Thunk void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002508 if (mAppWidgetHost != null) {
2509 mAppWidgetHost.startListening();
2510 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002511 }
2512
2513 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002514 * Launches the intent referred by the clicked shortcut.
2515 *
2516 * @param v The view representing the clicked shortcut.
2517 */
2518 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002519 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2520 // view has detached (it's possible for this to happen if the view is removed mid touch).
2521 if (v.getWindowToken() == null) {
2522 return;
2523 }
2524
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002525 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002526 return;
2527 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002528
Adam Cohen1697b792013-09-17 19:08:21 -07002529 if (v instanceof Workspace) {
2530 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002531 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002532 }
2533 return;
2534 }
2535
2536 if (v instanceof CellLayout) {
2537 if (mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07002538 showWorkspace(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002539 }
2540 }
2541
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002542 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002543 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002544 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002545 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002546 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002547 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002548 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002549 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002550 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002551 } else if (tag instanceof AppInfo) {
2552 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002553 } else if (tag instanceof LauncherAppWidgetInfo) {
2554 if (v instanceof PendingAppWidgetHostView) {
2555 onClickPendingWidget((PendingAppWidgetHostView) v);
2556 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557 }
2558 }
2559
Sunny Goyal70660032015-05-14 00:07:08 -07002560 @SuppressLint("ClickableViewAccessibility")
Michael Jurka0e260592010-06-30 17:07:39 -07002561 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002562 return false;
2563 }
2564
Michael Jurkaaf442092010-06-10 17:01:57 -07002565 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002566 * Event handler for the app widget view which has not fully restored.
2567 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002568 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002569 if (mIsSafeModeEnabled) {
2570 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2571 return;
2572 }
2573
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002574 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002575 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002576 int widgetId = info.appWidgetId;
2577 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2578 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002579 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2580 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002581 mPendingAddInfo.copyFrom(info);
2582 mPendingAddWidgetId = widgetId;
2583
Sunny Goyalffe83f12014-08-14 17:39:34 -07002584 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2585 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002586 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002587 } else if (info.installProgress < 0) {
2588 // The install has not been queued
2589 final String packageName = info.providerName.getPackageName();
2590 showBrokenAppInstallDialog(packageName,
2591 new DialogInterface.OnClickListener() {
2592 public void onClick(DialogInterface dialog, int id) {
2593 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2594 }
2595 });
2596 } else {
2597 // Download has started.
2598 final String packageName = info.providerName.getPackageName();
2599 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002600 }
2601 }
2602
2603 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002604 * Event handler for the "grid" button that appears on the home screen, which
2605 * enters all apps mode.
2606 *
2607 * @param v The view that was clicked.
2608 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002609 protected void onClickAllAppsButton(View v) {
2610 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
Winson Chungb745afb2015-03-02 11:51:23 -08002611 if (isAppsViewVisible()) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002612 showWorkspace(true);
2613 } else {
Winson Chung4ac30062015-05-08 17:34:17 -07002614 // Try and refresh the set of predicted apps before we enter launcher
2615 showAppsView(true /* animated */, false /* resetListToTop */,
2616 true /* updatePredictedApps */);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617 }
2618 }
2619
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002620 private void showBrokenAppInstallDialog(final String packageName,
2621 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002622 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002623 .setTitle(R.string.abandoned_promises_title)
2624 .setMessage(R.string.abandoned_promise_explanation)
2625 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2626 .setNeutralButton(R.string.abandoned_clean_this,
2627 new DialogInterface.OnClickListener() {
2628 public void onClick(DialogInterface dialog, int id) {
2629 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2630 mWorkspace.removeAbandonedPromise(packageName, user);
2631 }
2632 })
2633 .create().show();
2634 return;
2635 }
2636
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002637 /**
2638 * Event handler for an app shortcut click.
2639 *
2640 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2641 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002642 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002643 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2644 Object tag = v.getTag();
2645 if (!(tag instanceof ShortcutInfo)) {
2646 throw new IllegalArgumentException("Input must be a Shortcut");
2647 }
2648
2649 // Open shortcut
2650 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002651
2652 if (shortcut.isDisabled != 0) {
2653 int error = R.string.activity_not_available;
2654 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2655 error = R.string.safemode_shortcut_error;
2656 }
2657 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2658 return;
2659 }
2660
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002661 final Intent intent = shortcut.intent;
2662
2663 // Check for special shortcuts
2664 if (intent.getComponent() != null) {
2665 final String shortcutClass = intent.getComponent().getClassName();
2666
2667 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2668 MemoryDumpActivity.startDump(this);
2669 return;
2670 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2671 toggleShowWeightWatcher();
2672 return;
2673 }
2674 }
2675
Chris Wren40c5ed32014-06-24 18:24:23 -04002676 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002677 if ((v instanceof BubbleTextView)
2678 && shortcut.isPromise()
2679 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002680 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002681 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002682 new DialogInterface.OnClickListener() {
2683 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002684 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002685 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002686 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002687 return;
2688 }
2689
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002690 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002691 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002692
2693 if (mLauncherCallbacks != null) {
2694 mLauncherCallbacks.onClickAppShortcut(v);
2695 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002696 }
2697
Adam Cohen091440a2015-03-18 14:16:05 -07002698 @Thunk void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002699 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002700 final ShortcutInfo shortcut;
2701 final Intent intent;
2702 if (tag instanceof ShortcutInfo) {
2703 shortcut = (ShortcutInfo) tag;
2704 intent = shortcut.intent;
2705 int[] pos = new int[2];
2706 v.getLocationOnScreen(pos);
2707 intent.setSourceBounds(new Rect(pos[0], pos[1],
2708 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002709
Sunny Goyal508da152014-08-14 10:53:27 -07002710 } else if (tag instanceof AppInfo) {
2711 shortcut = null;
2712 intent = ((AppInfo) tag).intent;
2713 } else {
2714 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2715 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002716
2717 boolean success = startActivitySafely(v, intent, tag);
Winson Chung8f1eff72015-05-28 17:33:40 -07002718 mStats.recordLaunch(v, intent, shortcut);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002719
2720 if (success && v instanceof BubbleTextView) {
2721 mWaitingForResume = (BubbleTextView) v;
2722 mWaitingForResume.setStayPressed(true);
2723 }
2724 }
2725
2726 /**
2727 * Event handler for a folder icon click.
2728 *
2729 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2730 */
2731 protected void onClickFolderIcon(View v) {
2732 if (LOGD) Log.d(TAG, "onClickFolder");
2733 if (!(v instanceof FolderIcon)){
2734 throw new IllegalArgumentException("Input must be a FolderIcon");
2735 }
2736
2737 FolderIcon folderIcon = (FolderIcon) v;
2738 final FolderInfo info = folderIcon.getFolderInfo();
2739 Folder openFolder = mWorkspace.getFolderForTag(info);
2740
2741 // If the folder info reports that the associated folder is open, then verify that
2742 // it is actually opened. There have been a few instances where this gets out of sync.
2743 if (info.opened && openFolder == null) {
2744 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2745 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2746 info.opened = false;
2747 }
2748
2749 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2750 // Close any open folder
2751 closeFolder();
2752 // Open the requested folder
2753 openFolder(folderIcon);
2754 } else {
2755 // Find the open folder...
2756 int folderScreen;
2757 if (openFolder != null) {
2758 folderScreen = mWorkspace.getPageForView(openFolder);
2759 // .. and close it
2760 closeFolder(openFolder);
2761 if (folderScreen != mWorkspace.getCurrentPage()) {
2762 // Close any folder open on the current screen
2763 closeFolder();
2764 // Pull the folder onto this screen
2765 openFolder(folderIcon);
2766 }
2767 }
2768 }
Adam Cohen9211d422014-10-07 18:14:53 -07002769
2770 if (mLauncherCallbacks != null) {
2771 mLauncherCallbacks.onClickFolderIcon(v);
2772 }
Michael Jurka5130e402011-10-13 04:55:35 -07002773 }
2774
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002775 /**
2776 * Event handler for the (Add) Widgets button that appears after a long press
2777 * on the home screen.
2778 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002779 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002780 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002781 if (mIsSafeModeEnabled) {
2782 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2783 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08002784 showWidgetsView(true /* animated */, true /* resetPageToZero */);
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002785 if (mLauncherCallbacks != null) {
2786 mLauncherCallbacks.onClickAddWidgetButton(view);
2787 }
Adam Cohen9211d422014-10-07 18:14:53 -07002788 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002789 }
2790
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002791 /**
2792 * Event handler for the wallpaper picker button that appears after a long press
2793 * on the home screen.
2794 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002795 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002796 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
Sunny Goyal6a1e95a2015-03-20 17:26:30 -07002797 startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName()),
2798 REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002799
2800 if (mLauncherCallbacks != null) {
2801 mLauncherCallbacks.onClickWallpaperPicker(v);
2802 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002803 }
2804
2805 /**
2806 * Event handler for a click on the settings button that appears after a long press
2807 * on the home screen.
2808 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002809 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002810 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002811 if (mLauncherCallbacks != null) {
2812 mLauncherCallbacks.onClickSettingsButton(v);
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07002813 } else {
2814 showSettingsActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002815 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002816 }
2817
Michael Jurka5130e402011-10-13 04:55:35 -07002818 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002819 // Provide the same haptic feedback that the system offers for virtual keys.
2820 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002821 }
2822
Adam Cohen61f560d2013-09-30 15:58:20 -07002823 public void performHapticFeedbackOnTouchDown(View v) {
2824 // Provide the same haptic feedback that the system offers for virtual keys.
2825 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2826 }
2827
2828 public View.OnTouchListener getHapticFeedbackTouchListener() {
2829 if (mHapticFeedbackTouchListener == null) {
2830 mHapticFeedbackTouchListener = new View.OnTouchListener() {
Sunny Goyal70660032015-05-14 00:07:08 -07002831 @SuppressLint("ClickableViewAccessibility")
Adam Cohen61f560d2013-09-30 15:58:20 -07002832 @Override
2833 public boolean onTouch(View v, MotionEvent event) {
2834 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2835 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2836 }
2837 return false;
2838 }
2839 };
2840 }
2841 return mHapticFeedbackTouchListener;
2842 }
2843
Adam Cohen9211d422014-10-07 18:14:53 -07002844 public void onDragStarted(View view) {
2845 if (isOnCustomContent()) {
2846 // Custom content screen doesn't participate in drag and drop. If on custom
2847 // content screen, move to default.
2848 moveWorkspaceToDefaultScreen();
2849 }
2850
2851 if (mLauncherCallbacks != null) {
2852 mLauncherCallbacks.onDragStarted(view);
2853 }
2854 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002855
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002856 /**
2857 * Called when the user stops interacting with the launcher.
2858 * This implies that the user is now on the homescreen and is not doing housekeeping.
2859 */
Adam Cohen9211d422014-10-07 18:14:53 -07002860 protected void onInteractionEnd() {
2861 if (mLauncherCallbacks != null) {
2862 mLauncherCallbacks.onInteractionEnd();
2863 }
2864 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002865
2866 /**
2867 * Called when the user starts interacting with the launcher.
2868 * The possible interactions are:
2869 * - open all apps
2870 * - reorder an app shortcut, or a widget
2871 * - open the overview mode.
2872 * This is a good time to stop doing things that only make sense
2873 * when the user is on the homescreen and not doing housekeeping.
2874 */
Adam Cohen9211d422014-10-07 18:14:53 -07002875 protected void onInteractionBegin() {
2876 if (mLauncherCallbacks != null) {
2877 mLauncherCallbacks.onInteractionBegin();
2878 }
2879 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002880
Winson Chungcd99cd32015-04-29 11:03:24 -07002881 /** Updates the interaction state. */
2882 public void updateInteraction(Workspace.State fromState, Workspace.State toState) {
Winson Chung83f59ab2015-05-05 17:21:58 -07002883 // Only update the interacting state if we are transitioning to/from a view with an
Winson Chungcd99cd32015-04-29 11:03:24 -07002884 // overlay
Winson Chung83f59ab2015-05-05 17:21:58 -07002885 boolean fromStateWithOverlay;
2886 boolean toStateWithOverlay;
2887 if (Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
2888 fromStateWithOverlay = fromState != Workspace.State.NORMAL;
2889 toStateWithOverlay = toState != Workspace.State.NORMAL;
2890 } else {
2891 fromStateWithOverlay = fromState != Workspace.State.NORMAL &&
2892 fromState != Workspace.State.NORMAL_HIDDEN;
2893 toStateWithOverlay = toState != Workspace.State.NORMAL &&
2894 toState != Workspace.State.NORMAL_HIDDEN;
2895 }
2896 if (toStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002897 onInteractionBegin();
Winson Chung83f59ab2015-05-05 17:21:58 -07002898 } else if (fromStateWithOverlay) {
Winson Chungcd99cd32015-04-29 11:03:24 -07002899 onInteractionEnd();
2900 }
2901 }
2902
Kenny Guyf07af7b2014-07-31 11:39:16 +01002903 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002904 try {
2905 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002906 launcherApps.showAppDetailsForProfile(componentName, user);
2907 } catch (SecurityException e) {
2908 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2909 Log.e(TAG, "Launcher does not have permission to launch settings");
2910 } catch (ActivityNotFoundException e) {
2911 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2912 Log.e(TAG, "Unable to launch settings");
2913 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002914 }
2915
Michael Jurka1e2f4652013-07-08 18:03:46 -07002916 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002917 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2918 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002919 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002920 // System applications cannot be installed. For now, show a toast explaining that.
2921 // We may give them the option of disabling apps this way.
2922 int messageId = R.string.uninstall_system_app_text;
2923 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002924 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002925 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002926 String packageName = componentName.getPackageName();
2927 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002928 Intent intent = new Intent(
2929 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002930 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2931 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002932 if (user != null) {
2933 user.addToIntent(intent, Intent.EXTRA_USER);
2934 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002935 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002936 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002937 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002938 }
2939
Winson Chung8f1eff72015-05-28 17:33:40 -07002940 private boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002942 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002943 // Only launch using the new animation if the shortcut has not opted out (this is a
2944 // private contract between launcher and may be ignored in the future).
2945 boolean useLaunchAnimation = (v != null) &&
2946 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002947 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2948 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002949
Kenny Guy1317e2d2014-05-08 18:52:50 +01002950 UserHandleCompat user = null;
2951 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2952 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2953 user = userManager.getUserForSerialNumber(serialNumber);
2954 }
2955
2956 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002957 if (useLaunchAnimation) {
Chet Haasea8f996d2015-02-17 12:56:04 -08002958 ActivityOptions opts = null;
2959 if (sClipRevealMethod != null) {
2960 // TODO: call method directly when Launcher3 can depend on M APIs
2961 int left = 0, top = 0;
2962 int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
2963 if (v instanceof TextView) {
2964 // Launch from center of icon, not entire view
Winson Chungb745afb2015-03-02 11:51:23 -08002965 Drawable icon = Workspace.getTextViewIcon((TextView) v);
2966 if (icon != null) {
2967 Rect bounds = icon.getBounds();
Chet Haasea8f996d2015-02-17 12:56:04 -08002968 left = (width - bounds.width()) / 2;
Winson Chungb745afb2015-03-02 11:51:23 -08002969 top = v.getPaddingTop();
Chet Haasea8f996d2015-02-17 12:56:04 -08002970 width = bounds.width();
2971 height = bounds.height();
2972 }
2973 }
2974 try {
2975 opts = (ActivityOptions) sClipRevealMethod.invoke(null, v,
2976 left, top, width, height);
2977 } catch (IllegalAccessException e) {
2978 Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
2979 sClipRevealMethod = null;
2980 } catch (InvocationTargetException e) {
2981 Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
2982 sClipRevealMethod = null;
2983 }
2984 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002985 if (opts == null && !Utilities.isLmpOrAbove()) {
2986 opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
Chet Haasea8f996d2015-02-17 12:56:04 -08002987 v.getMeasuredWidth(), v.getMeasuredHeight());
2988 }
Adam Cohen2e52c902015-04-06 13:11:28 -07002989 optsBundle = opts != null ? opts.toBundle() : null;
Adam Cohen6ea3b112014-06-11 11:38:49 -07002990 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002991
2992 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2993 // Could be launching some bookkeeping activity
2994 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002995 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002996 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002997 launcherApps.startActivityForProfile(intent.getComponent(), user,
2998 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002999 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08003000 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003001 } catch (SecurityException e) {
3002 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08003003 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003004 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07003005 "or use the exported attribute for this activity. "
3006 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003007 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08003008 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003009 }
Winson Chungaafa03c2010-06-11 17:34:16 -07003010
Winson Chung8f1eff72015-05-28 17:33:40 -07003011 private boolean startActivitySafely(View v, Intent intent, Object tag) {
Michael Jurka86a720e2012-05-09 11:23:23 -07003012 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07003013 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
3014 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
3015 return false;
3016 }
Michael Jurka86a720e2012-05-09 11:23:23 -07003017 try {
3018 success = startActivity(v, intent, tag);
3019 } catch (ActivityNotFoundException e) {
3020 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
3021 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
3022 }
3023 return success;
3024 }
3025
Adam Cohen268c4752012-06-06 17:47:33 -07003026 /**
3027 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
3028 * in the DragLayer in the exact absolute location of the original FolderIcon.
3029 */
3030 private void copyFolderIconToImage(FolderIcon fi) {
3031 final int width = fi.getMeasuredWidth();
3032 final int height = fi.getMeasuredHeight();
3033
3034 // Lazy load ImageView, Bitmap and Canvas
3035 if (mFolderIconImageView == null) {
3036 mFolderIconImageView = new ImageView(this);
3037 }
3038 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
3039 mFolderIconBitmap.getHeight() != height) {
3040 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
3041 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
3042 }
3043
3044 DragLayer.LayoutParams lp;
3045 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3046 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3047 } else {
3048 lp = new DragLayer.LayoutParams(width, height);
3049 }
3050
Adam Cohen307fe232012-08-16 17:55:58 -07003051 // The layout from which the folder is being opened may be scaled, adjust the starting
3052 // view size by this scale factor.
3053 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003054 lp.customPosition = true;
3055 lp.x = mRectForFolderAnimation.left;
3056 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003057 lp.width = (int) (scale * width);
3058 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003059
3060 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3061 fi.draw(mFolderIconCanvas);
3062 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003063 if (fi.getFolder() != null) {
3064 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3065 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003066 }
Adam Cohen268c4752012-06-06 17:47:33 -07003067 // Just in case this image view is still in the drag layer from a previous animation,
3068 // we remove it and re-add it.
3069 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3070 mDragLayer.removeView(mFolderIconImageView);
3071 }
3072 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003073 if (fi.getFolder() != null) {
3074 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003075 }
Adam Cohen268c4752012-06-06 17:47:33 -07003076 }
3077
Adam Cohen2801caf2011-05-13 20:57:39 -07003078 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003079 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003080 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
3081 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
3082 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
3083
Adam Cohenc51934b2011-07-26 21:07:43 -07003084 FolderInfo info = (FolderInfo) fi.getTag();
3085 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3086 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003087 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3088 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003089 }
3090
Adam Cohen268c4752012-06-06 17:47:33 -07003091 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3092 copyFolderIconToImage(fi);
3093 fi.setVisibility(View.INVISIBLE);
3094
Michael Jurka2ecf9952012-06-18 12:52:28 -07003095 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003096 scaleX, scaleY);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003097 if (Utilities.isLmpOrAbove()) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003098 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3099 }
3100 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003101 oa.start();
3102 }
3103
Adam Cohen268c4752012-06-06 17:47:33 -07003104 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003105 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003106 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3107 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3108 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3109
Adam Cohen268c4752012-06-06 17:47:33 -07003110 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003111
Adam Cohen268c4752012-06-06 17:47:33 -07003112 // We remove and re-draw the FolderIcon in-case it has changed
3113 mDragLayer.removeView(mFolderIconImageView);
3114 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003115 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003116 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003117 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003118 oa.addListener(new AnimatorListenerAdapter() {
3119 @Override
3120 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003121 if (cl != null) {
3122 cl.clearFolderLeaveBehind();
3123 // Remove the ImageView copy of the FolderIcon and make the original visible.
3124 mDragLayer.removeView(mFolderIconImageView);
3125 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003126 }
3127 }
3128 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003129 oa.start();
3130 }
3131
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003132 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003133 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003134 * is animated relative to the specified View. If the View is null, no animation
3135 * is played.
3136 *
3137 * @param folderInfo The FolderInfo describing the folder to open.
3138 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003139 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003140 Folder folder = folderIcon.getFolder();
Sunny Goyalf4066152015-04-15 09:42:19 -07003141 Folder openFolder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3142 if (openFolder != null && openFolder != folder) {
3143 // Close any open folder before opening a folder.
3144 closeFolder();
3145 }
3146
Adam Cohena9cf38f2011-05-02 15:36:58 -07003147 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003148
Adam Cohena9cf38f2011-05-02 15:36:58 -07003149 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003150
Sunny Goyalf4066152015-04-15 09:42:19 -07003151 // While the folder is open, the position of the icon cannot change.
3152 ((CellLayout.LayoutParams) folderIcon.getLayoutParams()).canReorder = false;
3153
Adam Cohen4554ee12011-08-03 16:13:21 -07003154 // Just verify that the folder hasn't already been added to the DragLayer.
3155 // There was a one-off crash where the folder had a parent already.
3156 if (folder.getParent() == null) {
3157 mDragLayer.addView(folder);
3158 mDragController.addDropTarget((DropTarget) folder);
3159 } else {
3160 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3161 folder.getParent() + ").");
3162 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003163 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003164 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003165
3166 // Notify the accessibility manager that this folder "window" has appeared and occluded
3167 // the workspace items
3168 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3169 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003170 }
3171
3172 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003173 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003174 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003175 if (folder.isEditingName()) {
3176 folder.dismissEditingName();
3177 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003178 closeFolder(folder);
3179 }
3180 }
3181
Sunny Goyal83a8f042015-05-19 12:52:12 -07003182 public void closeFolder(Folder folder) {
Adam Cohen4554ee12011-08-03 16:13:21 -07003183 folder.getInfo().opened = false;
3184
3185 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3186 if (parent != null) {
3187 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3188 shrinkAndFadeInFolderIcon(fi);
Sunny Goyalf4066152015-04-15 09:42:19 -07003189 if (fi != null) {
3190 ((CellLayout.LayoutParams) fi.getLayoutParams()).canReorder = true;
3191 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003192 }
3193 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003194
3195 // Notify the accessibility manager that this folder "window" has disappeard and no
3196 // longer occludeds the workspace items
3197 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003198 }
3199
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003200 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003201 if (!isDraggingEnabled()) return false;
3202 if (isWorkspaceLocked()) return false;
3203 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003204
Adam Cohen1697b792013-09-17 19:08:21 -07003205 if (v instanceof Workspace) {
3206 if (!mWorkspace.isInOverviewMode()) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003207 if (!mWorkspace.isTouchActive()) {
3208 showOverviewMode(true);
Adam Cohen93c97562013-09-26 13:48:01 -07003209 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3210 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3211 return true;
3212 } else {
3213 return false;
3214 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003215 } else {
3216 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003217 }
Adam Cohen1697b792013-09-17 19:08:21 -07003218 }
3219
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003220 CellLayout.CellInfo longClickCellInfo = null;
3221 View itemUnderLongClick = null;
3222 if (v.getTag() instanceof ItemInfo) {
3223 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohenc9735cf2015-01-23 16:11:55 -08003224 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003225 itemUnderLongClick = longClickCellInfo.cell;
3226 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003227 }
3228
Winson Chung3d503fb2011-07-13 17:25:49 -07003229 // The hotseat touch handling does not go through Workspace, and we always allow long press
3230 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003231 final boolean inHotseat = isHotseatLayout(v);
Sunny Goyal8e2133b2015-05-06 13:39:07 -07003232 if (!mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003233 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003234 // User long pressed on empty space
3235 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3236 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003237 if (mWorkspace.isInOverviewMode()) {
3238 mWorkspace.startReordering(v);
3239 } else {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003240 showOverviewMode(true);
Adam Cohendedbd962013-07-11 14:21:49 -07003241 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003242 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003243 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3244 mHotseat.getOrderInHotseat(
3245 longClickCellInfo.cellX,
3246 longClickCellInfo.cellY));
3247 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003248 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003249 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003250 }
3251 }
3252 }
3253 return true;
3254 }
3255
Winson Chung3d503fb2011-07-13 17:25:49 -07003256 boolean isHotseatLayout(View layout) {
3257 return mHotseat != null && layout != null &&
3258 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3259 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003260
Winson Chung3d503fb2011-07-13 17:25:49 -07003261 /**
3262 * Returns the CellLayout of the specified container at the specified screen.
3263 */
Sunny Goyal92820592015-03-02 11:31:35 -08003264 public CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003265 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3266 if (mHotseat != null) {
3267 return mHotseat.getLayout();
3268 } else {
3269 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003270 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003271 } else {
Winson Chungb745afb2015-03-02 11:51:23 -08003272 return mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003273 }
3274 }
3275
Winson Chungb745afb2015-03-02 11:51:23 -08003276 /**
3277 * For overridden classes.
3278 */
Daniel Sandler843e8602010-06-07 14:59:01 -04003279 public boolean isAllAppsVisible() {
Winson Chungb745afb2015-03-02 11:51:23 -08003280 return isAppsViewVisible();
3281 }
3282
3283 public boolean isAppsViewVisible() {
3284 return (mState == State.APPS) || (mOnResumeState == State.APPS);
3285 }
3286
3287 public boolean isWidgetsViewVisible() {
3288 return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003289 }
3290
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003291 private void setWorkspaceBackground(int background) {
3292 switch (background) {
3293 case WORKSPACE_BACKGROUND_TRANSPARENT:
3294 getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
3295 break;
3296 case WORKSPACE_BACKGROUND_BLACK:
3297 getWindow().setBackgroundDrawable(null);
3298 break;
3299 default:
3300 getWindow().setBackgroundDrawable(mWorkspaceBackgroundDrawable);
3301 }
Craig Mautner360310b2012-10-26 15:13:08 -07003302 }
3303
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003304 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003305 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3306 int curflags = getWindow().getAttributes().flags
3307 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3308 if (wpflags != curflags) {
3309 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3310 }
Sunny Goyal4a6c6f32015-05-19 12:36:46 -07003311 setWorkspaceBackground(visible ? WORKSPACE_BACKGROUND_GRADIENT : WORKSPACE_BACKGROUND_BLACK);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003312 }
3313
Michael Jurkae326f182011-11-21 14:05:46 -08003314 @Override
3315 public void onTrimMemory(int level) {
3316 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003317 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3318 // The widget preview db can result in holding onto over
3319 // 3MB of memory for caching which isn't necessary.
3320 SQLiteDatabase.releaseMemory();
3321
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003322 // This clears all widget bitmaps from the widget tray
Hyunyoung Song3f471442015-04-08 19:01:34 -07003323 // TODO(hyunyoungs)
Michael Jurkae326f182011-11-21 14:05:46 -08003324 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003325 if (mLauncherCallbacks != null) {
3326 mLauncherCallbacks.onTrimMemory(level);
3327 }
Michael Jurkae326f182011-11-21 14:05:46 -08003328 }
3329
Winson Chungb745afb2015-03-02 11:51:23 -08003330 @Override
3331 public void onStateTransitionHideSearchBar() {
3332 // Hide the search bar
3333 if (mSearchDropTargetBar != null) {
3334 mSearchDropTargetBar.hideSearchBar(false /* animated */);
3335 }
Adam Cohened66b2b2012-01-23 17:28:51 -08003336 }
3337
Winson Chung5f4e0fd2015-05-22 11:12:27 -07003338 public void showWorkspace(boolean animated) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003339 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated, null,
3340 true);
Adam Cohened307df2013-10-02 09:37:31 -07003341 }
3342
Sunny Goyal83a8f042015-05-19 12:52:12 -07003343 public void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Winson Chungdc61c4d2015-04-20 18:26:57 -07003344 showWorkspace(WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
3345 onCompleteRunnable, true);
3346 }
3347
3348 protected void showWorkspace(int snapToPage, boolean animated) {
3349 showWorkspace(snapToPage, animated, null, true);
3350 }
3351
3352 void showWorkspace(int snapToPage, boolean animated, Runnable onCompleteRunnable,
3353 boolean notifyLauncherCallbacks) {
Winson Chung0f785722015-04-08 10:27:49 -07003354 boolean changed = mState != State.WORKSPACE ||
3355 mWorkspace.getState() != Workspace.State.NORMAL;
3356 if (changed) {
Winson Chung2d75f122013-09-23 16:53:31 -07003357 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003358 mWorkspace.setVisibility(View.VISIBLE);
Winson Chungb745afb2015-03-02 11:51:23 -08003359 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.NORMAL,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003360 snapToPage, animated, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003361
Winson Chungc7d2b602012-05-16 17:02:20 -07003362 // Show the search bar (only animate if we were showing the drop target bar in spring
3363 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003364 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003365 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003366 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003367
Michael Jurkab3e22d92011-10-31 15:58:33 -07003368 // Set focus to the AppsCustomize button
3369 if (mAllAppsButton != null) {
3370 mAllAppsButton.requestFocus();
3371 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003372 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003373
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003374 // Change the state *after* we've called all the transition code
3375 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003376
Winson Chung5fb63472011-02-02 17:03:37 -08003377 // Resume the auto-advance of widgets
3378 mUserPresent = true;
Winson Chungb745afb2015-03-02 11:51:23 -08003379 updateAutoAdvanceState();
Winson Chung5fb63472011-02-02 17:03:37 -08003380
Winson Chung0f785722015-04-08 10:27:49 -07003381 if (changed) {
3382 // Send an accessibility event to announce the context change
3383 getWindow().getDecorView()
3384 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Winson Chungcd99cd32015-04-29 11:03:24 -07003385 if (notifyLauncherCallbacks) {
3386 // Dismiss all apps when the workspace is shown
Winson Chung83f59ab2015-05-05 17:21:58 -07003387 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003388 mLauncherCallbacks.onAllAppsHidden();
3389 }
3390 }
Winson Chung0f785722015-04-08 10:27:49 -07003391 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01003392 }
3393
Adam Cohened307df2013-10-02 09:37:31 -07003394 void showOverviewMode(boolean animated) {
3395 mWorkspace.setVisibility(View.VISIBLE);
Winson Chungb745afb2015-03-02 11:51:23 -08003396 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.OVERVIEW,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003397 WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, animated,
3398 null /* onCompleteRunnable */);
Adam Cohened307df2013-10-02 09:37:31 -07003399 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04003400 }
3401
Winson Chungb745afb2015-03-02 11:51:23 -08003402 /**
3403 * Shows the apps view.
3404 */
Winson Chung4ac30062015-05-08 17:34:17 -07003405 void showAppsView(boolean animated, boolean resetListToTop, boolean updatePredictedApps) {
Winson Chungb745afb2015-03-02 11:51:23 -08003406 if (resetListToTop) {
3407 mAppsView.scrollToTop();
3408 }
Winson Chung4ac30062015-05-08 17:34:17 -07003409 if (updatePredictedApps) {
3410 tryAndUpdatePredictedApps();
3411 }
Winson Chungb745afb2015-03-02 11:51:23 -08003412 showAppsOrWidgets(animated, State.APPS);
3413 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003414
Winson Chungb745afb2015-03-02 11:51:23 -08003415 /**
3416 * Shows the widgets view.
3417 */
3418 void showWidgetsView(boolean animated, boolean resetPageToZero) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003419 if (LOGD) Log.d(TAG, "showWidgetsView:" + animated + " resetPageToZero:" + resetPageToZero);
Winson Chung82963d52013-10-09 11:20:57 -07003420 if (resetPageToZero) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003421 mWidgetsView.scrollToTop();
Winson Chung82963d52013-10-09 11:20:57 -07003422 }
Winson Chungb745afb2015-03-02 11:51:23 -08003423 showAppsOrWidgets(animated, State.WIDGETS);
Hyunyoung Song3f471442015-04-08 19:01:34 -07003424
3425 mWidgetsView.post(new Runnable() {
Adam Cohendcc5e712014-06-23 15:38:55 -04003426 @Override
3427 public void run() {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003428 mWidgetsView.requestFocus();
Adam Cohendcc5e712014-06-23 15:38:55 -04003429 }
3430 });
Winson Chungb745afb2015-03-02 11:51:23 -08003431 }
3432
3433 /**
3434 * Sets up the transition to show the apps/widgets view.
Hyunyoung Songb7900832015-05-15 16:29:45 -07003435 *
3436 * @return whether the current from and to state allowed this operation
Winson Chungb745afb2015-03-02 11:51:23 -08003437 */
Hyunyoung Songb7900832015-05-15 16:29:45 -07003438 // TODO: calling method should use the return value so that when {@code false} is returned
3439 // the workspace transition doesn't fall into invalid state.
3440 private boolean showAppsOrWidgets(boolean animated, State toState) {
3441 if (mState != State.WORKSPACE && mState != State.APPS_SPRING_LOADED &&
3442 mState != State.WIDGETS_SPRING_LOADED) {
3443 return false;
3444 }
3445 if (toState != State.APPS && toState != State.WIDGETS) {
3446 return false;
3447 }
Winson Chungb745afb2015-03-02 11:51:23 -08003448
3449 if (toState == State.APPS) {
3450 mStateTransitionAnimation.startAnimationToAllApps(animated);
Winson Chung83f59ab2015-05-05 17:21:58 -07003451 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chung0f785722015-04-08 10:27:49 -07003452 mLauncherCallbacks.onAllAppsShown();
3453 }
Winson Chungb745afb2015-03-02 11:51:23 -08003454 } else {
3455 mStateTransitionAnimation.startAnimationToWidgets(animated);
3456 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003457
Michael Jurkab3e22d92011-10-31 15:58:33 -07003458 // Change the state *after* we've called all the transition code
Winson Chungb745afb2015-03-02 11:51:23 -08003459 mState = toState;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003460
3461 // Pause the auto-advance of widgets until we are out of AllApps
3462 mUserPresent = false;
Winson Chungb745afb2015-03-02 11:51:23 -08003463 updateAutoAdvanceState();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003464 closeFolder();
3465
3466 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003467 getWindow().getDecorView()
3468 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Hyunyoung Songb7900832015-05-15 16:29:45 -07003469 return true;
Michael Jurkab3e22d92011-10-31 15:58:33 -07003470 }
3471
Winson Chungcd99cd32015-04-29 11:03:24 -07003472 /**
3473 * Updates the workspace and interaction state on state change, and return the animation to this
3474 * new state.
3475 */
3476 public Animator startWorkspaceStateChangeAnimation(Workspace.State toState, int toPage,
3477 boolean animated, HashMap<View, Integer> layerViews) {
3478 Workspace.State fromState = mWorkspace.getState();
3479 Animator anim = mWorkspace.setStateWithAnimation(toState, toPage, animated, layerViews);
3480 updateInteraction(fromState, toState);
3481 return anim;
3482 }
3483
Hyunyoung Song3f471442015-04-08 19:01:34 -07003484 public void enterSpringLoadedDragMode() {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003485 if (LOGD) Log.d(TAG, String.format("enterSpringLoadedDragMode [mState=%s", mState.name()));
Winson Chungb745afb2015-03-02 11:51:23 -08003486 if (mState == State.WORKSPACE || mState == State.APPS_SPRING_LOADED ||
3487 mState == State.WIDGETS_SPRING_LOADED) {
3488 return;
Winson Chungb26f3d62011-06-02 10:49:29 -07003489 }
Winson Chungb745afb2015-03-02 11:51:23 -08003490
3491 mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.SPRING_LOADED,
Winson Chungdc61c4d2015-04-20 18:26:57 -07003492 WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE, true /* animated */,
3493 null /* onCompleteRunnable */);
Winson Chungb745afb2015-03-02 11:51:23 -08003494 mState = isAppsViewVisible() ? State.APPS_SPRING_LOADED : State.WIDGETS_SPRING_LOADED;
Michael Jurkad3ef3062010-11-23 16:23:58 -08003495 }
Adam Cohen7777d962011-08-18 18:58:38 -07003496
Hyunyoung Song3f471442015-04-08 19:01:34 -07003497 public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003498 final Runnable onCompleteRunnable) {
Winson Chungb745afb2015-03-02 11:51:23 -08003499 if (mState != State.APPS_SPRING_LOADED && mState != State.WIDGETS_SPRING_LOADED) return;
Winson Chung09bfc452011-09-09 11:30:20 -07003500
Winson Chungcd99cd32015-04-29 11:03:24 -07003501 if (successfulDrop) {
3502 // We need to trigger all apps hidden to notify search to update itself before the
3503 // delayed call to showWorkspace below
Winson Chung83f59ab2015-05-05 17:21:58 -07003504 if (!Launcher.DISABLE_ALL_APPS_SEARCH_INTEGRATION && mLauncherCallbacks != null) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003505 mLauncherCallbacks.onAllAppsHidden();
3506 }
3507 }
3508
Winson Chunge7a03942011-08-05 15:05:12 -07003509 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003510 @Override
3511 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003512 if (successfulDrop) {
Hyunyoung Song3f471442015-04-08 19:01:34 -07003513 // TODO(hyunyoungs): verify if this hack is still needed, if not, delete.
3514 //
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003515 // Before we show workspace, hide all apps again because
3516 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3517 // clean up our state transition functions
Hyunyoung Song3f471442015-04-08 19:01:34 -07003518 mWidgetsView.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003519 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003520 } else {
3521 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003522 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003523 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003524 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003525 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003526
Michael Jurkad3ef3062010-11-23 16:23:58 -08003527 void exitSpringLoadedDragMode() {
Winson Chungb745afb2015-03-02 11:51:23 -08003528 if (mState == State.APPS_SPRING_LOADED) {
Winson Chung4ac30062015-05-08 17:34:17 -07003529 showAppsView(true /* animated */, false /* resetListToTop */,
3530 false /* updatePredictedApps */);
Winson Chungb745afb2015-03-02 11:51:23 -08003531 } else if (mState == State.WIDGETS_SPRING_LOADED) {
Winson Chungcd99cd32015-04-29 11:03:24 -07003532 showWidgetsView(true, false);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003533 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003534 }
3535
Winson Chung4ac30062015-05-08 17:34:17 -07003536 /**
3537 * Updates the set of predicted apps if it hasn't been updated since the last time Launcher was
3538 * resumed.
3539 */
3540 private void tryAndUpdatePredictedApps() {
3541 if (mLauncherCallbacks != null) {
3542 List<ComponentName> apps = mLauncherCallbacks.getPredictedApps();
3543 if (!apps.isEmpty()) {
3544 mAppsView.setPredictedApps(apps);
3545 }
3546 }
3547 }
3548
Michael Jurkab3e22d92011-10-31 15:58:33 -07003549 void lockAllApps() {
3550 // TODO
3551 }
3552
3553 void unlockAllApps() {
3554 // TODO
3555 }
3556
Sunny Goyal594d76d2014-11-06 10:12:54 -08003557 protected void disableVoiceButtonProxy(boolean disable) {
3558 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003559 }
3560
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003561 public View getOrCreateQsbBar() {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003562 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
3563 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003564 }
3565
Adam Cohen24ce0b32014-01-14 16:18:14 -08003566 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003567 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3568 if (searchProvider == null) {
3569 return null;
3570 }
3571
3572 Bundle opts = new Bundle();
3573 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
Adam Coheneb8e2822015-02-20 16:38:48 +00003574 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003575
3576 SharedPreferences sp = getSharedPreferences(
3577 LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
3578 int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003579 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003580 if (!searchProvider.provider.flattenToString().equals(
3581 sp.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003582 || (widgetInfo == null)
3583 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003584 // A valid widget is not already bound.
3585 if (widgetId > -1) {
3586 mAppWidgetHost.deleteAppWidgetId(widgetId);
3587 widgetId = -1;
3588 }
3589
3590 // Try to bind a new widget
3591 widgetId = mAppWidgetHost.allocateAppWidgetId();
3592
3593 if (!AppWidgetManagerCompat.getInstance(this)
3594 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3595 mAppWidgetHost.deleteAppWidgetId(widgetId);
3596 widgetId = -1;
3597 }
3598
3599 sp.edit()
3600 .putInt(QSB_WIDGET_ID, widgetId)
3601 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
3602 .commit();
3603 }
3604
3605 if (widgetId != -1) {
3606 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
3607 mQsb.updateAppWidgetOptions(opts);
3608 mQsb.setPadding(0, 0, 0, 0);
3609 mSearchDropTargetBar.addView(mQsb);
Sunny Goyal64b3fcc2015-03-04 13:54:52 -08003610 mSearchDropTargetBar.setQsbSearchBar(mQsb);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003611 }
Cristina Stancu476493b2013-08-07 17:20:14 +01003612 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003613 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003614 }
3615
Sunny Goyal22235bc2015-04-03 09:23:43 -07003616 private void reinflateQSBIfNecessary() {
3617 if (mQsb instanceof LauncherAppWidgetHostView &&
3618 ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
3619 mSearchDropTargetBar.removeView(mQsb);
3620 mQsb = null;
3621 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
3622 }
3623 }
3624
Michael Jurkad7c28052012-04-27 15:43:36 -07003625 @Override
3626 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003627 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003628 final List<CharSequence> text = event.getText();
3629 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003630 // Populate event with a fake title based on the current state.
Winson Chungb745afb2015-03-02 11:51:23 -08003631 if (mState == State.APPS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003632 text.add(getString(R.string.all_apps_button_label));
Winson Chungb745afb2015-03-02 11:51:23 -08003633 } else if (mState == State.WIDGETS) {
Sunny Goyalc525d802015-04-29 11:05:34 -07003634 text.add(getString(R.string.widget_button_text));
alanv1d4fde62012-10-17 13:15:47 -07003635 } else {
3636 text.add(getString(R.string.all_apps_home_button_label));
3637 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003638 return result;
3639 }
3640
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003641 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003642 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003643 */
Adam Cohen091440a2015-03-18 14:16:05 -07003644 @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003645 @Override
3646 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003647 closeSystemDialogs();
3648 }
3649 }
3650
3651 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003652 * Receives notifications whenever the appwidgets are reset.
3653 */
3654 private class AppWidgetResetObserver extends ContentObserver {
3655 public AppWidgetResetObserver() {
3656 super(new Handler());
3657 }
3658
3659 @Override
3660 public void onChange(boolean selfChange) {
3661 onAppWidgetReset();
3662 }
3663 }
3664
3665 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003666 * If the activity is currently paused, signal that we need to run the passed Runnable
3667 * in onResume.
3668 *
3669 * This needs to be called from incoming places where resources might have been loaded
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003670 * while the activity is paused. That is because the Configuration (e.g., rotation) might be
3671 * wrong when we're not running, and if the activity comes back to what the configuration was
3672 * when we were paused, activity is not restarted.
Michael Jurka7607c2f2013-04-03 14:33:19 -07003673 *
3674 * Implementation of the method from LauncherModel.Callbacks.
3675 *
Hyunyoung Song8821ca92015-05-04 16:28:20 -07003676 * @return {@code true} if we are currently paused. The caller might be able to skip some work
Michael Jurka7607c2f2013-04-03 14:33:19 -07003677 */
Rahul Chaturvedi799aa042015-06-01 21:26:41 -04003678 @Thunk boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003679 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003680 if (LOGD) Log.d(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003681 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003682 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003683 }
3684 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003685 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003686 return true;
3687 } else {
3688 return false;
3689 }
3690 }
3691
Michael Jurkac402cd92013-05-20 15:49:32 +02003692 private boolean waitUntilResume(Runnable run) {
3693 return waitUntilResume(run, false);
3694 }
3695
Michael Jurka1e2f4652013-07-08 18:03:46 -07003696 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003697 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003698 }
3699
Michael Jurka7607c2f2013-04-03 14:33:19 -07003700 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003701 * If the activity is currently paused, signal that we need to re-run the loader
3702 * in onResume.
3703 *
3704 * This needs to be called from incoming places where resources might have been loaded
3705 * while we are paused. That is becaues the Configuration might be wrong
3706 * when we're not running, and if it comes back to what it was when we
3707 * were paused, we are not restarted.
3708 *
3709 * Implementation of the method from LauncherModel.Callbacks.
3710 *
3711 * @return true if we are currently paused. The caller might be able to
3712 * skip some work in that case since we will come back again.
3713 */
3714 public boolean setLoadOnResume() {
3715 if (mPaused) {
Sunny Goyal2bba4c32015-05-18 15:42:48 -07003716 if (LOGD) Log.d(TAG, "setLoadOnResume");
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003717 mOnResumeNeedsLoad = true;
3718 return true;
3719 } else {
3720 return false;
3721 }
3722 }
3723
3724 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003725 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003726 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003727 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003728 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003729 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003730 } else {
3731 return SCREEN_COUNT / 2;
3732 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003733 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003734
Joe Onorato9c1289c2009-08-17 11:03:03 -04003735 /**
3736 * Refreshes the shortcuts shown on the workspace.
3737 *
3738 * Implementation of the method from LauncherModel.Callbacks.
3739 */
3740 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003741 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003742
Michael Jurka7607c2f2013-04-03 14:33:19 -07003743 // If we're starting binding all over again, clear any bind calls we'd postponed in
3744 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3745 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003746 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003747
Winson Chungd64d1762013-08-20 14:37:16 -07003748 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003749 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003750 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003751
Michael Jurka05bf6442011-11-30 20:28:53 -08003752 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003753 if (mHotseat != null) {
3754 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003755 }
3756 }
3757
Adam Cohendcd297f2013-06-18 13:13:40 -07003758 @Override
3759 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003760 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003761
Adam Cohen5084cba2013-09-03 12:01:16 -07003762 // If there are no screens, we need to have an empty screen
3763 if (orderedScreenIds.size() == 0) {
3764 mWorkspace.addExtraEmptyScreen();
3765 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003766
3767 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003768 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003769 if (hasCustomContentToLeft()) {
3770 mWorkspace.createCustomContentContainer();
3771 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003772 }
Winson Chung64359a52013-07-08 17:17:08 -07003773 }
3774
3775 @Override
3776 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003777 // Log to disk
3778 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3779 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3780 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003781 int count = orderedScreenIds.size();
3782 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003783 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003784 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003785 }
3786
Adam Cohen39a06042013-07-19 14:30:12 -07003787 private boolean shouldShowWeightWatcher() {
3788 String spKey = LauncherAppState.getSharedPreferencesKey();
3789 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003790 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003791
3792 return show;
3793 }
3794
3795 private void toggleShowWeightWatcher() {
3796 String spKey = LauncherAppState.getSharedPreferencesKey();
3797 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3798 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3799
3800 show = !show;
3801
3802 SharedPreferences.Editor editor = sp.edit();
3803 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3804 editor.commit();
3805
3806 if (mWeightWatcher != null) {
3807 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3808 }
3809 }
3810
Winson Chungd64d1762013-08-20 14:37:16 -07003811 public void bindAppsAdded(final ArrayList<Long> newScreens,
3812 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003813 final ArrayList<ItemInfo> addAnimated,
3814 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003815 Runnable r = new Runnable() {
3816 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003817 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003818 }
3819 };
3820 if (waitUntilResume(r)) {
3821 return;
3822 }
3823
Winson Chungd64d1762013-08-20 14:37:16 -07003824 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003825 if (newScreens != null) {
3826 bindAddScreens(newScreens);
3827 }
Winson Chungd64d1762013-08-20 14:37:16 -07003828
3829 // We add the items without animation on non-visible pages, and with
3830 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003831 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003832 bindItems(addNotAnimated, 0,
3833 addNotAnimated.size(), false);
3834 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003835 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003836 bindItems(addAnimated, 0,
3837 addAnimated.size(), true);
3838 }
Winson Chungc58497e2013-09-03 17:48:37 -07003839
Winson Chung87412982013-10-03 18:34:14 -07003840 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003841 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003842
Winson Chungb745afb2015-03-02 11:51:23 -08003843 if (addedApps != null && mAppsView != null) {
3844 mAppsView.addApps(addedApps);
Winson Chungc58497e2013-09-03 17:48:37 -07003845 }
Winson Chungd64d1762013-08-20 14:37:16 -07003846 }
3847
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003848 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003849 * Bind the items start-end from the list.
3850 *
3851 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003852 */
Winson Chung64359a52013-07-08 17:17:08 -07003853 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3854 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003855 Runnable r = new Runnable() {
3856 public void run() {
3857 bindItems(shortcuts, start, end, forceAnimateIcons);
3858 }
3859 };
3860 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003861 return;
3862 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003863
Winson Chungf0c6ae02012-03-21 16:10:31 -07003864 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003865 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3866 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003867 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003868 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003869 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003870 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003871 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003872
3873 // Short circuit if we are loading dock items for a configuration which has no dock
3874 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3875 mHotseat == null) {
3876 continue;
3877 }
3878
Joe Onorato9c1289c2009-08-17 11:03:03 -04003879 switch (item.itemType) {
3880 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3881 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003882 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003883 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003884
Winson Chung64359a52013-07-08 17:17:08 -07003885 /*
3886 * TODO: FIX collision case
3887 */
Winson Chungce376632013-07-11 16:12:41 -07003888 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3889 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3890 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07003891 View v = cl.getChildAt(item.cellX, item.cellY);
3892 Object tag = v.getTag();
3893 String desc = "Collision while binding workspace item: " + item
3894 + ". Collides with " + tag;
3895 if (LauncherAppState.isDogfoodBuild()) {
3896 throw (new RuntimeException(desc));
3897 } else {
3898 Log.d(TAG, desc);
3899 }
Winson Chungce376632013-07-11 16:12:41 -07003900 }
Winson Chung64359a52013-07-08 17:17:08 -07003901 }
3902
Adam Cohendcd297f2013-06-18 13:13:40 -07003903 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3904 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003905 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003906 // Animate all the applications up now
3907 shortcut.setAlpha(0f);
3908 shortcut.setScaleX(0f);
3909 shortcut.setScaleY(0f);
3910 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003911 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003912 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003913 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003914 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003915 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003916 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003917 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003918 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3919 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003920 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003921 default:
3922 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003923 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003924 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003925
Winson Chung997a9232013-07-24 15:33:46 -07003926 if (animateIcons) {
3927 // Animate to the correct page
3928 if (newShortcutsScreenId > -1) {
3929 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003930 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003931 final Runnable startBounceAnimRunnable = new Runnable() {
3932 public void run() {
3933 anim.playTogether(bounceAnims);
3934 anim.start();
3935 }
3936 };
Winson Chung997a9232013-07-24 15:33:46 -07003937 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003938 // We post the animation slightly delayed to prevent slowdowns
3939 // when we are loading right after we return to launcher.
3940 mWorkspace.postDelayed(new Runnable() {
3941 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00003942 if (mWorkspace != null) {
3943 mWorkspace.snapToPage(newScreenIndex);
3944 mWorkspace.postDelayed(startBounceAnimRunnable,
3945 NEW_APPS_ANIMATION_DELAY);
3946 }
Winson Chung94d67682013-09-25 16:29:40 -07003947 }
3948 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003949 } else {
3950 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003951 }
3952 }
Winson Chung64359a52013-07-08 17:17:08 -07003953 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003954 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003955 }
3956
Joe Onorato9c1289c2009-08-17 11:03:03 -04003957 /**
3958 * Implementation of the method from LauncherModel.Callbacks.
3959 */
Sunny Goyale2df0622015-04-24 11:27:00 -07003960 public void bindFolders(final LongArrayMap<FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003961 Runnable r = new Runnable() {
3962 public void run() {
3963 bindFolders(folders);
3964 }
3965 };
3966 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003967 return;
3968 }
Sunny Goyale2df0622015-04-24 11:27:00 -07003969 sFolders = folders.clone();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003970 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003971
3972 /**
3973 * Add the views for a widget to the workspace.
3974 *
3975 * Implementation of the method from LauncherModel.Callbacks.
3976 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003977 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003978 Runnable r = new Runnable() {
3979 public void run() {
3980 bindAppWidget(item);
3981 }
3982 };
3983 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003984 return;
3985 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003986
Daniel Sandler843e8602010-06-07 14:59:01 -04003987 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3988 if (DEBUG_WIDGETS) {
3989 Log.d(TAG, "bindAppWidget: " + item);
3990 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003991 final Workspace workspace = mWorkspace;
3992
Adam Cohen59400422014-03-05 18:07:04 -08003993 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee26ace122015-03-16 19:41:43 +00003994 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08003995
Sunny Goyal9b4b0812014-10-08 10:47:28 -07003996 if (!mIsSafeModeEnabled
3997 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
3998 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
Sunny Goyalff572272014-07-23 13:58:07 -07003999 if (appWidgetInfo == null) {
4000 if (DEBUG_WIDGETS) {
4001 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4002 + " belongs to component " + item.providerName
4003 + ", as the povider is null");
4004 }
4005 LauncherModel.deleteItemFromDatabase(this, item);
4006 return;
4007 }
4008 // Note: This assumes that the id remap broadcast is received before this step.
4009 // If that is not the case, the id remap will be ignored and user may see the
4010 // click to setup view.
Adam Cohen2e6da152015-05-06 11:42:25 -07004011 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null);
Sunny Goyalff572272014-07-23 13:58:07 -07004012 pendingInfo.spanX = item.spanX;
4013 pendingInfo.spanY = item.spanY;
4014 pendingInfo.minSpanX = item.minSpanX;
4015 pendingInfo.minSpanY = item.minSpanY;
Hyunyoung Song3f471442015-04-08 19:01:34 -07004016 Bundle options = null;
Hyunyoung Songb99ff3e2015-04-23 15:17:50 -07004017 WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07004018
Sunny Goyalff572272014-07-23 13:58:07 -07004019 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004020 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4021 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004022
4023 // TODO consider showing a permission dialog when the widget is clicked.
4024 if (!success) {
4025 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4026 if (DEBUG_WIDGETS) {
4027 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4028 + " belongs to component " + item.providerName
4029 + ", as the launcher is unable to bing a new widget id");
4030 }
4031 LauncherModel.deleteItemFromDatabase(this, item);
4032 return;
4033 }
4034
4035 item.appWidgetId = newWidgetId;
4036
4037 // If the widget has a configure activity, it is still needs to set it up, otherwise
4038 // the widget is ready to go.
4039 item.restoreStatus = (appWidgetInfo.configure == null)
4040 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4041 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4042
4043 LauncherModel.updateItemInDatabase(this, item);
4044 }
4045
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004046 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004047 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004048 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004049 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4050 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004051 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004052
Sunny Goyal651077b2014-06-30 14:15:31 -07004053 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4054 } else {
4055 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004056 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4057 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004058 view.updateIcon(mIconCache);
4059 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004060 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004061 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004062 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004063
Joe Onorato9c1289c2009-08-17 11:03:03 -04004064 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004065 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004066
Adam Cohendcd297f2013-06-18 13:13:40 -07004067 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004068 item.cellY, item.spanX, item.spanY, false);
Adam Cohen59400422014-03-05 18:07:04 -08004069 if (!item.isCustomWidget()) {
4070 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4071 }
Adam Cohended9f8d2010-11-03 13:25:16 -07004072
Joe Onorato9c1289c2009-08-17 11:03:03 -04004073 workspace.requestLayout();
4074
Daniel Sandler843e8602010-06-07 14:59:01 -04004075 if (DEBUG_WIDGETS) {
4076 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4077 + (SystemClock.uptimeMillis()-start) + "ms");
4078 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004079 }
4080
Sunny Goyalff572272014-07-23 13:58:07 -07004081 /**
4082 * Restores a pending widget.
4083 *
4084 * @param appWidgetId The app widget id
4085 * @param cellInfo The position on screen where to create the widget.
4086 */
4087 private void completeRestoreAppWidget(final int appWidgetId) {
4088 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4089 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4090 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4091 return;
4092 }
4093
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004094 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004095 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4096
4097 mWorkspace.reinflateWidgetsIfNecessary();
4098 LauncherModel.updateItemInDatabase(this, info);
4099 }
4100
Adam Cohen1462de32012-07-24 22:34:36 -07004101 public void onPageBoundSynchronously(int page) {
4102 mSynchronouslyBoundPages.add(page);
4103 }
4104
Joe Onorato9c1289c2009-08-17 11:03:03 -04004105 /**
4106 * Callback saying that there aren't any more items to bind.
4107 *
4108 * Implementation of the method from LauncherModel.Callbacks.
4109 */
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004110 public void finishBindingItems() {
Winson Chungd64d1762013-08-20 14:37:16 -07004111 Runnable r = new Runnable() {
4112 public void run() {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004113 finishBindingItems();
Winson Chungd64d1762013-08-20 14:37:16 -07004114 }
4115 };
4116 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004117 return;
4118 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004119 if (mSavedState != null) {
4120 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004121 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004122 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004123 mSavedState = null;
4124 }
4125
Adam Cohen1462de32012-07-24 22:34:36 -07004126 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004127
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004128 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004129 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004130
4131 // If we received the result of any pending adds while the loader was running (e.g. the
4132 // widget configuration forced an orientation change), process them now.
4133 if (sPendingAddItem != null) {
4134 final long screenId = completeAdd(sPendingAddItem);
4135
4136 // TODO: this moves the user to the page where the pending item was added. Ideally,
4137 // the screen would be guaranteed to exist after bind, and the page would be set through
4138 // the workspace restore process.
4139 mWorkspace.post(new Runnable() {
4140 @Override
4141 public void run() {
4142 mWorkspace.snapToScreenId(screenId);
4143 }
4144 });
4145 sPendingAddItem = null;
4146 }
4147
Sunny Goyal756adbc2015-04-16 15:20:51 -07004148 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Adam Cohen9211d422014-10-07 18:14:53 -07004149
4150 if (mLauncherCallbacks != null) {
Sunny Goyal66cfdc22015-02-02 13:01:51 -08004151 mLauncherCallbacks.finishBindingItems(false);
Adam Cohen9211d422014-10-07 18:14:53 -07004152 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004153 }
4154
Adam Cohen3ed316a2014-07-23 18:21:20 -07004155 private void sendLoadingCompleteBroadcastIfNecessary() {
4156 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4157 String permission =
4158 getResources().getString(R.string.receive_first_load_broadcast_permission);
4159 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4160 sendBroadcast(intent, permission);
4161 SharedPreferences.Editor editor = mSharedPrefs.edit();
4162 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4163 editor.apply();
4164 }
4165 }
4166
Winson Chunga0b7e862013-09-05 16:03:15 -07004167 public boolean isAllAppsButtonRank(int rank) {
4168 if (mHotseat != null) {
4169 return mHotseat.isAllAppsButtonRank(rank);
4170 }
4171 return false;
4172 }
4173
Winson Chunga2413752012-04-03 14:22:34 -07004174 private boolean canRunNewAppsAnimation() {
4175 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4176 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4177 }
4178
Winson Chungc9168342013-06-26 14:54:55 -07004179 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4180 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4181 PropertyValuesHolder.ofFloat("alpha", 1f),
4182 PropertyValuesHolder.ofFloat("scaleX", 1f),
4183 PropertyValuesHolder.ofFloat("scaleY", 1f));
4184 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4185 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
Sunny Goyal5a1f53b2015-05-27 10:24:24 -07004186 bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
Winson Chungc9168342013-06-26 14:54:55 -07004187 return bounceAnim;
4188 }
4189
Adam Cohen27772732013-11-11 14:00:56 +00004190 public boolean useVerticalBarLayout() {
Sunny Goyaldfaccf62015-05-11 16:30:44 -07004191 return mDeviceProfile.isVerticalBarLayout();
Adam Cohen27772732013-11-11 14:00:56 +00004192 }
4193
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004194 protected Rect getSearchBarBounds() {
Sunny Goyalc6205602015-05-21 20:46:33 -07004195 return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004196 }
4197
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004198 public void bindSearchablesChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004199 if (mSearchDropTargetBar == null) {
4200 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004201 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004202 if (mQsb != null) {
4203 mSearchDropTargetBar.removeView(mQsb);
4204 mQsb = null;
4205 }
Adam Cohenb0df1b02015-03-18 22:21:40 -07004206 mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004207 }
4208
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004209 /**
Winson Chungbb785c62015-05-05 10:05:08 -07004210 * A runnable that we can dequeue and re-enqueue when all applications are bound (to prevent
4211 * multiple calls to bind the same list.)
4212 */
4213 @Thunk ArrayList<AppInfo> mTmpAppsList;
4214 private Runnable mBindAllApplicationsRunnable = new Runnable() {
4215 public void run() {
4216 bindAllApplications(mTmpAppsList);
4217 mTmpAppsList = null;
4218 }
4219 };
4220
4221 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004222 * Add the icons for all apps.
4223 *
4224 * Implementation of the method from LauncherModel.Callbacks.
4225 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004226 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungbb785c62015-05-05 10:05:08 -07004227 if (waitUntilResume(mBindAllApplicationsRunnable, true)) {
4228 mTmpAppsList = apps;
4229 return;
4230 }
4231
Winson Chungb745afb2015-03-02 11:51:23 -08004232 if (mAppsView != null) {
4233 mAppsView.setApps(apps);
4234 }
Adam Cohen9211d422014-10-07 18:14:53 -07004235 if (mLauncherCallbacks != null) {
4236 mLauncherCallbacks.bindAllApplications(apps);
4237 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004238 }
4239
4240 /**
4241 * A package was updated.
4242 *
4243 * Implementation of the method from LauncherModel.Callbacks.
4244 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004245 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004246 Runnable r = new Runnable() {
4247 public void run() {
4248 bindAppsUpdated(apps);
4249 }
4250 };
4251 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004252 return;
4253 }
4254
Winson Chungb745afb2015-03-02 11:51:23 -08004255 if (mAppsView != null) {
4256 mAppsView.updateApps(apps);
Winson Chungc58497e2013-09-03 17:48:37 -07004257 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004258 }
4259
Sunny Goyal4390ace2014-10-13 11:33:11 -07004260 @Override
4261 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4262 Runnable r = new Runnable() {
4263 public void run() {
4264 bindWidgetsRestored(widgets);
4265 }
4266 };
4267 if (waitUntilResume(r)) {
4268 return;
4269 }
4270 mWorkspace.widgetsRestored(widgets);
4271 }
4272
Joe Onorato9c1289c2009-08-17 11:03:03 -04004273 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004274 * Some shortcuts were updated in the background.
4275 *
4276 * Implementation of the method from LauncherModel.Callbacks.
4277 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004278 @Override
4279 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4280 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004281 Runnable r = new Runnable() {
4282 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004283 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004284 }
4285 };
4286 if (waitUntilResume(r)) {
4287 return;
4288 }
4289
Sunny Goyal4390ace2014-10-13 11:33:11 -07004290 if (!updated.isEmpty()) {
4291 mWorkspace.updateShortcuts(updated);
4292 }
4293
4294 if (!removed.isEmpty()) {
4295 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4296 for (ShortcutInfo si : removed) {
4297 removedComponents.add(si.getTargetComponent());
4298 }
4299 mWorkspace.removeItemsByComponentName(removedComponents, user);
4300 // Notify the drag controller
4301 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004302 }
4303 }
4304
4305 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004306 * Update the state of a package, typically related to install state.
4307 *
4308 * Implementation of the method from LauncherModel.Callbacks.
4309 */
Sunny Goyale755d462014-07-22 13:48:29 -07004310 @Override
Sunny Goyal756adbc2015-04-16 15:20:51 -07004311 public void bindRestoreItemsChange(final HashSet<ItemInfo> updates) {
4312 Runnable r = new Runnable() {
4313 public void run() {
4314 bindRestoreItemsChange(updates);
4315 }
4316 };
4317 if (waitUntilResume(r)) {
4318 return;
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004319 }
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004320
Sunny Goyal756adbc2015-04-16 15:20:51 -07004321 mWorkspace.updateRestoreItems(updates);
Sunny Goyala22666f2014-09-18 13:25:15 -07004322 }
4323
4324 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004325 * A package was uninstalled. We take both the super set of packageNames
4326 * in addition to specific applications to remove, the reason being that
4327 * this can be called when a package is updated as well. In that scenario,
4328 * we only remove specific components from the workspace, where as
4329 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004330 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004331 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004332 * Implementation of the method from LauncherModel.Callbacks.
4333 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004334 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004335 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004336 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004337 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004338 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004339 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004340 }
Winson Chungd64d1762013-08-20 14:37:16 -07004341 };
4342 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004343 return;
4344 }
4345
Sunny Goyal1a745e82014-10-02 15:58:31 -07004346 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004347 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4348 for (AppInfo info : appInfos) {
4349 removedComponents.add(info.componentName);
4350 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004351 if (!packageNames.isEmpty()) {
4352 mWorkspace.removeItemsByPackageName(packageNames, user);
4353 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004354 if (!removedComponents.isEmpty()) {
4355 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004356 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004357 // Notify the drag controller
4358 mDragController.onAppsRemoved(packageNames, removedComponents);
4359
Sunny Goyal1a745e82014-10-02 15:58:31 -07004360 } else {
4361 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004362 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004363
Winson Chungdf95eb12013-10-16 14:57:07 -07004364 // Update AllApps
Winson Chungb745afb2015-03-02 11:51:23 -08004365 if (mAppsView != null) {
4366 mAppsView.removeApps(appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004367 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004368 }
Joe Onoratobe386092009-11-17 17:32:16 -08004369
Michael Jurkac402cd92013-05-20 15:49:32 +02004370 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004371 public void run() {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004372 bindAllPackages(mWidgetsModel);
Winson Chung83892cc2013-05-01 16:53:33 -07004373 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004374 };
Hyunyoung Song3f471442015-04-08 19:01:34 -07004375
Hyunyoung Song8821ca92015-05-04 16:28:20 -07004376 @Override
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004377 public void bindAllPackages(final WidgetsModel model) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004378 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004379 mWidgetsModel = model;
Winson Chung83892cc2013-05-01 16:53:33 -07004380 return;
4381 }
4382
Hyunyoung Song2bd3d7d2015-05-21 13:04:53 -07004383 if (mWidgetsView != null && model != null) {
4384 mWidgetsView.addWidgets(model);
4385 mWidgetsModel = null;
Winson Chung785d2eb2011-04-14 16:08:02 -07004386 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004387 }
4388
Winson Chung400438b2011-01-16 17:53:48 -08004389 private int mapConfigurationOriActivityInfoOri(int configOri) {
4390 final Display d = getWindowManager().getDefaultDisplay();
4391 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4392 switch (d.getRotation()) {
4393 case Surface.ROTATION_0:
4394 case Surface.ROTATION_180:
4395 // We are currently in the same basic orientation as the natural orientation
4396 naturalOri = configOri;
4397 break;
4398 case Surface.ROTATION_90:
4399 case Surface.ROTATION_270:
4400 // We are currently in the other basic orientation to the natural orientation
4401 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4402 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4403 break;
4404 }
4405
4406 int[] oriMap = {
4407 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4408 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4409 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4410 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4411 };
4412 // Since the map starts at portrait, we need to offset if this device's natural orientation
4413 // is landscape.
4414 int indexOffset = 0;
4415 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4416 indexOffset = 1;
4417 }
4418 return oriMap[(d.getRotation() + indexOffset) % 4];
4419 }
Adam Cohen446e9402011-09-15 18:21:21 -07004420
Winson Chung4b919f82012-05-01 10:44:08 -07004421 public void lockScreenOrientation() {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004422 if (mRotationEnabled) {
Sunny Goyal3c1865a2015-02-10 14:28:44 -08004423 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
4424 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4425 .getConfiguration().orientation));
4426 } else {
4427 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4428 }
Winson Chung4b919f82012-05-01 10:44:08 -07004429 }
4430 }
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004431
Winson Chung4b919f82012-05-01 10:44:08 -07004432 public void unlockScreenOrientation(boolean immediate) {
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004433 if (mRotationEnabled) {
Winson Chung4b919f82012-05-01 10:44:08 -07004434 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004435 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004436 } else {
4437 mHandler.postDelayed(new Runnable() {
4438 public void run() {
4439 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4440 }
4441 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004442 }
Winson Chung4b919f82012-05-01 10:44:08 -07004443 }
Winson Chung400438b2011-01-16 17:53:48 -08004444 }
4445
Winson Chunge43a1e72014-01-15 10:33:02 -08004446 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004447 if (mLauncherCallbacks != null) {
4448 return mLauncherCallbacks.isLauncherPreinstalled();
4449 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004450 PackageManager pm = getPackageManager();
4451 try {
4452 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4453 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4454 return true;
4455 } else {
4456 return false;
4457 }
4458 } catch (NameNotFoundException e) {
4459 e.printStackTrace();
4460 return false;
4461 }
4462 }
4463
Adam Cohenea90f832014-05-21 15:03:34 -07004464 /**
4465 * This method indicates whether or not we should suggest default wallpaper dimensions
4466 * when our wallpaper cropper was not yet used to set a wallpaper.
4467 */
4468 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004469 if (mLauncherCallbacks != null) {
4470 return mLauncherCallbacks.overrideWallpaperDimensions();
4471 }
Adam Cohenea90f832014-05-21 15:03:34 -07004472 return true;
4473 }
4474
Adam Cohen432609a2014-03-13 17:03:22 -07004475 /**
4476 * To be overridden by subclasses to indicate that there is an activity to launch
4477 * before showing the standard launcher experience.
4478 */
4479 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004480 if (mLauncherCallbacks != null) {
4481 return mLauncherCallbacks.hasFirstRunActivity();
4482 }
Adam Cohen432609a2014-03-13 17:03:22 -07004483 return false;
4484 }
4485
4486 /**
4487 * To be overridden by subclasses to launch any first run activity
4488 */
4489 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004490 if (mLauncherCallbacks != null) {
4491 return mLauncherCallbacks.getFirstRunActivity();
4492 }
Adam Cohen432609a2014-03-13 17:03:22 -07004493 return null;
4494 }
4495
Winson Chung2826a402015-04-17 16:18:53 -07004496 /**
4497 * Returns whether the launcher callbacks overrides search in all apps.
Winson Chung2826a402015-04-17 16:18:53 -07004498 */
4499 @Thunk boolean isAllAppsSearchOverridden() {
Winson Chung83f59ab2015-05-05 17:21:58 -07004500 if (DISABLE_ALL_APPS_SEARCH_INTEGRATION) {
4501 return false;
4502 }
4503
Winson Chung2826a402015-04-17 16:18:53 -07004504 if (mLauncherCallbacks != null) {
4505 return mLauncherCallbacks.overrideAllAppsSearch();
4506 }
4507 return false;
4508 }
4509
Winson Chunga6945242014-01-08 14:04:34 -08004510 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004511 return !ActivityManager.isRunningInTestHarness() &&
4512 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004513 }
4514
Adam Cohen4a9423d2014-03-28 14:22:31 -07004515 protected boolean hasRunFirstRunActivity() {
4516 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4517 }
4518
Adam Cohen432609a2014-03-13 17:03:22 -07004519 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004520 if (shouldRunFirstRunActivity() &&
4521 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004522 Intent firstRunIntent = getFirstRunActivity();
4523 if (firstRunIntent != null) {
4524 startActivity(firstRunIntent);
4525 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004526 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004527 }
4528 }
Adam Cohen432609a2014-03-13 17:03:22 -07004529 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004530 }
4531
4532 private void markFirstRunActivityShown() {
4533 SharedPreferences.Editor editor = mSharedPrefs.edit();
4534 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4535 editor.apply();
4536 }
4537
Rahul Chaturvedi7fc77ca2015-05-19 18:02:16 -07004538 private void showSettingsActivity() {
4539 startActivity(new Intent(this, SettingsActivity.class));
4540 }
4541
Adam Cohen432609a2014-03-13 17:03:22 -07004542 /**
4543 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4544 * screen that must be displayed and dismissed.
4545 */
4546 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004547 if (mLauncherCallbacks != null) {
4548 return mLauncherCallbacks.hasDismissableIntroScreen();
4549 }
Adam Cohen432609a2014-03-13 17:03:22 -07004550 return false;
4551 }
4552
4553 /**
4554 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4555 */
4556 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004557 if (mLauncherCallbacks != null) {
4558 return mLauncherCallbacks.getIntroScreen();
4559 }
Adam Cohen432609a2014-03-13 17:03:22 -07004560 return null;
4561 }
4562
4563 /**
4564 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4565 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4566 */
4567 private boolean shouldShowIntroScreen() {
4568 return hasDismissableIntroScreen() &&
4569 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4570 }
4571
4572 protected void showIntroScreen() {
4573 View introScreen = getIntroScreen();
4574 changeWallpaperVisiblity(false);
4575 if (introScreen != null) {
4576 mDragLayer.showOverlayView(introScreen);
4577 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004578 if (mLauncherOverlayContainer != null) {
4579 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4580 }
Adam Cohen432609a2014-03-13 17:03:22 -07004581 }
4582
4583 public void dismissIntroScreen() {
4584 markIntroScreenDismissed();
4585 if (showFirstRunActivity()) {
4586 // We delay hiding the intro view until the first run activity is showing. This
4587 // avoids a blip.
4588 mWorkspace.postDelayed(new Runnable() {
4589 @Override
4590 public void run() {
4591 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004592 if (mLauncherOverlayContainer != null) {
4593 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4594 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004595 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004596 }
4597 }, ACTIVITY_START_DELAY);
4598 } else {
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 changeWallpaperVisiblity(true);
4606 }
4607
4608 private void markIntroScreenDismissed() {
4609 SharedPreferences.Editor editor = mSharedPrefs.edit();
4610 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4611 editor.apply();
4612 }
4613
Adam Cohen091440a2015-03-18 14:16:05 -07004614 @Thunk void showFirstRunClings() {
Sunny Goyal88d60f12014-09-08 03:47:29 -07004615 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4616 // on the device, then we always show the first run cling experience (or if there is no
4617 // launcher2). Otherwise, we prompt the user upon started for migration
4618 LauncherClings launcherClings = new LauncherClings(this);
4619 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
4620 if (mModel.canMigrateFromOldLauncherDb(this)) {
4621 launcherClings.showMigrationCling();
4622 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07004623 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004624 }
4625 }
4626 }
4627
Winson Chunga6945242014-01-08 14:04:34 -08004628 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004629 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4630 if (mHotseat != null) mHotseat.setAlpha(1f);
4631 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4632 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004633 }
4634
4635 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004636 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4637 if (mHotseat != null) mHotseat.setAlpha(0f);
4638 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4639 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004640 }
4641
Mathew Inwood72fbec12013-11-19 15:45:07 +00004642 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004643 // Called from search suggestion, not supported in other profiles.
4644 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4645 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4646 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4647 myUser);
4648 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004649 return null;
4650 }
Sunny Goyal4fbc3822015-02-18 16:46:50 -08004651 return new AppInfo(this, activityInfo, myUser, mIconCache);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004652 }
4653
4654 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4655 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004656 // Called from search suggestion, not supported in other profiles.
4657 return createShortcutDragInfo(shortcutIntent, caption, icon,
4658 UserHandleCompat.myUserHandle());
4659 }
4660
4661 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4662 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004663 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004664 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004665 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004666 }
4667
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004668 protected void moveWorkspaceToDefaultScreen() {
4669 mWorkspace.moveToDefaultScreen(false);
4670 }
4671
Mathew Inwood72fbec12013-11-19 15:45:07 +00004672 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4673 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004674 mWorkspace.onExternalDragStartedWithItem(dragView);
4675 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004676 }
4677
Anjali Koppalf5d29132014-02-28 13:33:27 -08004678 @Override
4679 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07004680 if (mLauncherCallbacks != null) {
4681 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
4682 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08004683 }
4684
Winson Chung80baf5a2010-08-09 16:03:15 -07004685 /**
Sunny Goyal53d7ee42015-05-22 12:25:45 -07004686 * Returns a FastBitmapDrawable with the icon, accurately sized.
4687 */
4688 public FastBitmapDrawable createIconDrawable(Bitmap icon) {
4689 FastBitmapDrawable d = new FastBitmapDrawable(icon);
4690 d.setFilterBitmap(true);
4691 resizeIconDrawable(d);
4692 return d;
4693 }
4694
4695 /**
4696 * Resizes an icon drawable to the correct icon size.
4697 */
4698 public void resizeIconDrawable(Drawable icon) {
4699 icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
4700 }
4701
4702 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004703 * Prints out out state for debugging.
4704 */
4705 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004706 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004707 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004708 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4709 Log.d(TAG, "mRestoring=" + mRestoring);
4710 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4711 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004712 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004713 mModel.dumpState();
Hyunyoung Song3f471442015-04-08 19:01:34 -07004714 // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004715
Daniel Sandler325dc232013-06-05 22:57:57 -04004716 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004717 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004718
4719 @Override
4720 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4721 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004722 synchronized (sDumpLogs) {
4723 writer.println(" ");
4724 writer.println("Debug logs: ");
4725 for (int i = 0; i < sDumpLogs.size(); i++) {
4726 writer.println(" " + sDumpLogs.get(i));
4727 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004728 }
Adam Cohen9211d422014-10-07 18:14:53 -07004729 if (mLauncherCallbacks != null) {
4730 mLauncherCallbacks.dump(prefix, fd, writer, args);
4731 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004732 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004733
4734 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004735 if (DEBUG_DUMP_LOG) {
4736 synchronized (sDumpLogs) {
4737 Log.d(TAG, "");
4738 Log.d(TAG, "*********************");
4739 Log.d(TAG, "Launcher debug logs: ");
4740 for (int i = 0; i < sDumpLogs.size(); i++) {
4741 Log.d(TAG, " " + sDumpLogs.get(i));
4742 }
4743 Log.d(TAG, "*********************");
4744 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004745 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004746 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004747 }
4748
4749 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004750 addDumpLog(tag, log, null, debugLog);
4751 }
4752
4753 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004754 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004755 if (e != null) {
4756 Log.d(tag, log, e);
4757 } else {
4758 Log.d(tag, log);
4759 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004760 }
Winson Chungede41292013-09-19 16:27:36 -07004761 if (DEBUG_DUMP_LOG) {
4762 sDateStamp.setTime(System.currentTimeMillis());
4763 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004764 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4765 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004766 }
Winson Chungede41292013-09-19 16:27:36 -07004767 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004768 }
4769
Adam Cohen59400422014-03-05 18:07:04 -08004770 public static CustomAppWidget getCustomAppWidget(String name) {
4771 return sCustomAppWidgets.get(name);
4772 }
4773
4774 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
4775 return sCustomAppWidgets;
4776 }
4777
Winson Chungede41292013-09-19 16:27:36 -07004778 public void dumpLogsToLocalData() {
4779 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004780 new AsyncTask<Void, Void, Void>() {
4781 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004782 boolean success = false;
4783 sDateStamp.setTime(sRunStart);
4784 String FILENAME = sDateStamp.getMonth() + "-"
4785 + sDateStamp.getDay() + "_"
4786 + sDateStamp.getHours() + "-"
4787 + sDateStamp.getMinutes() + "_"
4788 + sDateStamp.getSeconds() + ".txt";
4789
4790 FileOutputStream fos = null;
4791 File outFile = null;
4792 try {
4793 outFile = new File(getFilesDir(), FILENAME);
4794 outFile.createNewFile();
4795 fos = new FileOutputStream(outFile);
4796 } catch (Exception e) {
4797 e.printStackTrace();
4798 }
4799 if (fos != null) {
4800 PrintWriter writer = new PrintWriter(fos);
4801
4802 writer.println(" ");
4803 writer.println("Debug logs: ");
4804 synchronized (sDumpLogs) {
4805 for (int i = 0; i < sDumpLogs.size(); i++) {
4806 writer.println(" " + sDumpLogs.get(i));
4807 }
4808 }
4809 writer.close();
4810 }
4811 try {
4812 if (fos != null) {
4813 fos.close();
4814 success = true;
4815 }
4816 } catch (IOException e) {
4817 e.printStackTrace();
4818 }
Michael Jurka43467462013-11-14 12:03:58 +01004819 return null;
Winson Chungede41292013-09-19 16:27:36 -07004820 }
Michael Jurka43467462013-11-14 12:03:58 +01004821 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004822 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004823 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004824}
Michael Jurka2763be32011-02-24 11:19:57 -08004825
Dan Sandlerd5024042014-01-09 15:01:33 -05004826interface DebugIntents {
4827 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4828 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004829}