blob: 0414a5b1eabc324b7c93eff39f368ba12403434e [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Adam Cohen2854d252014-08-27 16:04:07 -070025import android.animation.TimeInterpolator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070026import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000027import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070028import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070029import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070030import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040031import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040042import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Adam Cohen173f7112015-03-27 15:14:00 -070045import android.content.IntentSender;
Winson Chung82f55532011-08-09 14:14:23 -070046import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070047import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080048import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070050import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070052import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
Adam Cohen3f9c9712014-10-31 11:48:25 -070054import android.database.sqlite.SQLiteDatabase;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.Bitmap;
56import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070057import android.graphics.Color;
Adam Cohen268c4752012-06-06 17:47:33 -070058import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070060import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040061import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070062import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020063import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020065import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080066import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070067import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070068import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040069import android.os.SystemClock;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070072import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.Display;
76import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
79import android.view.LayoutInflater;
80import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070081import android.view.MotionEvent;
82import android.view.Surface;
83import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070084import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Adam Cohen2854d252014-08-27 16:04:07 -070086import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.ViewGroup;
Adam Cohenc2d6e892014-10-16 09:49:24 -070088import android.view.ViewStub;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.ViewTreeObserver;
Sunny Goyal651077b2014-06-30 14:15:31 -070090import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080092import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070093import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080094import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070096import android.widget.Advanceable;
97import android.widget.FrameLayout;
98import android.widget.ImageView;
Adam Cohen96d30a12013-07-16 18:13:21 -070099import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700100
Sunny Goyal651077b2014-06-30 14:15:31 -0700101import com.android.launcher3.DropTarget.DragObject;
102import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700103import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100104import com.android.launcher3.compat.LauncherActivityInfoCompat;
105import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700106import com.android.launcher3.compat.PackageInstallerCompat;
107import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100108import com.android.launcher3.compat.UserHandleCompat;
109import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700110
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.io.DataInputStream;
112import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700114import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700118import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000119import java.lang.reflect.Field;
120import java.lang.reflect.InvocationTargetException;
121import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700122import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700124import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.HashMap;
Sunny Goyal4390ace2014-10-13 11:33:11 -0700127import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700128import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000129import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131/**
132 * Default launcher application.
133 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100134public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700135 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700136 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800137 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700138 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Daniel Sandlerf061f822013-06-27 13:59:36 -0400140 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400141 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700142 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400143 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700144 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700145
Dan Sandlerd5024042014-01-09 15:01:33 -0500146 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
147
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700149 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700151 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700152 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Michael Jurka8b805b12012-04-18 14:23:14 -0700154 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700155 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700156
Mathew Inwood876a8462013-06-14 14:12:41 +0100157 /**
158 * IntentStarter uses request codes starting with this. This must be greater than all activity
159 * request codes used internally.
160 */
161 protected static final int REQUEST_LAST = 100;
162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
164
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800165 static final int SCREEN_COUNT = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Michael Jurka0a457bf2012-11-19 14:05:05 -0800167 // To turn on these properties, type
168 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
Michael Jurka0a457bf2012-11-19 14:05:05 -0800169 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800170 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171
Winson Chung2672ff92012-05-04 16:22:30 -0700172 // The Intent extra that defines whether to ignore the launch animation
173 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400174 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700175
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: int
177 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700178 // Type: int
179 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700181 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
182 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
184 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700185 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700187 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 // Type: boolean
189 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
190 // Type: long
191 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700192 // Type: int
193 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
194 // Type: int
195 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
196 // Type: parcelable
197 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000198 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000200 // Type: int[]
201 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202
Adam Cohen432609a2014-03-13 17:03:22 -0700203 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800204 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
205
Adam Cohen3ed316a2014-07-23 18:21:20 -0700206 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
207 static final String ACTION_FIRST_LOAD_COMPLETE =
208 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
209
Adam Cohen39a06042013-07-19 14:30:12 -0700210 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700211 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700212
Sunny Goyal594d76d2014-11-06 10:12:54 -0800213 private static final String QSB_WIDGET_ID = "qsb_widget_id";
214 private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
215
Winson Chunga6945242014-01-08 14:04:34 -0800216 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
217
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700218 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700219 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700220 private State mState = State.WORKSPACE;
221 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700222
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700223 private boolean mIsSafeModeEnabled;
224
Adam Cohenc2d6e892014-10-16 09:49:24 -0700225 LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl();
226 LauncherOverlay mLauncherOverlay;
Adam Cohena6d04922014-10-23 17:28:30 -0700227 InsettableFrameLayout mLauncherOverlayContainer;
Adam Cohenc2d6e892014-10-16 09:49:24 -0700228
Joe Onorato9c1289c2009-08-17 11:03:03 -0400229 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700230 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
231 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700232 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 private static final Object sLock = new Object();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000236 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
237 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
238
Winson Chunga2413752012-04-03 14:22:34 -0700239 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700240 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
241 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700242 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700243 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700244
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800245 private final BroadcastReceiver mCloseSystemDialogsReceiver
246 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800247 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
248
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 private LayoutInflater mInflater;
250
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700252 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800253 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800254 private DragLayer mDragLayer;
255 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700256 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700257
Sunny Goyalffe83f12014-08-14 17:39:34 -0700258 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
Michael Jurkac9d95c52011-08-29 14:03:34 -0700261 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen59400422014-03-05 18:07:04 -0800262 private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800263 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700264
Michael Jurka0280c3b2010-09-17 15:00:07 -0700265 private int[] mTmpAddItemCellCoordinates = new int[2];
266
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 private FolderInfo mFolderInfo;
268
Winson Chung3d503fb2011-07-13 17:25:49 -0700269 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800270 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700271
Michael Jurka838a4ca2011-02-07 13:33:06 -0800272 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700273
Winson Chungc51db6a2011-10-05 11:44:49 -0700274 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700275 private AppsCustomizeTabHost mAppsCustomizeTabHost;
276 private AppsCustomizePagedView mAppsCustomizeContent;
277 private boolean mAutoAdvanceRunning = false;
Sunny Goyal594d76d2014-11-06 10:12:54 -0800278 private AppWidgetHostView mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700281 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
282 // scroll issues (because the workspace may not have been measured yet) and extra work.
283 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
284 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285
286 private SpannableStringBuilder mDefaultKeySsb = null;
287
Joe Onorato9c1289c2009-08-17 11:03:03 -0400288 private boolean mWorkspaceLoading = true;
289
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800290 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 private boolean mRestoring;
292 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700293 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294
Michael Jurka1e2f4652013-07-08 18:03:46 -0700295 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700296 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
297
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298 private Bundle mSavedInstanceState;
299
Joe Onorato9c1289c2009-08-17 11:03:03 -0400300 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800301 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800302 private boolean mUserPresent = true;
303 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700304 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800305 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400306
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700307 private static LocaleConfiguration sLocaleConfiguration = null;
308
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700309 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700310
Adam Cohen61f560d2013-09-30 15:58:20 -0700311 private View.OnTouchListener mHapticFeedbackTouchListener;
312
Adam Cohen80e6beb2015-02-13 16:14:33 -0800313 public static final int BUILD_LAYER = 0;
314 public static final int BUILD_AND_SET_LAYER = 1;
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;
322 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
323 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
Craig Mautner360310b2012-10-26 15:13:08 -0700329 private 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
Adam Cohene25af792013-06-06 23:08:25 -0700345 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
346
Winson Chungf0c6ae02012-03-21 16:10:31 -0700347 // Holds the page that we need to animate to, and the icon views that we need to animate up
348 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700349 private ImageView mFolderIconImageView;
350 private Bitmap mFolderIconBitmap;
351 private Canvas mFolderIconCanvas;
352 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700353
Michael Jurkaddd62e92011-02-16 17:49:14 -0800354 private BubbleTextView mWaitingForResume;
355
Adam Cohen59400422014-03-05 18:07:04 -0800356 protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
357 new HashMap<String, CustomAppWidget>();
358
359 private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
360 static {
361 if (ENABLE_CUSTOM_WIDGET_TEST) {
362 sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
363 }
364 }
365
Michael Jurkac1f5d262011-09-30 19:32:27 -0700366 private Runnable mBuildLayersRunnable = new Runnable() {
367 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700368 if (mWorkspace != null) {
369 mWorkspace.buildPageHardwareLayers();
370 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700371 }
372 };
373
Adam Cohendb364c32014-05-20 14:23:40 -0700374 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800375
376 private static class PendingAddArguments {
377 int requestCode;
378 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700379 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700380 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800381 int cellX;
382 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700383 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800384 }
385
Daniel Sandlerff02d492013-08-05 02:12:05 -0400386 private Stats mStats;
387
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700388 FocusIndicatorView mFocusHandler;
389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 @Override
391 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700392 if (DEBUG_STRICT_MODE) {
393 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
394 .detectDiskReads()
395 .detectDiskWrites()
396 .detectNetwork() // or .detectAll() for all detectable problems
397 .penaltyLog()
398 .build());
399 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
400 .detectLeakedSqlLiteObjects()
401 .detectLeakedClosableObjects()
402 .penaltyLog()
403 .penaltyDeath()
404 .build());
405 }
406
Adam Cohen9211d422014-10-07 18:14:53 -0700407 if (mLauncherCallbacks != null) {
408 mLauncherCallbacks.preOnCreate();
409 }
410
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800411 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400412
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400413 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400414 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700415 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700416
Winson Chung5f8afe62013-08-12 16:19:28 -0700417 // Lazy-initialize the dynamic grid
Sunny Goyal33d44382014-10-16 09:24:19 -0700418 DeviceProfile grid = app.initDynamicGrid(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700419
420 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400421 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700422 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700423 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800424 mModel = app.setLauncher(this);
425 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700426 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400427 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700429
Daniel Sandlerff02d492013-08-05 02:12:05 -0400430 mStats = new Stats(this);
431
Sunny Goyalffe83f12014-08-14 17:39:34 -0700432 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700433
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700434 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
435 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700436
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700437 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
438 // this also ensures that any synchronous binding below doesn't re-trigger another
439 // LauncherModel load.
440 mPaused = false;
441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200443 android.os.Debug.startMethodTracing(
444 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 }
446
447 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100451 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800453 registerContentObservers();
454
Joe Onorato7c312c12009-08-13 21:36:53 -0700455 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 mSavedState = savedInstanceState;
458 restoreState(mSavedState);
459
460 if (PROFILE_STARTUP) {
461 android.os.Debug.stopMethodTracing();
462 }
463
464 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700465 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 // If the user leaves launcher, then we should just load items asynchronously when
467 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500468 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 } else {
470 // We only load the page synchronously if the user rotates (or triggers a
471 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800472 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 }
475
476 // For handling default keys
477 mDefaultKeySsb = new SpannableStringBuilder();
478 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800479
480 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
481 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800482
Adam Cohenf9426d52012-06-04 17:26:21 -0700483 // On large interfaces, we want the screen to auto-rotate based on the current orientation
484 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700485
Adam Cohen9211d422014-10-07 18:14:53 -0700486 if (mLauncherCallbacks != null) {
487 mLauncherCallbacks.onCreate(savedInstanceState);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700488 if (mLauncherCallbacks.hasLauncherOverlay()) {
489 ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
Adam Cohena6d04922014-10-23 17:28:30 -0700490 mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
491 mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(
492 mLauncherOverlayContainer, mLauncherOverlayCallbacks);
Adam Cohenc2d6e892014-10-16 09:49:24 -0700493 mWorkspace.setLauncherOverlay(mLauncherOverlay);
494 }
Adam Cohen9211d422014-10-07 18:14:53 -0700495 }
Adam Cohenc3e12c72014-10-31 16:15:36 -0700496
497 if (shouldShowIntroScreen()) {
498 showIntroScreen();
499 } else {
500 showFirstRunActivity();
501 showFirstRunClings();
502 }
Adam Cohen9211d422014-10-07 18:14:53 -0700503 }
504
505 private LauncherCallbacks mLauncherCallbacks;
506
507 public void onPostCreate(Bundle savedInstanceState) {
508 super.onPostCreate(savedInstanceState);
509 if (mLauncherCallbacks != null) {
510 mLauncherCallbacks.onPostCreate(savedInstanceState);
511 }
512 }
513
514 public boolean setLauncherCallbacks(LauncherCallbacks callbacks) {
515 mLauncherCallbacks = callbacks;
516 return true;
Adam Cohenf9426d52012-06-04 17:26:21 -0700517 }
518
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700519 @Override
Adam Cohen9211d422014-10-07 18:14:53 -0700520 public void onLauncherProviderChange() {
521 if (mLauncherCallbacks != null) {
522 mLauncherCallbacks.onLauncherProviderChange();
523 }
524 }
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700525
Adam Cohen9211d422014-10-07 18:14:53 -0700526 /** To be overridden by subclasses to hint to Launcher that we have custom content */
Winson Chung98ca0f72013-07-29 12:58:51 -0700527 protected boolean hasCustomContentToLeft() {
Adam Cohen9211d422014-10-07 18:14:53 -0700528 if (mLauncherCallbacks != null) {
529 return mLauncherCallbacks.hasCustomContentToLeft();
530 }
Winson Chung98ca0f72013-07-29 12:58:51 -0700531 return false;
532 }
533
Dave Hawkeya8881582013-09-17 15:55:33 -0600534 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500535 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 * {@link #addToCustomContentPage}. This will only be invoked if
537 * {@link #hasCustomContentToLeft()} is {@code true}.
538 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500539 protected void populateCustomContentContainer() {
Adam Cohen9211d422014-10-07 18:14:53 -0700540 if (mLauncherCallbacks != null) {
541 mLauncherCallbacks.populateCustomContentContainer();
542 }
Dave Hawkeya8881582013-09-17 15:55:33 -0600543 }
544
545 /**
546 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
547 * ensure the custom content page is added or removed if necessary.
548 */
549 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600550 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600551 // Not bound yet, wait for bindScreens to be called.
552 return;
553 }
554
555 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
556 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500557 mWorkspace.createCustomContentContainer();
558 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600559 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
560 mWorkspace.removeCustomContentPage();
561 }
562 }
563
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700565 if (sLocaleConfiguration == null) {
566 new AsyncTask<Void, Void, LocaleConfiguration>() {
567 @Override
568 protected LocaleConfiguration doInBackground(Void... unused) {
569 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
570 readConfiguration(Launcher.this, localeConfiguration);
571 return localeConfiguration;
572 }
573
574 @Override
575 protected void onPostExecute(LocaleConfiguration result) {
576 sLocaleConfiguration = result;
577 checkForLocaleChange(); // recursive, but now with a locale configuration
578 }
579 }.execute();
580 return;
581 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700582
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583 final Configuration configuration = getResources().getConfiguration();
584
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 final String locale = configuration.locale.toString();
587
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700588 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589 final int mcc = configuration.mcc;
590
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700591 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592 final int mnc = configuration.mnc;
593
Romain Guy84f296c2009-11-04 15:00:44 -0800594 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800595
Romain Guy84f296c2009-11-04 15:00:44 -0800596 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700597 sLocaleConfiguration.locale = locale;
598 sLocaleConfiguration.mcc = mcc;
599 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700600
Joe Onorato0589f0f2010-02-08 13:44:00 -0800601 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602
603 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100604 new AsyncTask<Void, Void, Void>() {
605 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100607 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 }
Michael Jurka43467462013-11-14 12:03:58 +0100609 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700610 }
611 }
612
613 private static class LocaleConfiguration {
614 public String locale;
615 public int mcc = -1;
616 public int mnc = -1;
617 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700618
Romain Guy98d01652009-06-30 16:21:04 -0700619 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
620 DataInputStream in = null;
621 try {
Helena Josol28db2802014-10-09 17:04:09 +0100622 in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
Romain Guy98d01652009-06-30 16:21:04 -0700623 configuration.locale = in.readUTF();
624 configuration.mcc = in.readInt();
625 configuration.mnc = in.readInt();
626 } catch (FileNotFoundException e) {
627 // Ignore
628 } catch (IOException e) {
629 // Ignore
630 } finally {
631 if (in != null) {
632 try {
633 in.close();
634 } catch (IOException e) {
635 // Ignore
636 }
637 }
638 }
639 }
640
641 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
642 DataOutputStream out = null;
643 try {
Helena Josol4fbbb3e2014-10-06 16:06:46 +0100644 out = new DataOutputStream(context.openFileOutput(
Helena Josol28db2802014-10-09 17:04:09 +0100645 LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE));
Romain Guy98d01652009-06-30 16:21:04 -0700646 out.writeUTF(configuration.locale);
647 out.writeInt(configuration.mcc);
648 out.writeInt(configuration.mnc);
649 out.flush();
650 } catch (FileNotFoundException e) {
651 // Ignore
652 } catch (IOException e) {
653 //noinspection ResultOfMethodCallIgnored
Helena Josol28db2802014-10-09 17:04:09 +0100654 context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete();
Romain Guy98d01652009-06-30 16:21:04 -0700655 } finally {
656 if (out != null) {
657 try {
658 out.close();
659 } catch (IOException e) {
660 // Ignore
661 }
662 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 }
664 }
665
Anton Hanssona2f665f2013-09-26 12:18:32 +0100666 public Stats getStats() {
667 return mStats;
668 }
669
Bjorn Bringertc459e522013-06-07 19:36:01 +0100670 public LayoutInflater getInflater() {
671 return mInflater;
672 }
673
Winson Chung36a62fe2012-05-06 18:04:42 -0700674 boolean isDraggingEnabled() {
675 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
676 // that is subsequently removed from the workspace in startBinding().
677 return !mModel.isLoadingWorkspace();
678 }
679
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800680 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000681 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100682 if (Build.VERSION.SDK_INT >= 17) {
683 return View.generateViewId();
684 } else {
685 // View.generateViewId() is not available. The following fallback logic is a copy
686 // of its implementation.
687 for (;;) {
688 final int result = sNextGeneratedId.get();
689 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
690 int newValue = result + 1;
691 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
692 if (sNextGeneratedId.compareAndSet(result, newValue)) {
693 return result;
694 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000695 }
696 }
697 }
698
699 public int getViewIdForItem(ItemInfo info) {
700 // This cast is safe given the > 2B range for int.
701 int itemId = (int) info.id;
702 if (mItemIdToViewId.containsKey(itemId)) {
703 return mItemIdToViewId.get(itemId);
704 }
705 int viewId = generateViewId();
706 mItemIdToViewId.put(itemId, viewId);
707 return viewId;
708 }
709
710 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700711 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
712 * a configuration step, this allows the proper animations to run after other transitions.
713 */
Adam Cohendb364c32014-05-20 14:23:40 -0700714 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700715 long screenId = args.screenId;
716 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
717 // When the screen id represents an actual screen (as opposed to a rank) we make sure
718 // that the drop page actually exists.
719 screenId = ensurePendingDropLayoutExists(args.screenId);
720 }
Adam Cohendb364c32014-05-20 14:23:40 -0700721
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800722 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800723 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700724 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700725 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700726 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800727 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700728 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700729 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700730 case REQUEST_RECONFIGURE_APPWIDGET:
731 completeRestoreAppWidget(args.appWidgetId);
732 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800733 }
Michael Jurka27614d22012-04-02 06:40:22 -0700734 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
735 // if you turned the screen off and then back while in All Apps, Launcher would not
736 // return to the workspace. Clearing mAddInfo.container here fixes this issue
737 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700738 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800739 }
740
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800741 private void handleActivityResult(
Michael Jurka8b805b12012-04-18 14:23:14 -0700742 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700743 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700744 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700745 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800746 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700747
Adam Cohenad4e15c2013-10-17 16:21:35 -0700748 Runnable exitSpringLoaded = new Runnable() {
749 @Override
750 public void run() {
751 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
752 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
753 }
754 };
755
Michael Jurka8b805b12012-04-18 14:23:14 -0700756 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700757 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700758 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
759 if (resultCode == RESULT_CANCELED) {
760 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700761 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700762 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700763 } else if (resultCode == RESULT_OK) {
Sunny Goyal8f9a7872015-01-16 16:14:29 -0800764 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700765 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 }
767 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200768 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
769 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
770 mWorkspace.exitOverviewMode(false);
771 }
772 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700773 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200774
Adam Cohened66b2b2012-01-23 17:28:51 -0800775 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
776 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700777
Adam Cohendb364c32014-05-20 14:23:40 -0700778 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800779 // We have special handling for widgets
780 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800781 final int appWidgetId;
782 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
783 : -1;
784 if (widgetId < 0) {
785 appWidgetId = pendingAddWidgetId;
786 } else {
787 appWidgetId = widgetId;
788 }
789
Adam Cohenad4e15c2013-10-17 16:21:35 -0700790 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800791 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700792 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
793 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700794 result = RESULT_CANCELED;
795 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700796 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700797 @Override
798 public void run() {
799 exitSpringLoadedDragModeDelayed(false, 0, null);
800 }
801 };
Adam Cohendb364c32014-05-20 14:23:40 -0700802 if (workspaceLocked) {
803 // No need to remove the empty screen if we're mid-binding, as the
804 // the bind will not add the empty screen.
805 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
806 } else {
807 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
808 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
809 }
Winson Chung5aaab772012-04-27 15:24:02 -0700810 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700811 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700812 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
813 // When the screen id represents an actual screen (as opposed to a rank)
814 // we make sure that the drop page actually exists.
815 mPendingAddInfo.screenId =
816 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
817 }
Adam Cohendb364c32014-05-20 14:23:40 -0700818 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
819
820 dropLayout.setDropPending(true);
821 final Runnable onComplete = new Runnable() {
822 @Override
823 public void run() {
824 completeTwoStageWidgetDrop(resultCode, appWidgetId);
825 dropLayout.setDropPending(false);
826 }
827 };
828 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
829 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
830 } else {
831 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
832 mPendingAddInfo);
833 sPendingAddItem = args;
834 }
Winson Chung5aaab772012-04-27 15:24:02 -0700835 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800836 return;
837 }
838
Sunny Goyalff572272014-07-23 13:58:07 -0700839 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
840 if (resultCode == RESULT_OK) {
841 // Update the widget view.
842 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
843 pendingAddWidgetId, mPendingAddInfo);
844 if (workspaceLocked) {
845 sPendingAddItem = args;
846 } else {
847 completeAdd(args);
848 }
849 }
850 // Leave the widget in the pending state if the user canceled the configure.
851 return;
852 }
853
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 // The pattern used here is that a user PICKs a specific application,
855 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700856
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
858 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700859 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700860 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
861 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800862 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700863 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800864 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700865 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700866 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
867 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 }
Adam Cohen00074722013-10-11 17:46:09 -0700869 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700870 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700871 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800873 mDragLayer.clearAnimatedView();
Adam Cohenc7cd2cb2014-11-17 17:45:34 -0800874
875 }
876
877 @Override
878 protected void onActivityResult(
879 final int requestCode, final int resultCode, final Intent data) {
880 handleActivityResult(requestCode, resultCode, data);
881 if (mLauncherCallbacks != null) {
882 mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
883 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 }
885
Adam Cohendb364c32014-05-20 14:23:40 -0700886 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
887 appWidgetId, ItemInfo info) {
888 PendingAddArguments args = new PendingAddArguments();
889 args.requestCode = requestCode;
890 args.intent = data;
891 args.container = info.container;
892 args.screenId = info.screenId;
893 args.cellX = info.cellX;
894 args.cellY = info.cellY;
895 args.appWidgetId = appWidgetId;
896 return args;
897 }
898
899 /**
900 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
901 *
902 * @param screenId the screen id to check
903 * @return the new screen, or screenId if it exists
904 */
905 private long ensurePendingDropLayoutExists(long screenId) {
906 CellLayout dropLayout =
907 (CellLayout) mWorkspace.getScreenWithId(screenId);
908 if (dropLayout == null) {
909 // it's possible that the add screen was removed because it was
910 // empty and a re-bind occurred
911 mWorkspace.addExtraEmptyScreen();
912 return mWorkspace.commitExtraEmptyScreen();
913 } else {
914 return screenId;
915 }
916 }
917
Adam Cohened66b2b2012-01-23 17:28:51 -0800918 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700919 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700920 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800921 Runnable onCompleteRunnable = null;
922 int animationType = 0;
923
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700924 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800925 if (resultCode == RESULT_OK) {
926 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
927 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700928 mPendingAddWidgetInfo);
929 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 onCompleteRunnable = new Runnable() {
931 @Override
932 public void run() {
933 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700934 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700935 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
936 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 }
938 };
939 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800940 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800941 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800942 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700943 if (mDragLayer.getAnimatedView() != null) {
944 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
945 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
946 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700947 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700948 // The animated view may be null in the case of a rotation during widget configuration
949 onCompleteRunnable.run();
950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 }
952
953 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700954 protected void onStop() {
955 super.onStop();
956 FirstFrameAnimatorHelper.setIsVisible(false);
Adam Cohen9211d422014-10-07 18:14:53 -0700957
958 if (mLauncherCallbacks != null) {
959 mLauncherCallbacks.onStop();
960 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700961 }
962
963 @Override
964 protected void onStart() {
965 super.onStart();
966 FirstFrameAnimatorHelper.setIsVisible(true);
Adam Cohen9211d422014-10-07 18:14:53 -0700967
968 if (mLauncherCallbacks != null) {
969 mLauncherCallbacks.onStart();
970 }
Michael Jurkacd496d72013-04-11 11:32:45 -0700971 }
972
973 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800974 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200975 long startTime = 0;
976 if (DEBUG_RESUME_TIME) {
977 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400978 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200979 }
Adam Cohen9211d422014-10-07 18:14:53 -0700980
981 if (mLauncherCallbacks != null) {
982 mLauncherCallbacks.preOnResume();
983 }
984
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800985 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700986
Winson Chung4a2afa32012-07-19 14:53:05 -0700987 // Restore the previous launcher state
988 if (mOnResumeState == State.WORKSPACE) {
989 showWorkspace(false);
990 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800991 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700992 }
993 mOnResumeState = State.NONE;
994
Craig Mautner360310b2012-10-26 15:13:08 -0700995 // Background was set to gradient in onPause(), restore to black if in all apps.
996 setWorkspaceBackground(mState == State.WORKSPACE);
997
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800998 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700999 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001000 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -05001001 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001002 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001003 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001004 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001005 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001006 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1007 // execute them here
1008 long startTimeCallbacks = 0;
1009 if (DEBUG_RESUME_TIME) {
1010 startTimeCallbacks = System.currentTimeMillis();
1011 }
1012
1013 if (mAppsCustomizeContent != null) {
1014 mAppsCustomizeContent.setBulkBind(true);
1015 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001016 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1017 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001018 }
1019 if (mAppsCustomizeContent != null) {
1020 mAppsCustomizeContent.setBulkBind(false);
1021 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001022 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001023 if (DEBUG_RESUME_TIME) {
1024 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1025 (System.currentTimeMillis() - startTimeCallbacks));
1026 }
Michael Jurka447bf842013-05-15 14:52:15 +02001027 }
Michael Jurka54554252013-08-01 12:52:23 +02001028 if (mOnResumeCallbacks.size() > 0) {
1029 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1030 mOnResumeCallbacks.get(i).run();
1031 }
1032 mOnResumeCallbacks.clear();
1033 }
Winson Chunge4e50662012-01-23 14:45:13 -08001034
1035 // Reset the pressed state of icons that were locked in the press state while activities
1036 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001037 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001038 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001039 mWaitingForResume.setStayPressed(false);
1040 }
Winson Chung82963d52013-10-09 11:20:57 -07001041
Adam Cohen06dff352012-06-01 17:17:08 -07001042 // It is possible that widgets can receive updates while launcher is not in the foreground.
1043 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1044 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1045 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001046 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001047
Winson Chung780fe592013-09-26 14:48:44 -07001048 // Process any items that were added while Launcher was away.
1049 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1050
Michael Jurka447bf842013-05-15 14:52:15 +02001051 if (DEBUG_RESUME_TIME) {
1052 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1053 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001054
1055 if (mWorkspace.getCustomContentCallbacks() != null) {
1056 // If we are resuming and the custom content is the current page, we call onShow().
1057 // It is also poassible that onShow will instead be called slightly after first layout
1058 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1059 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001060 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001061 }
1062 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001063 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001064 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001065
1066 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen9211d422014-10-07 18:14:53 -07001067
1068 if (mLauncherCallbacks != null) {
1069 mLauncherCallbacks.onResume();
1070 }
Adam Cohen06dff352012-06-01 17:17:08 -07001071 }
1072
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001073 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001074 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001075 // Ensure that items added to Launcher are queued until Launcher returns
1076 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001077 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001078
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001079 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001080 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001081 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001082 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001083
1084 // We call onHide() aggressively. The custom content callbacks should be able to
1085 // debounce excess onHide calls.
1086 if (mWorkspace.getCustomContentCallbacks() != null) {
1087 mWorkspace.getCustomContentCallbacks().onHide();
1088 }
Romain Guycbb89e42009-06-08 15:52:54 -07001089
Adam Cohen9211d422014-10-07 18:14:53 -07001090 if (mLauncherCallbacks != null) {
1091 mLauncherCallbacks.onPause();
Adam Cohenbffe7452013-07-22 18:21:45 -07001092 }
Adam Cohenbffe7452013-07-22 18:21:45 -07001093 }
1094
1095 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001096 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1097 // by a onResume or by scrolling otherwise.
1098 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001099
1100 // Custom content is completely hidden
1101 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001102
1103 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1104 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001105
1106 // Indicates whether the user is allowed to scroll away from the custom content.
1107 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001108 }
1109
Adam Cohenc2d6e892014-10-16 09:49:24 -07001110 public interface LauncherOverlay {
1111
1112 /**
1113 * Touch interaction leading to overscroll has begun
1114 */
1115 public void onScrollInteractionBegin();
1116
1117 /**
1118 * Touch interaction related to overscroll has ended
1119 */
1120 public void onScrollInteractionEnd();
1121
1122 /**
1123 * Scroll progress, between 0 and 100, when the user scrolls beyond the leftmost
1124 * screen (or in the case of RTL, the rightmost screen).
1125 */
1126 public void onScrollChange(int progress, boolean rtl);
1127
1128 /**
1129 * Screen has stopped scrolling
1130 */
1131 public void onScrollSettled();
1132
1133 /**
1134 * This method can be called by the Launcher in order to force the LauncherOverlay
1135 * to exit fully immersive mode.
1136 */
1137 public void forceExitFullImmersion();
1138 }
1139
1140 public interface LauncherOverlayCallbacks {
1141 /**
1142 * This method indicates whether a call to {@link #enterFullImmersion()} will succeed,
1143 * however it doesn't modify any state within the launcher.
1144 */
1145 public boolean canEnterFullImmersion();
1146
1147 /**
1148 * Should be called to tell Launcher that the LauncherOverlay will take over interaction,
1149 * eg. by occupying the full screen and handling all touch events.
1150 *
1151 * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this
1152 * case, Launcher will modify any necessary state and assumes the overlay is
1153 * handling all interaction. If false, the LauncherOverlay should cancel any
1154 *
1155 */
1156 public boolean enterFullImmersion();
1157
1158 /**
1159 * Must be called when exiting fully immersive mode. Indicates to Launcher that it has
1160 * full control over UI and state.
1161 */
1162 public void exitFullImmersion();
1163 }
1164
1165 class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks {
1166
1167 @Override
1168 public boolean canEnterFullImmersion() {
1169 return mState == State.WORKSPACE;
1170 }
1171
1172 @Override
1173 public boolean enterFullImmersion() {
1174 if (mState == State.WORKSPACE) {
1175 // When fully immersed, disregard any touches which fall through.
1176 mDragLayer.setBlockTouch(true);
1177 return true;
1178 }
1179 return false;
1180 }
1181
1182 @Override
1183 public void exitFullImmersion() {
1184 mDragLayer.setBlockTouch(false);
1185 }
1186 }
1187
Jorim Jaggid017f882014-01-14 17:08:48 -08001188 protected boolean hasSettings() {
Adam Cohen9211d422014-10-07 18:14:53 -07001189 if (mLauncherCallbacks != null) {
1190 return mLauncherCallbacks.hasSettings();
1191 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001192 return false;
1193 }
1194
Adam Cohenbffe7452013-07-22 18:21:45 -07001195
Adam Cohen9211d422014-10-07 18:14:53 -07001196 public void addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001197 CustomContentCallbacks callbacks, String description) {
1198 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohen66a01fd2013-06-11 12:48:00 -07001199 }
1200
Adam Cohenedb40762013-07-18 16:45:45 -07001201 // The custom content needs to offset its content to account for the QSB
1202 public int getTopOffsetForCustomContent() {
1203 return mWorkspace.getPaddingTop();
1204 }
1205
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001206 @Override
1207 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001208 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001209 if (mModel.isCurrentCallbacks(this)) {
1210 mModel.stopLoader();
1211 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001212 if (mAppsCustomizeContent != null) {
1213 mAppsCustomizeContent.surrender();
1214 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001215 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001216 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001217
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001218 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001219 @Override
1220 public void onWindowFocusChanged(boolean hasFocus) {
1221 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001222 mHasFocus = hasFocus;
Adam Cohen9211d422014-10-07 18:14:53 -07001223
1224 if (mLauncherCallbacks != null) {
1225 mLauncherCallbacks.onWindowFocusChanged(hasFocus);
1226 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001227 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001228
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 private boolean acceptFilter() {
1230 final InputMethodManager inputManager = (InputMethodManager)
1231 getSystemService(Context.INPUT_METHOD_SERVICE);
1232 return !inputManager.isFullscreenMode();
1233 }
1234
1235 @Override
1236 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001237 final int uniChar = event.getUnicodeChar();
1238 final boolean handled = super.onKeyDown(keyCode, event);
1239 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1240 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1242 keyCode, event);
1243 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001244 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001245 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001246 // showSearchDialog()
1247 // If there are multiple keystrokes before the search dialog takes focus,
1248 // onSearchRequested() will be called for every keystroke,
1249 // but it is idempotent, so it's fine.
1250 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
1252 }
1253
Joe Onorato8a9625e2010-01-28 15:55:35 -08001254 // Eat the long press event so the keyboard doesn't come up.
1255 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1256 return true;
1257 }
1258
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 return handled;
1260 }
1261
Karl Rosaen138a0412009-04-23 19:00:21 -07001262 private String getTypedText() {
1263 return mDefaultKeySsb.toString();
1264 }
1265
1266 private void clearTypedText() {
1267 mDefaultKeySsb.clear();
1268 mDefaultKeySsb.clearSpans();
1269 Selection.setSelection(mDefaultKeySsb, 0);
1270 }
1271
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001273 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1274 * State
1275 */
1276 private static State intToState(int stateOrdinal) {
1277 State state = State.WORKSPACE;
1278 final State[] stateValues = State.values();
1279 for (int i = 0; i < stateValues.length; i++) {
1280 if (stateValues[i].ordinal() == stateOrdinal) {
1281 state = stateValues[i];
1282 break;
1283 }
1284 }
1285 return state;
1286 }
1287
1288 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 * Restores the previous state, if it exists.
1290 *
1291 * @param savedState The previous state.
1292 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001293 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001294 private void restoreState(Bundle savedState) {
1295 if (savedState == null) {
1296 return;
1297 }
1298
Michael Jurka883f55b2010-10-21 15:47:14 -07001299 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001300 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001301 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001302 }
1303
Adam Cohen21cd0022013-10-09 18:57:02 -07001304 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1305 PagedView.INVALID_RESTORE_PAGE);
1306 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001307 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 }
1309
Winson Chung3d503fb2011-07-13 17:25:49 -07001310 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001311 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001312
Winson Chung3d503fb2011-07-13 17:25:49 -07001313 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1314 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001315 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001316 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1317 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001318 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1319 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Adam Cohenb823ae42015-03-27 18:07:52 -07001320 AppWidgetProviderInfo info = savedState.getParcelable(
1321 RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
1322 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001323 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001324 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 mRestoring = true;
1326 }
1327
1328 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1329 if (renameFolder) {
1330 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001331 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332 mRestoring = true;
1333 }
Winson Chunga12a2502010-12-20 14:41:35 -08001334
Winson Chung785d2eb2011-04-14 16:08:02 -07001335 // Restore the AppsCustomize tab
1336 if (mAppsCustomizeTabHost != null) {
1337 String curTab = savedState.getString("apps_customize_currentTab");
1338 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001339 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001340 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001341 mAppsCustomizeContent.loadAssociatedPages(
1342 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001343 }
1344
Winson Chung5afbf7b2011-07-25 11:53:08 -07001345 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1346 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001347 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001348 mItemIdToViewId = (HashMap<Integer, Integer>)
1349 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 }
1351
1352 /**
1353 * Finds all the views we need and configure them properly.
1354 */
1355 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001356 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001357
Craig Mautner360310b2012-10-26 15:13:08 -07001358 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001359 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001360 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1361 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001362 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001363 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001364
John Spurlock77e1f472013-09-11 10:09:51 -04001365 mLauncherView.setSystemUiVisibility(
1366 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001367 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368
Winson Chung4c98d922011-05-31 16:50:48 -07001369 // Setup the drag layer
1370 mDragLayer.setup(this, dragController);
1371
Winson Chung3d503fb2011-07-13 17:25:49 -07001372 // Setup the hotseat
1373 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1374 if (mHotseat != null) {
1375 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001376 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 }
1378
Jorim Jaggid017f882014-01-14 17:08:48 -08001379 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001380 View widgetButton = findViewById(R.id.widget_button);
1381 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001382 @Override
1383 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001384 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001385 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001386 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001387 }
1388 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001389 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1390
1391 View wallpaperButton = findViewById(R.id.wallpaper_button);
1392 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001393 @Override
1394 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001395 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001396 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001397 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001398 }
1399 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001400 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1401
1402 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001403 if (hasSettings()) {
1404 settingsButton.setOnClickListener(new OnClickListener() {
1405 @Override
1406 public void onClick(View arg0) {
1407 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001408 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001409 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001410 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001411 });
1412 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1413 } else {
1414 settingsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001415 }
1416
Adam Cohendbdff6b2013-09-18 19:09:15 -07001417 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001418
Winson Chung4c98d922011-05-31 16:50:48 -07001419 // Setup the workspace
1420 mWorkspace.setHapticFeedbackEnabled(false);
1421 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001422 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001423 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001424
Winson Chungf0ea4d32011-06-06 14:27:16 -07001425 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001426 mSearchDropTargetBar = (SearchDropTargetBar)
1427 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001428
Winson Chungf0ea4d32011-06-06 14:27:16 -07001429 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001430 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001431 mAppsCustomizeContent = (AppsCustomizePagedView)
1432 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1433 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001434
Winson Chung3d503fb2011-07-13 17:25:49 -07001435 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001436 dragController.setDragScoller(mWorkspace);
1437 dragController.setScrollView(mDragLayer);
1438 dragController.setMoveTarget(mWorkspace);
1439 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001440 if (mSearchDropTargetBar != null) {
1441 mSearchDropTargetBar.setup(this, dragController);
Sunny Goyal594d76d2014-11-06 10:12:54 -08001442 mSearchDropTargetBar.setQsbSearchBar(getQsbBar());
Michael Jurkae0f5a612011-02-07 16:45:41 -08001443 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001444
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001445 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001446 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001447 mWeightWatcher = new WeightWatcher(this);
1448 mWeightWatcher.setAlpha(0.5f);
1449 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001450 new FrameLayout.LayoutParams(
1451 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001452 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001453 Gravity.BOTTOM)
1454 );
Adam Cohen39a06042013-07-19 14:30:12 -07001455
1456 boolean show = shouldShowWeightWatcher();
1457 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001458 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 }
1460
1461 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001462 * Sets the all apps button. This method is called from {@link Hotseat}.
1463 */
1464 public void setAllAppsButton(View allAppsButton) {
1465 mAllAppsButton = allAppsButton;
1466 }
1467
1468 public View getAllAppsButton() {
1469 return mAllAppsButton;
1470 }
1471
1472 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 * Creates a view representing a shortcut.
1474 *
1475 * @param info The data structure describing the shortcut.
1476 *
1477 * @return A View inflated from R.layout.application.
1478 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001479 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001480 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001481 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001482 }
1483
1484 /**
1485 * Creates a view representing a shortcut inflated from the specified resource.
1486 *
1487 * @param layoutResId The id of the XML layout used to create the shortcut.
1488 * @param parent The group the shortcut belongs to.
1489 * @param info The data structure describing the shortcut.
1490 *
1491 * @return A View inflated from layoutResId.
1492 */
Adam Cohen59400422014-03-05 18:07:04 -08001493 public View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001494 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001495 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001497 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 return favorite;
1499 }
1500
1501 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001502 * Add a shortcut to the workspace.
1503 *
1504 * @param data The intent describing the shortcut.
1505 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001507 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001508 int cellY) {
1509 int[] cellXY = mTmpAddItemCellCoordinates;
1510 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001511 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001512
Michael Jurkad3ef3062010-11-23 16:23:58 -08001513 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001514
Sunny Goyal2350bc92014-10-14 16:42:54 -07001515 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data);
Adam Cohend9198822011-11-22 16:42:47 -08001516 if (info == null) {
1517 return;
1518 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001519 final View view = createShortcut(info);
1520
Adam Cohenfbba09b2011-07-18 21:43:05 -07001521 // First we check if we already know the exact location where we want to add this item.
1522 if (cellX >= 0 && cellY >= 0) {
1523 cellXY[0] = cellX;
1524 cellXY[1] = cellY;
1525 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001526
1527 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001528 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001529 true, null,null)) {
1530 return;
1531 }
1532 DragObject dragObject = new DragObject();
1533 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001534 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1535 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001536 return;
1537 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001538 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001539 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001540 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001541 foundCellSpan = (result != null);
1542 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001543 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001544 }
1545
1546 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001547 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001548 return;
1549 }
1550
Adam Cohendcd297f2013-06-18 13:13:40 -07001551 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001552
1553 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001554 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001555 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 }
1557 }
1558
Adam Cohen2f093b62012-04-30 18:59:53 -07001559 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1560 int minHeight) {
1561 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001562 // We want to account for the extra amount of padding that we are adding to the widget
1563 // to ensure that it gets the full amount of space that it has requested
1564 int requiredWidth = minWidth + padding.left + padding.right;
1565 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001566 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001567 }
1568
Adam Cohen2f093b62012-04-30 18:59:53 -07001569 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1570 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001571 }
1572
Adam Cohen2f093b62012-04-30 18:59:53 -07001573 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1574 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001575 }
1576
Adam Cohen2f093b62012-04-30 18:59:53 -07001577 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1578 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001579 }
1580
Adam Cohen2f093b62012-04-30 18:59:53 -07001581 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1582 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001583 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001584 }
1585
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001587 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001589 * @param appWidgetId The app widget id
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001590 */
Adam Cohen59400422014-03-05 18:07:04 -08001591 private void completeAddAppWidget(int appWidgetId, long container, long screenId,
1592 AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
1593
1594 ItemInfo info = mPendingAddInfo;
Adam Cohened66b2b2012-01-23 17:28:51 -08001595 if (appWidgetInfo == null) {
Adam Cohen59400422014-03-05 18:07:04 -08001596 appWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this,
1597 mAppWidgetManager.getAppWidgetInfo(appWidgetId));
Adam Cohened66b2b2012-01-23 17:28:51 -08001598 }
Romain Guycbb89e42009-06-08 15:52:54 -07001599
Adam Cohen59400422014-03-05 18:07:04 -08001600 if (appWidgetInfo.isCustomWidget) {
1601 appWidgetId = LauncherAppWidgetInfo.CUSTOM_WIDGET_ID;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001602 }
1603
Adam Cohen59400422014-03-05 18:07:04 -08001604 LauncherAppWidgetInfo launcherInfo;
1605 launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider);
1606 launcherInfo.spanX = info.spanX;
1607 launcherInfo.spanY = info.spanY;
1608 launcherInfo.minSpanX = info.minSpanX;
1609 launcherInfo.minSpanY = info.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001610 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001611
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohen59400422014-03-05 18:07:04 -08001613 container, screenId, info.cellX, info.cellY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614
1615 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001616 if (hostView == null) {
1617 // Perform actual inflation because we're live
Adam Cohen59400422014-03-05 18:07:04 -08001618 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
1619 appWidgetInfo);
Adam Cohened66b2b2012-01-23 17:28:51 -08001620 } else {
1621 // The AppWidgetHostView has already been inflated and instantiated
1622 launcherInfo.hostView = hostView;
1623 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001624 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001625 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001626 launcherInfo.notifyWidgetSizeChanged(this);
1627
Adam Cohen59400422014-03-05 18:07:04 -08001628 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
1629 info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001630
1631 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001632 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001633 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001634 }
Romain Guycbb89e42009-06-08 15:52:54 -07001635
Adam Cohended9f8d2010-11-03 13:25:16 -07001636 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1637 @Override
1638 public void onReceive(Context context, Intent intent) {
1639 final String action = intent.getAction();
1640 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1641 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001642 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001643 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001644
Winson Chungc100e8e2011-08-09 16:02:43 -07001645 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001646 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001647 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001648 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001649 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001650 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1651 mUserPresent = true;
1652 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001653 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1654 mModel.resetLoadedState(false, true);
1655 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1656 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1657 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1658 mModel.resetLoadedState(false, true);
1659 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1660 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1661 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001662 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1663 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1664 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001665 }
1666 }
1667 };
1668
1669 @Override
1670 public void onAttachedToWindow() {
1671 super.onAttachedToWindow();
1672
1673 // Listen for broadcasts related to user-presence
1674 final IntentFilter filter = new IntentFilter();
1675 filter.addAction(Intent.ACTION_SCREEN_OFF);
1676 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001677 // For handling managed profiles
1678 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1679 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001680 if (ENABLE_DEBUG_INTENTS) {
1681 filter.addAction(DebugIntents.DELETE_DATABASE);
1682 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1683 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001684 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001685 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001686 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001687 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001688 mVisible = true;
1689 }
1690
Adam Cohen0b395352014-06-09 22:54:36 +00001691 /**
1692 * Sets up transparent navigation and status bars in LMP.
1693 * This method is a no-op for other platform versions.
1694 */
1695 @TargetApi(19)
1696 private void setupTransparentSystemBarsForLmp() {
1697 // TODO(sansid): use the APIs directly when compiling against L sdk.
1698 // Currently we use reflection to access the flags and the API to set the transparency
1699 // on the System bars.
Kenny Guyd794a3f2014-09-16 15:17:58 +01001700 if (Utilities.isLmpOrAbove()) {
Adam Cohen0b395352014-06-09 22:54:36 +00001701 try {
1702 getWindow().getAttributes().systemUiVisibility |=
1703 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1704 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1705 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1706 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1707 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1708 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1709 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1710 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1711
1712 Method setStatusBarColorMethod =
1713 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1714 Method setNavigationBarColorMethod =
1715 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1716 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1717 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1718 } catch (NoSuchFieldException e) {
1719 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1720 } catch (NoSuchMethodException ex) {
1721 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1722 } catch (IllegalAccessException e) {
1723 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1724 } catch (IllegalArgumentException e) {
1725 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1726 } catch (InvocationTargetException e) {
1727 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1728 } finally {}
1729 }
1730 }
1731
Adam Cohended9f8d2010-11-03 13:25:16 -07001732 @Override
1733 public void onDetachedFromWindow() {
1734 super.onDetachedFromWindow();
1735 mVisible = false;
1736
Adam Cohend113e0c2010-11-11 10:48:05 -08001737 if (mAttached) {
1738 unregisterReceiver(mReceiver);
1739 mAttached = false;
1740 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001741 updateRunning();
1742 }
1743
1744 public void onWindowVisibilityChanged(int visibility) {
1745 mVisible = visibility == View.VISIBLE;
1746 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001747 // The following code used to be in onResume, but it turns out onResume is called when
1748 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1749 // is a more appropriate event to handle
1750 if (mVisible) {
1751 mAppsCustomizeTabHost.onWindowVisible();
1752 if (!mWorkspaceLoading) {
1753 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001754 // We want to let Launcher draw itself at least once before we force it to build
1755 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001756 // apps is nice and speedy.
1757 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001758 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001759 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001760 if (mStarted) return;
1761 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001762 // We delay the layer building a bit in order to give
1763 // other message processing a time to run. In particular
1764 // this avoids a delay in hiding the IME if it was
1765 // currently shown, because doing that may involve
1766 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001767 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001768 final ViewTreeObserver.OnDrawListener listener = this;
1769 mWorkspace.post(new Runnable() {
1770 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001771 if (mWorkspace != null &&
1772 mWorkspace.getViewTreeObserver() != null) {
1773 mWorkspace.getViewTreeObserver().
1774 removeOnDrawListener(listener);
1775 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001776 }
1777 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001778 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001779 }
1780 });
1781 }
1782 clearTypedText();
1783 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001784 }
1785
1786 private void sendAdvanceMessage(long delay) {
1787 mHandler.removeMessages(ADVANCE_MSG);
1788 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1789 mHandler.sendMessageDelayed(msg, delay);
1790 mAutoAdvanceSentTime = System.currentTimeMillis();
1791 }
1792
1793 private void updateRunning() {
1794 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1795 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1796 mAutoAdvanceRunning = autoAdvanceRunning;
1797 if (autoAdvanceRunning) {
1798 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1799 sendAdvanceMessage(delay);
1800 } else {
1801 if (!mWidgetsToAdvance.isEmpty()) {
1802 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1803 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1804 }
1805 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001806 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001807 }
1808 }
1809 }
1810
1811 private final Handler mHandler = new Handler() {
1812 @Override
1813 public void handleMessage(Message msg) {
1814 if (msg.what == ADVANCE_MSG) {
1815 int i = 0;
1816 for (View key: mWidgetsToAdvance.keySet()) {
1817 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1818 final int delay = mAdvanceStagger * i;
1819 if (v instanceof Advanceable) {
1820 postDelayed(new Runnable() {
1821 public void run() {
1822 ((Advanceable) v).advance();
1823 }
1824 }, delay);
1825 }
1826 i++;
1827 }
1828 sendAdvanceMessage(mAdvanceInterval);
1829 }
1830 }
1831 };
1832
1833 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001834 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001835 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1836 if (v instanceof Advanceable) {
1837 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001838 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001839 updateRunning();
1840 }
1841 }
1842
1843 void removeWidgetToAutoAdvance(View hostView) {
1844 if (mWidgetsToAdvance.containsKey(hostView)) {
1845 mWidgetsToAdvance.remove(hostView);
1846 updateRunning();
1847 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001848 }
1849
Joe Onorato9c1289c2009-08-17 11:03:03 -04001850 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001851 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001852 launcherInfo.hostView = null;
1853 }
1854
Winson Chung93eef082012-03-23 15:59:27 -07001855 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1856 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1857 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001858 }
1859
Adam Cohen59400422014-03-05 18:07:04 -08001860 public ArrayList<AppInfo> getAllAppsList() {
1861 return mAppsCustomizeContent.getApps();
1862 }
1863
Winson Chunga6945242014-01-08 14:04:34 -08001864 public DragLayer getDragLayer() {
1865 return mDragLayer;
1866 }
1867
1868 public Workspace getWorkspace() {
1869 return mWorkspace;
1870 }
1871
1872 public Hotseat getHotseat() {
1873 return mHotseat;
1874 }
1875
Jorim Jaggid017f882014-01-14 17:08:48 -08001876 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001877 return mOverviewPanel;
1878 }
1879
1880 public SearchDropTargetBar getSearchBar() {
1881 return mSearchDropTargetBar;
1882 }
1883
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001884 public LauncherAppWidgetHost getAppWidgetHost() {
1885 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 }
Romain Guycbb89e42009-06-08 15:52:54 -07001887
Winson Chunga9abd0e2010-10-27 17:18:37 -07001888 public LauncherModel getModel() {
1889 return mModel;
1890 }
1891
Winson Chunga6945242014-01-08 14:04:34 -08001892 protected SharedPreferences getSharedPrefs() {
1893 return mSharedPrefs;
1894 }
1895
Bjorn Bringertc459e522013-06-07 19:36:01 +01001896 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001897 getWindow().closeAllPanels();
1898
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001899 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001900 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001901 }
1902
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 @Override
1904 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001905 long startTime = 0;
1906 if (DEBUG_RESUME_TIME) {
1907 startTime = System.currentTimeMillis();
1908 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 super.onNewIntent(intent);
1910
1911 // Close the menu
1912 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001913 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001914 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001915
Adam Cohened307df2013-10-02 09:37:31 -07001916 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1917 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1918 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001919
Adam Cohen6fecd412013-10-02 17:41:50 -07001920 if (mWorkspace == null) {
1921 // Can be cases where mWorkspace is null, this prevents a NPE
1922 return;
1923 }
1924 Folder openFolder = mWorkspace.getOpenFolder();
1925 // In all these cases, only animate if we're already on home
1926 mWorkspace.exitWidgetResizeMode();
Adam Cohen9211d422014-10-07 18:14:53 -07001927
1928 boolean moveToDefaultScreen = mLauncherCallbacks != null ?
1929 mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true;
Adam Cohen6fecd412013-10-02 17:41:50 -07001930 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Cohen9211d422014-10-07 18:14:53 -07001931 openFolder == null && moveToDefaultScreen) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001932 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001933 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001934
Adam Cohen6fecd412013-10-02 17:41:50 -07001935 closeFolder();
1936 exitSpringLoadedDragMode();
1937
1938 // If we are already on home, then just animate back to the workspace,
1939 // otherwise, just wait until onResume to set the state back to Workspace
1940 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001941 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001942 } else {
1943 mOnResumeState = State.WORKSPACE;
1944 }
1945
1946 final View v = getWindow().peekDecorView();
1947 if (v != null && v.getWindowToken() != null) {
1948 InputMethodManager imm = (InputMethodManager)getSystemService(
1949 INPUT_METHOD_SERVICE);
1950 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1951 }
1952
1953 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001954 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001955 mAppsCustomizeTabHost.reset();
1956 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001957
Adam Cohen9211d422014-10-07 18:14:53 -07001958 if (mLauncherCallbacks != null) {
1959 mLauncherCallbacks.onHomeIntent();
1960 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 }
Adam Cohened307df2013-10-02 09:37:31 -07001962
Michael Jurka447bf842013-05-15 14:52:15 +02001963 if (DEBUG_RESUME_TIME) {
1964 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1965 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966
Adam Cohen9211d422014-10-07 18:14:53 -07001967 if (mLauncherCallbacks != null) {
1968 mLauncherCallbacks.onNewIntent(intent);
1969 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001970 }
1971
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001973 public void onRestoreInstanceState(Bundle state) {
1974 super.onRestoreInstanceState(state);
1975 for (int page: mSynchronouslyBoundPages) {
1976 mWorkspace.restoreInstanceStateForChild(page);
1977 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001978 }
1979
1980 @Override
1981 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001982 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001983 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1984 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001985 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001986 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987
Michael Jurka883f55b2010-10-21 15:47:14 -07001988 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001989 // We close any open folder since it will not be re-opened, and we need to make sure
1990 // this state is reflected.
1991 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001992
Adam Cohendcd297f2013-06-18 13:13:40 -07001993 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001994 mWaitingForResult) {
1995 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001996 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001997 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1998 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001999 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2000 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2001 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08002002 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 }
2004
2005 if (mFolderInfo != null && mWaitingForResult) {
2006 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
2007 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
2008 }
Michael Jurka946ad472010-07-09 18:05:18 -07002009
Winson Chung785d2eb2011-04-14 16:08:02 -07002010 // Save the current AppsCustomize tab
2011 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08002012 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
2013 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07002014 if (currentTabTag != null) {
2015 outState.putString("apps_customize_currentTab", currentTabTag);
2016 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002017 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2018 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002019 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002020 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
Adam Cohen9211d422014-10-07 18:14:53 -07002021
2022 if (mLauncherCallbacks != null) {
2023 mLauncherCallbacks.onSaveInstanceState(outState);
2024 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 }
2026
2027 @Override
2028 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002029 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002030
Winson Chunge7a03942011-08-05 15:05:12 -07002031 // Remove all pending runnables
2032 mHandler.removeMessages(ADVANCE_MSG);
2033 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002034 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002035
Winson Chungcd2b0142011-06-08 16:02:26 -07002036 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002037 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07002038
2039 // It's possible to receive onDestroy after a new Launcher activity has
2040 // been created. In this case, don't interfere with the new Launcher.
2041 if (mModel.isCurrentCallbacks(this)) {
2042 mModel.stopLoader();
2043 app.setLauncher(null);
2044 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002045
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002046 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002047 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002049 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002051 mAppWidgetHost = null;
2052
2053 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054
2055 TextKeyListener.getInstance().release();
2056
Winson Chung81b52252012-08-27 15:34:29 -07002057 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2058 // to prevent leaking Launcher activities on orientation change.
2059 if (mModel != null) {
2060 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2061 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002062
2063 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002064 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002065
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002066 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002067 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002068 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002069 mWorkspace = null;
2070 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002071
Michael Jurka2ecf9952012-06-18 12:52:28 -07002072 LauncherAnimUtils.onDestroyActivity();
Adam Cohen9211d422014-10-07 18:14:53 -07002073
2074 if (mLauncherCallbacks != null) {
2075 mLauncherCallbacks.onDestroy();
2076 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 }
2078
Adam Cohena9cf38f2011-05-02 15:36:58 -07002079 public DragController getDragController() {
2080 return mDragController;
2081 }
2082
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 @Override
2084 public void startActivityForResult(Intent intent, int requestCode) {
Adam Cohen173f7112015-03-27 15:14:00 -07002085 onStartForResult(requestCode);
2086 super.startActivityForResult(intent, requestCode);
2087 }
2088
2089 @Override
2090 public void startIntentSenderForResult (IntentSender intent, int requestCode,
2091 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
2092 onStartForResult(requestCode);
2093 try {
2094 super.startIntentSenderForResult(intent, requestCode,
2095 fillInIntent, flagsMask, flagsValues, extraFlags, options);
2096 } catch (IntentSender.SendIntentException e) {
2097 throw new ActivityNotFoundException();
2098 }
2099 }
2100
2101 private void onStartForResult(int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002102 if (requestCode >= 0) {
2103 setWaitingForResult(true);
2104 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 }
2106
Winson Chung70d72102011-08-12 11:24:35 -07002107 /**
2108 * Indicates that we want global search for this activity by setting the globalSearch
2109 * argument for {@link #startSearch} to true.
2110 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002111 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002112 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002113 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002114
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002115 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002116
Karl Rosaen138a0412009-04-23 19:00:21 -07002117 if (initialQuery == null) {
2118 // Use any text typed in the launcher as the initial query
2119 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002120 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002121 if (appSearchData == null) {
2122 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002123 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 }
Winson Chungadf0c182012-08-23 14:59:07 -07002125 Rect sourceBounds = new Rect();
2126 if (mSearchDropTargetBar != null) {
2127 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2128 }
Romain Guycbb89e42009-06-08 15:52:54 -07002129
Ian Parkinson047036e2014-09-01 15:40:53 +01002130 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002131 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002132 if (clearTextImmediately) {
2133 clearTypedText();
2134 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01002135 }
2136
Ian Parkinson047036e2014-09-01 15:40:53 +01002137 /**
2138 * Start a text search.
2139 *
2140 * @return {@code true} if the search will start immediately, so any further keypresses
2141 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2142 * to buffer keypresses.
2143 */
2144 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002145 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Adam Cohen9211d422014-10-07 18:14:53 -07002146 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
2147 return mLauncherCallbacks.startSearch(initialQuery, selectInitialQuery, appSearchData,
2148 sourceBounds);
2149 }
2150
Michael Jurkaa33411c2012-06-14 16:18:21 -07002151 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002152 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002153 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002154 }
2155
2156 /**
2157 * Starts the global search activity. This code is a copied from SearchManager
2158 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002159 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002160 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002161 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002162 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2163 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2164 if (globalSearchActivity == null) {
2165 Log.w(TAG, "No global search activity found.");
2166 return;
2167 }
2168 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2169 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2170 intent.setComponent(globalSearchActivity);
2171 // Make sure that we have a Bundle to put source in
2172 if (appSearchData == null) {
2173 appSearchData = new Bundle();
2174 } else {
2175 appSearchData = new Bundle(appSearchData);
2176 }
Adam Cohen9211d422014-10-07 18:14:53 -07002177 // Set source to package name of app that starts global search if not set already.
Michael Jurkaa33411c2012-06-14 16:18:21 -07002178 if (!appSearchData.containsKey("source")) {
2179 appSearchData.putString("source", getPackageName());
2180 }
2181 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2182 if (!TextUtils.isEmpty(initialQuery)) {
2183 intent.putExtra(SearchManager.QUERY, initialQuery);
2184 }
2185 if (selectInitialQuery) {
2186 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2187 }
2188 intent.setSourceBounds(sourceBounds);
2189 try {
2190 startActivity(intent);
2191 } catch (ActivityNotFoundException ex) {
2192 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2193 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002194 }
2195
Yura4f93ec62014-02-04 14:15:21 +00002196 public boolean isOnCustomContent() {
2197 return mWorkspace.isOnOrMovingToCustomContent();
2198 }
2199
Winson Chung70d72102011-08-12 11:24:35 -07002200 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002201 public boolean onPrepareOptionsMenu(Menu menu) {
2202 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002203 if (!isOnCustomContent()) {
2204 // Close any open folders
2205 closeFolder();
2206 // Stop resizing any widgets
2207 mWorkspace.exitWidgetResizeMode();
2208 if (!mWorkspace.isInOverviewMode()) {
2209 // Show the overview mode
2210 showOverviewMode(true);
2211 } else {
2212 showWorkspace(true);
2213 }
Winson Chunge0298742014-01-17 12:03:00 -08002214 }
Adam Cohen9211d422014-10-07 18:14:53 -07002215 if (mLauncherCallbacks != null) {
2216 return mLauncherCallbacks.onPrepareOptionsMenu(menu);
2217 }
2218
Michael Jurkab94f3f82013-09-11 18:08:54 +02002219 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002220 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002221
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002222 @Override
2223 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002224 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002225 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002226 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002227 }
2228
Joe Onorato9c1289c2009-08-17 11:03:03 -04002229 public boolean isWorkspaceLocked() {
2230 return mWorkspaceLoading || mWaitingForResult;
2231 }
2232
Adam Cohen517a7f52014-03-01 12:12:59 -08002233 public boolean isWorkspaceLoading() {
2234 return mWorkspaceLoading;
2235 }
2236
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002237 private void setWorkspaceLoading(boolean value) {
2238 boolean isLocked = isWorkspaceLocked();
2239 mWorkspaceLoading = value;
2240 if (isLocked != isWorkspaceLocked()) {
2241 onWorkspaceLockedChanged();
2242 }
2243 }
2244
2245 private void setWaitingForResult(boolean value) {
2246 boolean isLocked = isWorkspaceLocked();
2247 mWaitingForResult = value;
2248 if (isLocked != isWorkspaceLocked()) {
2249 onWorkspaceLockedChanged();
2250 }
2251 }
2252
Adam Cohen9211d422014-10-07 18:14:53 -07002253 protected void onWorkspaceLockedChanged() {
2254 if (mLauncherCallbacks != null) {
2255 mLauncherCallbacks.onWorkspaceLockedChanged();
2256 }
2257 }
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002258
Michael Jurka0280c3b2010-09-17 15:00:07 -07002259 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002260 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002261 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002262 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2263 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002264 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002265 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002266 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002267
Sunny Goyal8f9a7872015-01-16 16:14:29 -08002268 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info, final
Adam Cohen59400422014-03-05 18:07:04 -08002269 AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo) {
Adam Cohenad4e15c2013-10-17 16:21:35 -07002270 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2271 }
2272
Sunny Goyal8f9a7872015-01-16 16:14:29 -08002273 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
Adam Cohen59400422014-03-05 18:07:04 -08002274 final AppWidgetHostView boundWidget, final LauncherAppWidgetProviderInfo appWidgetInfo,
2275 int delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002276 if (appWidgetInfo.configure != null) {
2277 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002278 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002279
Bjorn Bringert7984c942009-12-09 15:38:25 +00002280 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002281 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2282 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2283
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002284 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002285 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002286 Runnable onComplete = new Runnable() {
2287 @Override
2288 public void run() {
2289 // Exit spring loaded mode if necessary after adding the widget
2290 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2291 null);
2292 }
2293 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002294 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002295 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002296 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002297 }
2298 }
Romain Guycbb89e42009-06-08 15:52:54 -07002299
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002300 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002301 // Close any folders that may be open.
2302 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002303 mWorkspace.moveToCustomContentScreen(animate);
2304 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002305
2306 public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
2307 int[] cell, int spanX, int spanY) {
2308 switch (info.itemType) {
2309 case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
2310 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
2311 int span[] = new int[2];
2312 span[0] = spanX;
2313 span[1] = spanY;
2314 addAppWidgetFromDrop((PendingAddWidgetInfo) info,
2315 container, screenId, cell, span);
2316 break;
2317 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
2318 processShortcutFromDrop(info.componentName, container, screenId, cell);
2319 break;
2320 default:
2321 throw new IllegalStateException("Unknown item type: " + info.itemType);
2322 }
2323 }
2324
Adam Cohenfbba09b2011-07-18 21:43:05 -07002325 /**
2326 * Process a shortcut drop.
2327 *
2328 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002329 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002330 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002331 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002332 private void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2333 int[] cell) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002334 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002335 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002336 mPendingAddInfo.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002337 mPendingAddInfo.dropPos = null;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002338
2339 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002340 mPendingAddInfo.cellX = cell[0];
2341 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002342 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002343
2344 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2345 createShortcutIntent.setComponent(componentName);
2346 processShortcut(createShortcutIntent);
2347 }
2348
Adam Cohenfbba09b2011-07-18 21:43:05 -07002349 /**
2350 * Process a widget drop.
2351 *
2352 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002353 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002354 * @param cell The cell it should be added to, optional
Adam Cohenfbba09b2011-07-18 21:43:05 -07002355 */
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002356 private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2357 int[] cell, int[] span) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002358 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002359 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002360 mPendingAddInfo.screenId = info.screenId = screenId;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002361 mPendingAddInfo.dropPos = null;
Adam Cohend41fbf52012-02-16 23:53:59 -08002362 mPendingAddInfo.minSpanX = info.minSpanX;
2363 mPendingAddInfo.minSpanY = info.minSpanY;
2364
Adam Cohenfbba09b2011-07-18 21:43:05 -07002365 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002366 mPendingAddInfo.cellX = cell[0];
2367 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002368 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002369 if (span != null) {
2370 mPendingAddInfo.spanX = span[0];
2371 mPendingAddInfo.spanY = span[1];
2372 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002373
Adam Cohened66b2b2012-01-23 17:28:51 -08002374 AppWidgetHostView hostView = info.boundWidget;
2375 int appWidgetId;
2376 if (hostView != null) {
2377 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002378 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002379 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002380 // In this case, we either need to start an activity to get permission to bind
2381 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002382 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002383 Bundle options = info.bindOptions;
2384
Sunny Goyalffe83f12014-08-14 17:39:34 -07002385 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2386 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002387 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002388 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002389 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002390 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002391 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2392 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2393 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002394 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2395 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002396 // TODO: we need to make sure that this accounts for the options bundle.
2397 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002398 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2399 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002400 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002401 }
2402
Joe Onoratodeb98af2010-02-19 14:59:39 -08002403 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002404 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002405 }
2406
Winson Chung24ab2f12010-09-16 14:10:47 -07002407 void processWallpaper(Intent intent) {
2408 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2409 }
2410
Adam Cohendcd297f2013-06-18 13:13:40 -07002411 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002412 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002413 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002414 folderInfo.title = getText(R.string.folder_name);
2415
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002416 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002417 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002418 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002419 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002420
2421 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002422 FolderIcon newFolder =
2423 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002424 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002425 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002426 // Force measure the new folder icon
2427 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2428 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002429 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430 }
Romain Guycbb89e42009-06-08 15:52:54 -07002431
Joe Onorato9c1289c2009-08-17 11:03:03 -04002432 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002433 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002434 }
2435
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002436 protected ComponentName getWallpaperPickerComponent() {
Adam Cohen9211d422014-10-07 18:14:53 -07002437 if (mLauncherCallbacks != null) {
2438 return mLauncherCallbacks.getWallpaperPickerComponent();
2439 }
Michael Jurka7ad868b2013-12-12 15:04:25 +01002440 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002441 }
2442
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002443 /**
2444 * Registers various content observers. The current implementation registers
2445 * only a favorites observer to keep track of the favorites applications.
2446 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002447 private void registerContentObservers() {
2448 ContentResolver resolver = getContentResolver();
2449 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2450 true, mWidgetObserver);
2451 }
2452
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002453 @Override
2454 public boolean dispatchKeyEvent(KeyEvent event) {
2455 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2456 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002457 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002458 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002459 case KeyEvent.KEYCODE_VOLUME_DOWN:
Sunny Goyal4bbf4192014-11-11 12:23:59 -08002460 if (Utilities.isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002461 dumpState();
2462 return true;
2463 }
2464 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002465 }
2466 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2467 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002468 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002469 return true;
2470 }
2471 }
2472
2473 return super.dispatchKeyEvent(event);
2474 }
2475
Joe Onorato88ec0992009-11-19 13:16:06 -08002476 @Override
2477 public void onBackPressed() {
Adam Cohen9211d422014-10-07 18:14:53 -07002478 if (mLauncherCallbacks != null && mLauncherCallbacks.handleBackPressed()) {
2479 return;
2480 }
2481
Winson Chungc93e5ae2012-07-23 20:48:26 -07002482 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002483 if (mAppsCustomizeContent.getContentType() ==
2484 AppsCustomizePagedView.ContentType.Applications) {
2485 showWorkspace(true);
2486 } else {
2487 showOverviewMode(true);
2488 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002489 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002490 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002491 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002492 Folder openFolder = mWorkspace.getOpenFolder();
2493 if (openFolder.isEditingName()) {
2494 openFolder.dismissEditingName();
2495 } else {
2496 closeFolder();
2497 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002498 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002499 mWorkspace.exitWidgetResizeMode();
2500
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002501 // Back button is a no-op here, but give at least some feedback for the button press
2502 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002503 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002504 }
2505
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002506 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002507 * Re-listen when widgets are reset.
2508 */
2509 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002510 if (mAppWidgetHost != null) {
2511 mAppWidgetHost.startListening();
2512 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002513 }
2514
2515 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002516 * Launches the intent referred by the clicked shortcut.
2517 *
2518 * @param v The view representing the clicked shortcut.
2519 */
2520 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002521 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2522 // view has detached (it's possible for this to happen if the view is removed mid touch).
2523 if (v.getWindowToken() == null) {
2524 return;
2525 }
2526
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002527 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002528 return;
2529 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002530
Adam Cohen1697b792013-09-17 19:08:21 -07002531 if (v instanceof Workspace) {
2532 if (mWorkspace.isInOverviewMode()) {
2533 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002534 }
2535 return;
2536 }
2537
2538 if (v instanceof CellLayout) {
2539 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002540 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002541 }
2542 }
2543
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002544 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002545 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002546 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002547 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002548 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002549 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002550 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002551 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002552 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002553 } else if (tag instanceof AppInfo) {
2554 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002555 } else if (tag instanceof LauncherAppWidgetInfo) {
2556 if (v instanceof PendingAppWidgetHostView) {
2557 onClickPendingWidget((PendingAppWidgetHostView) v);
2558 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002559 }
2560 }
2561
Sunny Goyal508da152014-08-14 10:53:27 -07002562 public void onClickPagedViewIcon(View v) {
2563 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002564 if (mLauncherCallbacks != null) {
2565 mLauncherCallbacks.onClickPagedViewIcon(v);
2566 }
Sunny Goyal508da152014-08-14 10:53:27 -07002567 }
2568
Michael Jurka0e260592010-06-30 17:07:39 -07002569 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002570 return false;
2571 }
2572
Michael Jurkaaf442092010-06-10 17:01:57 -07002573 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002574 * Event handler for the app widget view which has not fully restored.
2575 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002576 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002577 if (mIsSafeModeEnabled) {
2578 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2579 return;
2580 }
2581
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002582 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002583 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002584 int widgetId = info.appWidgetId;
2585 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2586 if (appWidgetInfo != null) {
Adam Cohen59400422014-03-05 18:07:04 -08002587 mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
2588 this, appWidgetInfo);
Sunny Goyalff572272014-07-23 13:58:07 -07002589 mPendingAddInfo.copyFrom(info);
2590 mPendingAddWidgetId = widgetId;
2591
Sunny Goyalffe83f12014-08-14 17:39:34 -07002592 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2593 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002594 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002595 } else if (info.installProgress < 0) {
2596 // The install has not been queued
2597 final String packageName = info.providerName.getPackageName();
2598 showBrokenAppInstallDialog(packageName,
2599 new DialogInterface.OnClickListener() {
2600 public void onClick(DialogInterface dialog, int id) {
2601 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2602 }
2603 });
2604 } else {
2605 // Download has started.
2606 final String packageName = info.providerName.getPackageName();
2607 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002608 }
2609 }
2610
2611 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002612 * Event handler for the "grid" button that appears on the home screen, which
2613 * enters all apps mode.
2614 *
2615 * @param v The view that was clicked.
2616 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617 protected void onClickAllAppsButton(View v) {
2618 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2619 if (isAllAppsVisible()) {
2620 showWorkspace(true);
2621 } else {
2622 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2623 }
Adam Cohen9211d422014-10-07 18:14:53 -07002624 if (mLauncherCallbacks != null) {
2625 mLauncherCallbacks.onClickAllAppsButton(v);
2626 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002627 }
2628
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002629 private void showBrokenAppInstallDialog(final String packageName,
2630 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyale03b8122014-10-08 09:55:24 -07002631 new AlertDialog.Builder(this)
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002632 .setTitle(R.string.abandoned_promises_title)
2633 .setMessage(R.string.abandoned_promise_explanation)
2634 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2635 .setNeutralButton(R.string.abandoned_clean_this,
2636 new DialogInterface.OnClickListener() {
2637 public void onClick(DialogInterface dialog, int id) {
2638 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2639 mWorkspace.removeAbandonedPromise(packageName, user);
2640 }
2641 })
2642 .create().show();
2643 return;
2644 }
2645
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002646 /**
2647 * Event handler for an app shortcut click.
2648 *
2649 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2650 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002651 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002652 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2653 Object tag = v.getTag();
2654 if (!(tag instanceof ShortcutInfo)) {
2655 throw new IllegalArgumentException("Input must be a Shortcut");
2656 }
2657
2658 // Open shortcut
2659 final ShortcutInfo shortcut = (ShortcutInfo) tag;
Sunny Goyal1a745e82014-10-02 15:58:31 -07002660
2661 if (shortcut.isDisabled != 0) {
2662 int error = R.string.activity_not_available;
2663 if ((shortcut.isDisabled & ShortcutInfo.FLAG_DISABLED_SAFEMODE) != 0) {
2664 error = R.string.safemode_shortcut_error;
2665 }
2666 Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
2667 return;
2668 }
2669
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002670 final Intent intent = shortcut.intent;
2671
2672 // Check for special shortcuts
2673 if (intent.getComponent() != null) {
2674 final String shortcutClass = intent.getComponent().getClassName();
2675
2676 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2677 MemoryDumpActivity.startDump(this);
2678 return;
2679 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2680 toggleShowWeightWatcher();
2681 return;
2682 }
2683 }
2684
Chris Wren40c5ed32014-06-24 18:24:23 -04002685 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002686 if ((v instanceof BubbleTextView)
2687 && shortcut.isPromise()
2688 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002689 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002690 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002691 new DialogInterface.OnClickListener() {
2692 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002693 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002694 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002695 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002696 return;
2697 }
2698
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002699 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002700 startAppShortcutOrInfoActivity(v);
Adam Cohen9211d422014-10-07 18:14:53 -07002701
2702 if (mLauncherCallbacks != null) {
2703 mLauncherCallbacks.onClickAppShortcut(v);
2704 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002705 }
2706
Sunny Goyal508da152014-08-14 10:53:27 -07002707 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002708 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002709 final ShortcutInfo shortcut;
2710 final Intent intent;
2711 if (tag instanceof ShortcutInfo) {
2712 shortcut = (ShortcutInfo) tag;
2713 intent = shortcut.intent;
2714 int[] pos = new int[2];
2715 v.getLocationOnScreen(pos);
2716 intent.setSourceBounds(new Rect(pos[0], pos[1],
2717 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002718
Sunny Goyal508da152014-08-14 10:53:27 -07002719 } else if (tag instanceof AppInfo) {
2720 shortcut = null;
2721 intent = ((AppInfo) tag).intent;
2722 } else {
2723 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2724 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002725
2726 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002727 mStats.recordLaunch(intent, shortcut);
2728
2729 if (success && v instanceof BubbleTextView) {
2730 mWaitingForResume = (BubbleTextView) v;
2731 mWaitingForResume.setStayPressed(true);
2732 }
2733 }
2734
2735 /**
2736 * Event handler for a folder icon click.
2737 *
2738 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2739 */
2740 protected void onClickFolderIcon(View v) {
2741 if (LOGD) Log.d(TAG, "onClickFolder");
2742 if (!(v instanceof FolderIcon)){
2743 throw new IllegalArgumentException("Input must be a FolderIcon");
2744 }
2745
2746 FolderIcon folderIcon = (FolderIcon) v;
2747 final FolderInfo info = folderIcon.getFolderInfo();
2748 Folder openFolder = mWorkspace.getFolderForTag(info);
2749
2750 // If the folder info reports that the associated folder is open, then verify that
2751 // it is actually opened. There have been a few instances where this gets out of sync.
2752 if (info.opened && openFolder == null) {
2753 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2754 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2755 info.opened = false;
2756 }
2757
2758 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2759 // Close any open folder
2760 closeFolder();
2761 // Open the requested folder
2762 openFolder(folderIcon);
2763 } else {
2764 // Find the open folder...
2765 int folderScreen;
2766 if (openFolder != null) {
2767 folderScreen = mWorkspace.getPageForView(openFolder);
2768 // .. and close it
2769 closeFolder(openFolder);
2770 if (folderScreen != mWorkspace.getCurrentPage()) {
2771 // Close any folder open on the current screen
2772 closeFolder();
2773 // Pull the folder onto this screen
2774 openFolder(folderIcon);
2775 }
2776 }
2777 }
Adam Cohen9211d422014-10-07 18:14:53 -07002778
2779 if (mLauncherCallbacks != null) {
2780 mLauncherCallbacks.onClickFolderIcon(v);
2781 }
Michael Jurka5130e402011-10-13 04:55:35 -07002782 }
2783
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002784 /**
2785 * Event handler for the (Add) Widgets button that appears after a long press
2786 * on the home screen.
2787 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002788 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002789 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sunny Goyal9b4b0812014-10-08 10:47:28 -07002790 if (mIsSafeModeEnabled) {
2791 Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
2792 } else {
2793 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2794 if (mLauncherCallbacks != null) {
2795 mLauncherCallbacks.onClickAddWidgetButton(view);
2796 }
Adam Cohen9211d422014-10-07 18:14:53 -07002797 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002798 }
2799
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002800 /**
2801 * Event handler for the wallpaper picker button that appears after a long press
2802 * on the home screen.
2803 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002804 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002805 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2806 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2807 pickWallpaper.setComponent(getWallpaperPickerComponent());
2808 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
Adam Cohen9211d422014-10-07 18:14:53 -07002809
2810 if (mLauncherCallbacks != null) {
2811 mLauncherCallbacks.onClickWallpaperPicker(v);
2812 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002813 }
2814
2815 /**
2816 * Event handler for a click on the settings button that appears after a long press
2817 * on the home screen.
2818 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002819 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002820 if (LOGD) Log.d(TAG, "onClickSettingsButton");
Adam Cohen9211d422014-10-07 18:14:53 -07002821 if (mLauncherCallbacks != null) {
2822 mLauncherCallbacks.onClickSettingsButton(v);
2823 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002824 }
2825
Michael Jurka5130e402011-10-13 04:55:35 -07002826 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002827 // Provide the same haptic feedback that the system offers for virtual keys.
2828 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002829 }
2830
Adam Cohen61f560d2013-09-30 15:58:20 -07002831 public void performHapticFeedbackOnTouchDown(View v) {
2832 // Provide the same haptic feedback that the system offers for virtual keys.
2833 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2834 }
2835
2836 public View.OnTouchListener getHapticFeedbackTouchListener() {
2837 if (mHapticFeedbackTouchListener == null) {
2838 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2839 @Override
2840 public boolean onTouch(View v, MotionEvent event) {
2841 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2842 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2843 }
2844 return false;
2845 }
2846 };
2847 }
2848 return mHapticFeedbackTouchListener;
2849 }
2850
Adam Cohen9211d422014-10-07 18:14:53 -07002851 public void onDragStarted(View view) {
2852 if (isOnCustomContent()) {
2853 // Custom content screen doesn't participate in drag and drop. If on custom
2854 // content screen, move to default.
2855 moveWorkspaceToDefaultScreen();
2856 }
2857
2858 if (mLauncherCallbacks != null) {
2859 mLauncherCallbacks.onDragStarted(view);
2860 }
2861 }
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002862
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002863 /**
2864 * Called when the user stops interacting with the launcher.
2865 * This implies that the user is now on the homescreen and is not doing housekeeping.
2866 */
Adam Cohen9211d422014-10-07 18:14:53 -07002867 protected void onInteractionEnd() {
2868 if (mLauncherCallbacks != null) {
2869 mLauncherCallbacks.onInteractionEnd();
2870 }
2871 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002872
2873 /**
2874 * Called when the user starts interacting with the launcher.
2875 * The possible interactions are:
2876 * - open all apps
2877 * - reorder an app shortcut, or a widget
2878 * - open the overview mode.
2879 * This is a good time to stop doing things that only make sense
2880 * when the user is on the homescreen and not doing housekeeping.
2881 */
Adam Cohen9211d422014-10-07 18:14:53 -07002882 protected void onInteractionBegin() {
2883 if (mLauncherCallbacks != null) {
2884 mLauncherCallbacks.onInteractionBegin();
2885 }
2886 }
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002887
Kenny Guyf07af7b2014-07-31 11:39:16 +01002888 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002889 try {
2890 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002891 launcherApps.showAppDetailsForProfile(componentName, user);
2892 } catch (SecurityException e) {
2893 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2894 Log.e(TAG, "Launcher does not have permission to launch settings");
2895 } catch (ActivityNotFoundException e) {
2896 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2897 Log.e(TAG, "Unable to launch settings");
2898 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002899 }
2900
Michael Jurka1e2f4652013-07-08 18:03:46 -07002901 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002902 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2903 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002904 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002905 // System applications cannot be installed. For now, show a toast explaining that.
2906 // We may give them the option of disabling apps this way.
2907 int messageId = R.string.uninstall_system_app_text;
2908 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002909 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002910 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002911 String packageName = componentName.getPackageName();
2912 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002913 Intent intent = new Intent(
2914 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002915 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2916 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002917 if (user != null) {
2918 user.addToIntent(intent, Intent.EXTRA_USER);
2919 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002920 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002921 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002922 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002923 }
2924
Michael Jurka86a720e2012-05-09 11:23:23 -07002925 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002926 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002927 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002928 // Only launch using the new animation if the shortcut has not opted out (this is a
2929 // private contract between launcher and may be ignored in the future).
2930 boolean useLaunchAnimation = (v != null) &&
2931 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002932 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2933 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002934
Kenny Guy1317e2d2014-05-08 18:52:50 +01002935 UserHandleCompat user = null;
2936 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2937 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2938 user = userManager.getUserForSerialNumber(serialNumber);
2939 }
2940
2941 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002942 if (useLaunchAnimation) {
Kenny Guyd794a3f2014-09-16 15:17:58 +01002943 ActivityOptions opts = Utilities.isLmpOrAbove() ?
Adam Cohen4da294d2014-07-28 10:56:19 -07002944 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2945 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002946 optsBundle = opts.toBundle();
2947 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002948
2949 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2950 // Could be launching some bookkeeping activity
2951 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002952 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002953 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002954 launcherApps.startActivityForProfile(intent.getComponent(), user,
2955 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002956 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002957 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002958 } catch (SecurityException e) {
2959 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002960 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002961 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002962 "or use the exported attribute for this activity. "
2963 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002964 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002965 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002966 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002967
Michael Jurka86a720e2012-05-09 11:23:23 -07002968 boolean startActivitySafely(View v, Intent intent, Object tag) {
2969 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002970 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2971 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2972 return false;
2973 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002974 try {
2975 success = startActivity(v, intent, tag);
2976 } catch (ActivityNotFoundException e) {
2977 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2978 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2979 }
2980 return success;
2981 }
2982
Adam Cohen268c4752012-06-06 17:47:33 -07002983 /**
2984 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2985 * in the DragLayer in the exact absolute location of the original FolderIcon.
2986 */
2987 private void copyFolderIconToImage(FolderIcon fi) {
2988 final int width = fi.getMeasuredWidth();
2989 final int height = fi.getMeasuredHeight();
2990
2991 // Lazy load ImageView, Bitmap and Canvas
2992 if (mFolderIconImageView == null) {
2993 mFolderIconImageView = new ImageView(this);
2994 }
2995 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2996 mFolderIconBitmap.getHeight() != height) {
2997 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2998 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2999 }
3000
3001 DragLayer.LayoutParams lp;
3002 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
3003 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
3004 } else {
3005 lp = new DragLayer.LayoutParams(width, height);
3006 }
3007
Adam Cohen307fe232012-08-16 17:55:58 -07003008 // The layout from which the folder is being opened may be scaled, adjust the starting
3009 // view size by this scale factor.
3010 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07003011 lp.customPosition = true;
3012 lp.x = mRectForFolderAnimation.left;
3013 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07003014 lp.width = (int) (scale * width);
3015 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07003016
3017 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3018 fi.draw(mFolderIconCanvas);
3019 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07003020 if (fi.getFolder() != null) {
3021 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3022 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07003023 }
Adam Cohen268c4752012-06-06 17:47:33 -07003024 // Just in case this image view is still in the drag layer from a previous animation,
3025 // we remove it and re-add it.
3026 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3027 mDragLayer.removeView(mFolderIconImageView);
3028 }
3029 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07003030 if (fi.getFolder() != null) {
3031 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07003032 }
Adam Cohen268c4752012-06-06 17:47:33 -07003033 }
3034
Adam Cohen2801caf2011-05-13 20:57:39 -07003035 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003036 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003037 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
3038 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
3039 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
3040
Adam Cohenc51934b2011-07-26 21:07:43 -07003041 FolderInfo info = (FolderInfo) fi.getTag();
3042 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3043 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07003044 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3045 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07003046 }
3047
Adam Cohen268c4752012-06-06 17:47:33 -07003048 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3049 copyFolderIconToImage(fi);
3050 fi.setVisibility(View.INVISIBLE);
3051
Michael Jurka2ecf9952012-06-18 12:52:28 -07003052 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003053 scaleX, scaleY);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003054 if (Utilities.isLmpOrAbove()) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003055 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3056 }
3057 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003058 oa.start();
3059 }
3060
Adam Cohen268c4752012-06-06 17:47:33 -07003061 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07003062 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07003063 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3064 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3065 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3066
Adam Cohen268c4752012-06-06 17:47:33 -07003067 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003068
Adam Cohen268c4752012-06-06 17:47:33 -07003069 // We remove and re-draw the FolderIcon in-case it has changed
3070 mDragLayer.removeView(mFolderIconImageView);
3071 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003072 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003073 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003074 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003075 oa.addListener(new AnimatorListenerAdapter() {
3076 @Override
3077 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003078 if (cl != null) {
3079 cl.clearFolderLeaveBehind();
3080 // Remove the ImageView copy of the FolderIcon and make the original visible.
3081 mDragLayer.removeView(mFolderIconImageView);
3082 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003083 }
3084 }
3085 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003086 oa.start();
3087 }
3088
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003089 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003090 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003091 * is animated relative to the specified View. If the View is null, no animation
3092 * is played.
3093 *
3094 * @param folderInfo The FolderInfo describing the folder to open.
3095 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003096 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003097 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07003098 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003099
Adam Cohena9cf38f2011-05-02 15:36:58 -07003100 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003101
Adam Cohen4554ee12011-08-03 16:13:21 -07003102 // Just verify that the folder hasn't already been added to the DragLayer.
3103 // There was a one-off crash where the folder had a parent already.
3104 if (folder.getParent() == null) {
3105 mDragLayer.addView(folder);
3106 mDragController.addDropTarget((DropTarget) folder);
3107 } else {
3108 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3109 folder.getParent() + ").");
3110 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003111 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003112 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003113
3114 // Notify the accessibility manager that this folder "window" has appeared and occluded
3115 // the workspace items
3116 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3117 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003118 }
3119
3120 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003121 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003122 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003123 if (folder.isEditingName()) {
3124 folder.dismissEditingName();
3125 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003126 closeFolder(folder);
3127 }
3128 }
3129
3130 void closeFolder(Folder folder) {
3131 folder.getInfo().opened = false;
3132
3133 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3134 if (parent != null) {
3135 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3136 shrinkAndFadeInFolderIcon(fi);
3137 }
3138 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003139
3140 // Notify the accessibility manager that this folder "window" has disappeard and no
3141 // longer occludeds the workspace items
3142 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003143 }
3144
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003145 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003146 if (!isDraggingEnabled()) return false;
3147 if (isWorkspaceLocked()) return false;
3148 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003149
Adam Cohen1697b792013-09-17 19:08:21 -07003150 if (v instanceof Workspace) {
3151 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003152 if (mWorkspace.enterOverviewMode()) {
3153 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3154 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3155 return true;
3156 } else {
3157 return false;
3158 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003159 } else {
3160 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003161 }
Adam Cohen1697b792013-09-17 19:08:21 -07003162 }
3163
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003164 CellLayout.CellInfo longClickCellInfo = null;
3165 View itemUnderLongClick = null;
3166 if (v.getTag() instanceof ItemInfo) {
3167 ItemInfo info = (ItemInfo) v.getTag();
3168 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3169 itemUnderLongClick = longClickCellInfo.cell;
3170 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003171 }
3172
Winson Chung3d503fb2011-07-13 17:25:49 -07003173 // The hotseat touch handling does not go through Workspace, and we always allow long press
3174 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003175 final boolean inHotseat = isHotseatLayout(v);
3176 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003177 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003178 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003179 // User long pressed on empty space
3180 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3181 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003182 if (mWorkspace.isInOverviewMode()) {
3183 mWorkspace.startReordering(v);
3184 } else {
3185 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003186 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003187 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003188 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3189 mHotseat.getOrderInHotseat(
3190 longClickCellInfo.cellX,
3191 longClickCellInfo.cellY));
3192 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003193 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003194 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003195 }
3196 }
3197 }
3198 return true;
3199 }
3200
Winson Chung3d503fb2011-07-13 17:25:49 -07003201 boolean isHotseatLayout(View layout) {
3202 return mHotseat != null && layout != null &&
3203 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3204 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003205
Winson Chung3d503fb2011-07-13 17:25:49 -07003206 /**
3207 * Returns the CellLayout of the specified container at the specified screen.
3208 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003209 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003210 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3211 if (mHotseat != null) {
3212 return mHotseat.getLayout();
3213 } else {
3214 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003215 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003216 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003217 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003218 }
3219 }
3220
Daniel Sandler843e8602010-06-07 14:59:01 -04003221 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003222 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003223 }
3224
Craig Mautner360310b2012-10-26 15:13:08 -07003225 private void setWorkspaceBackground(boolean workspace) {
3226 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003227 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003228 }
3229
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003230 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003231 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3232 int curflags = getWindow().getAttributes().flags
3233 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3234 if (wpflags != curflags) {
3235 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3236 }
Craig Mautner360310b2012-10-26 15:13:08 -07003237 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003238 }
3239
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003240 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3241 if (v instanceof LauncherTransitionable) {
3242 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3243 }
3244 }
3245
Michael Jurkabed61d22012-02-14 22:51:29 -08003246 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3247 if (v instanceof LauncherTransitionable) {
3248 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3249 }
Winson Chung70442722012-02-10 15:43:22 -08003250
3251 // Update the workspace transition step as well
3252 dispatchOnLauncherTransitionStep(v, 0f);
3253 }
3254
3255 private void dispatchOnLauncherTransitionStep(View v, float t) {
3256 if (v instanceof LauncherTransitionable) {
3257 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3258 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003259 }
3260
3261 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3262 if (v instanceof LauncherTransitionable) {
3263 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3264 }
Winson Chung70442722012-02-10 15:43:22 -08003265
3266 // Update the workspace transition step as well
3267 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003268 }
3269
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003270 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003271 * Things to test when changing the following seven functions.
3272 * - Home from workspace
3273 * - from center screen
3274 * - from other screens
3275 * - Home from all apps
3276 * - from center screen
3277 * - from other screens
3278 * - Back from all apps
3279 * - from center screen
3280 * - from other screens
3281 * - Launch app from workspace and quit
3282 * - with back
3283 * - with home
3284 * - Launch app from all apps and quit
3285 * - with back
3286 * - with home
3287 * - Go to a screen that's not the default, then all
3288 * apps, and launch and app, and go back
3289 * - with back
3290 * -with home
3291 * - On workspace, long press power and go back
3292 * - with back
3293 * - with home
3294 * - On all apps, long press power and go back
3295 * - with back
3296 * - with home
3297 * - On workspace, power off
3298 * - On all apps, power off
3299 * - Launch an app and turn off the screen while in that app
3300 * - Go back with home key
3301 * - Go back with back key TODO: make this not go to workspace
3302 * - From all apps
3303 * - From workspace
3304 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3305 * - From all apps
3306 * - From the center workspace
3307 * - From another workspace
3308 */
3309
3310 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003311 * Zoom the camera out from the workspace to reveal 'toView'.
3312 * Assumes that the view to show is anchored at either the very top or very bottom
3313 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003314 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003315 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003316 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3317 showAppsCustomizeHelper(animated, springLoaded, contentType);
3318 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003319
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08003320 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
Winson Chungc58497e2013-09-03 17:48:37 -07003321 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3322 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003323 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003324 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003325 mStateAnimation.cancel();
3326 mStateAnimation = null;
3327 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003328
Kenny Guyd794a3f2014-09-16 15:17:58 +01003329 boolean material = Utilities.isLmpOrAbove();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003330
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003331 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003332
Adam Cohen6c5891a2014-07-09 23:53:15 -07003333 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003334 final int itemsAlphaStagger =
3335 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003336
Michael Jurkabed61d22012-02-14 22:51:29 -08003337 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003338 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003339
Adam Cohen80e6beb2015-02-13 16:14:33 -08003340 final HashMap<View, Integer> layerViews = new HashMap<View, Integer>();
Adam Cohen2854d252014-08-27 16:04:07 -07003341
Adam Cohen6c5891a2014-07-09 23:53:15 -07003342 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3343 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003344 Animator workspaceAnim =
Adam Cohen2854d252014-08-27 16:04:07 -07003345 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003346 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003347 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3348 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003349 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3350 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003351
Adam Cohena38dc902014-09-07 17:48:55 +02003352 // If for some reason our views aren't initialized, don't animate
3353 boolean initialized = getAllAppsButton() != null;
3354
3355 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003356 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003357 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3358 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003359
Adam Cohen9bfdb762014-07-21 17:44:06 -07003360 final View page = content.getPageAt(content.getCurrentPage());
3361 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003362
Adam Cohen63f1ec02014-08-12 09:23:13 -07003363 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3364 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003365 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3366 } else {
3367 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3368 }
3369
Adam Cohen9bfdb762014-07-21 17:44:06 -07003370 // Hide the real page background, and swap in the fake one
Adam Cohen9bfdb762014-07-21 17:44:06 -07003371 content.setPageBackgroundsVisible(false);
Adam Cohen2854d252014-08-27 16:04:07 -07003372 revealView.setVisibility(View.VISIBLE);
3373 // We need to hide this view as the animation start will be posted.
3374 revealView.setAlpha(0);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003375
Adam Cohen9bfdb762014-07-21 17:44:06 -07003376 int width = revealView.getMeasuredWidth();
3377 int height = revealView.getMeasuredHeight();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003378 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen2854d252014-08-27 16:04:07 -07003379
Adam Cohen63f1ec02014-08-12 09:23:13 -07003380 revealView.setTranslationY(0);
Adam Cohen94afab42014-08-24 16:10:54 -07003381 revealView.setTranslationX(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003382
Adam Cohen63f1ec02014-08-12 09:23:13 -07003383 // Get the y delta between the center of the page and the center of the all apps button
3384 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3385 getAllAppsButton(), null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003386
Adam Cohen2854d252014-08-27 16:04:07 -07003387 float alpha = 0;
3388 float xDrift = 0;
3389 float yDrift = 0;
3390 if (material) {
3391 alpha = isWidgetTray ? 0.3f : 1f;
3392 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3393 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3394 } else {
3395 yDrift = 2 * height / 3;
3396 xDrift = 0;
3397 }
3398 final float initAlpha = alpha;
3399
Adam Cohen80e6beb2015-02-13 16:14:33 -08003400 layerViews.put(revealView, BUILD_AND_SET_LAYER);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003401 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen94afab42014-08-24 16:10:54 -07003402 PropertyValuesHolder panelDriftY =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003403 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen94afab42014-08-24 16:10:54 -07003404 PropertyValuesHolder panelDriftX =
3405 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003406
Adam Cohen2854d252014-08-27 16:04:07 -07003407 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3408 panelAlpha, panelDriftY, panelDriftX);
3409
Adam Cohen9bfdb762014-07-21 17:44:06 -07003410 panelAlphaAndDrift.setDuration(revealDuration);
3411 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003412
Adam Cohen9bfdb762014-07-21 17:44:06 -07003413 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003414
Adam Cohen4e243a22014-08-10 18:30:55 -07003415 if (page != null) {
3416 page.setVisibility(View.VISIBLE);
Adam Cohen80e6beb2015-02-13 16:14:33 -08003417 layerViews.put(page, BUILD_AND_SET_LAYER);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003418
Adam Cohen2854d252014-08-27 16:04:07 -07003419 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3420 page.setTranslationY(yDrift);
Adam Cohen4e243a22014-08-10 18:30:55 -07003421 pageDrift.setDuration(revealDuration);
3422 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003423 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003424 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003425
Adam Cohen63f1ec02014-08-12 09:23:13 -07003426 page.setAlpha(0f);
Adam Cohen2854d252014-08-27 16:04:07 -07003427 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003428 itemsAlpha.setDuration(revealDuration);
3429 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3430 itemsAlpha.setStartDelay(itemsAlphaStagger);
3431 mStateAnimation.play(itemsAlpha);
3432 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003433
Adam Cohen4e243a22014-08-10 18:30:55 -07003434 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3435 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003436 ObjectAnimator indicatorsAlpha =
Adam Cohen2854d252014-08-27 16:04:07 -07003437 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003438 indicatorsAlpha.setDuration(revealDuration);
3439 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003440
Adam Cohen9bfdb762014-07-21 17:44:06 -07003441 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003442 final View allApps = getAllAppsButton();
3443 int allAppsButtonSize = LauncherAppState.getInstance().
3444 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3445 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohen2854d252014-08-27 16:04:07 -07003446 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003447 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003448 reveal.setDuration(revealDuration);
3449 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003450
3451 reveal.addListener(new AnimatorListenerAdapter() {
3452 public void onAnimationStart(Animator animation) {
3453 if (!isWidgetTray) {
3454 allApps.setVisibility(View.INVISIBLE);
3455 }
3456 }
3457 public void onAnimationEnd(Animator animation) {
3458 if (!isWidgetTray) {
3459 allApps.setVisibility(View.VISIBLE);
3460 }
3461 }
3462 });
Adam Cohen6c5891a2014-07-09 23:53:15 -07003463 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003464 }
Michael Jurka1899a362011-11-03 13:50:45 -07003465
Adam Cohen9bfdb762014-07-21 17:44:06 -07003466 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3467 @Override
3468 public void onAnimationEnd(Animator animation) {
3469 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3470 dispatchOnLauncherTransitionEnd(toView, animated, false);
3471
3472 revealView.setVisibility(View.INVISIBLE);
Adam Cohen80e6beb2015-02-13 16:14:33 -08003473
3474 for (View v : layerViews.keySet()) {
3475 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3476 v.setLayerType(View.LAYER_TYPE_NONE, null);
3477 }
Adam Cohen4e243a22014-08-10 18:30:55 -07003478 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003479 content.setPageBackgroundsVisible(true);
3480
3481 // Hide the search bar
3482 if (mSearchDropTargetBar != null) {
3483 mSearchDropTargetBar.hideSearchBar(false);
3484 }
Adam Cohen3f9c9712014-10-31 11:48:25 -07003485
3486 // This can hold unnecessary references to views.
3487 mStateAnimation = null;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003488 }
3489
Adam Cohen9bfdb762014-07-21 17:44:06 -07003490 });
3491
Adam Cohen6c5891a2014-07-09 23:53:15 -07003492 if (workspaceAnim != null) {
3493 mStateAnimation.play(workspaceAnim);
3494 }
Adam Cohen2854d252014-08-27 16:04:07 -07003495
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003496 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3497 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003498 final AnimatorSet stateAnimation = mStateAnimation;
3499 final Runnable startAnimRunnable = new Runnable() {
3500 public void run() {
3501 // Check that mStateAnimation hasn't changed while
3502 // we waited for a layout/draw pass
3503 if (mStateAnimation != stateAnimation)
3504 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003505 dispatchOnLauncherTransitionStart(fromView, animated, false);
3506 dispatchOnLauncherTransitionStart(toView, animated, false);
Adam Cohen2854d252014-08-27 16:04:07 -07003507
3508 revealView.setAlpha(initAlpha);
Adam Cohen80e6beb2015-02-13 16:14:33 -08003509
3510 for (View v : layerViews.keySet()) {
3511 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3512 v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3513 }
3514 }
3515
Kenny Guyd794a3f2014-09-16 15:17:58 +01003516 if (Utilities.isLmpOrAbove()) {
Adam Cohen80e6beb2015-02-13 16:14:33 -08003517 for (View v : layerViews.keySet()) {
3518 if (Utilities.isViewAttachedToWindow(v)) v.buildLayer();
Adam Cohen2854d252014-08-27 16:04:07 -07003519 }
3520 }
3521 mStateAnimation.start();
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003522 }
3523 };
Adam Cohen2854d252014-08-27 16:04:07 -07003524 toView.bringToFront();
3525 toView.setVisibility(View.VISIBLE);
3526 toView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003527 } else {
3528 toView.setTranslationX(0.0f);
3529 toView.setTranslationY(0.0f);
3530 toView.setScaleX(1.0f);
3531 toView.setScaleY(1.0f);
3532 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003533 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003534
Daniel Sandlere4f98912013-06-25 15:13:26 -04003535 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003536 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003537 if (mSearchDropTargetBar != null) {
3538 mSearchDropTargetBar.hideSearchBar(false);
3539 }
Michael Jurkaabded662011-03-04 12:06:57 -08003540 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003541 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003542 dispatchOnLauncherTransitionStart(fromView, animated, false);
3543 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003544 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003545 dispatchOnLauncherTransitionStart(toView, animated, false);
3546 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003547 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003548 }
3549
3550 /**
3551 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003552 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003553 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003554 */
Adam Cohened307df2013-10-02 09:37:31 -07003555 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003556 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003557
Michael Jurkab3e22d92011-10-31 15:58:33 -07003558 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003559 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003560 mStateAnimation.cancel();
3561 mStateAnimation = null;
3562 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003563
Kenny Guyd794a3f2014-09-16 15:17:58 +01003564 boolean material = Utilities.isLmpOrAbove();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003565 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003566
Adam Cohen63f1ec02014-08-12 09:23:13 -07003567 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003568 final int itemsAlphaStagger =
3569 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003570
Winson Chungf0ea4d32011-06-06 14:27:16 -07003571 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003572 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003573 Animator workspaceAnim = null;
Adam Cohen80e6beb2015-02-13 16:14:33 -08003574 final HashMap<View, Integer> layerViews = new HashMap<View, Integer>();
Adam Cohen2854d252014-08-27 16:04:07 -07003575
Adam Cohened307df2013-10-02 09:37:31 -07003576 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003577 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003578 toState, animated, layerViews);
Adam Cohened307df2013-10-02 09:37:31 -07003579 } else if (toState == Workspace.State.SPRING_LOADED ||
3580 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003581 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003582 toState, animated, layerViews);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003583 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003584
Adam Cohena38dc902014-09-07 17:48:55 +02003585 // If for some reason our views aren't initialized, don't animate
3586 boolean initialized = getAllAppsButton() != null;
3587
3588 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003589 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen2854d252014-08-27 16:04:07 -07003590 if (workspaceAnim != null) {
3591 mStateAnimation.play(workspaceAnim);
3592 }
Michael Jurka159b4cc2012-01-17 03:00:35 -08003593
Adam Cohen9bfdb762014-07-21 17:44:06 -07003594 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3595 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003596
Adam Cohen9bfdb762014-07-21 17:44:06 -07003597 final View page = content.getPageAt(content.getNextPage());
Adam Cohen8e894fa2014-09-08 19:45:43 +02003598
3599 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3600 int count = content.getChildCount();
3601 for (int i = 0; i < count; i++) {
3602 View child = content.getChildAt(i);
3603 if (child != page) {
3604 child.setVisibility(View.INVISIBLE);
3605 }
3606 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003607 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003608
Adam Cohen2854d252014-08-27 16:04:07 -07003609 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3610 // don't perform all these no-op animations. In particularly, this was causing
3611 // the all-apps button to pop in and out.
3612 if (fromView.getVisibility() == View.VISIBLE) {
3613 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3614 final boolean isWidgetTray =
3615 contentType == AppsCustomizePagedView.ContentType.Widgets;
Adam Cohen63f1ec02014-08-12 09:23:13 -07003616
Adam Cohen2854d252014-08-27 16:04:07 -07003617 if (isWidgetTray) {
3618 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3619 } else {
3620 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003621 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003622
Adam Cohen2854d252014-08-27 16:04:07 -07003623 int width = revealView.getMeasuredWidth();
3624 int height = revealView.getMeasuredHeight();
3625 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3626
3627 // Hide the real page background, and swap in the fake one
3628 revealView.setVisibility(View.VISIBLE);
3629 content.setPageBackgroundsVisible(false);
3630
3631 final View allAppsButton = getAllAppsButton();
3632 revealView.setTranslationY(0);
3633 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3634 allAppsButton, null);
3635
3636 float xDrift = 0;
3637 float yDrift = 0;
3638 if (material) {
3639 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3640 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3641 } else {
Adam Cohen0fb5ce22014-10-24 13:50:20 -07003642 yDrift = 2 * height / 3;
Adam Cohen2854d252014-08-27 16:04:07 -07003643 xDrift = 0;
3644 }
3645
Adam Cohen80e6beb2015-02-13 16:14:33 -08003646 layerViews.put(revealView, BUILD_AND_SET_LAYER);
Adam Cohen2854d252014-08-27 16:04:07 -07003647 TimeInterpolator decelerateInterpolator = material ?
3648 new LogDecelerateInterpolator(100, 0) :
Adam Cohen0fb5ce22014-10-24 13:50:20 -07003649 new DecelerateInterpolator(1f);
Adam Cohen2854d252014-08-27 16:04:07 -07003650
3651 // The vertical motion of the apps panel should be delayed by one frame
3652 // from the conceal animation in order to give the right feel. We correpsondingly
3653 // shorten the duration so that the slide and conceal end at the same time.
3654 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3655 0, yDrift);
3656 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3657 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3658 panelDriftY.setInterpolator(decelerateInterpolator);
3659 mStateAnimation.play(panelDriftY);
3660
3661 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3662 0, xDrift);
3663 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3664 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3665 panelDriftX.setInterpolator(decelerateInterpolator);
3666 mStateAnimation.play(panelDriftX);
3667
3668 if (isWidgetTray || !material) {
3669 float finalAlpha = material ? 0.4f : 0f;
3670 revealView.setAlpha(1f);
3671 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3672 1f, finalAlpha);
Adam Cohen0fb5ce22014-10-24 13:50:20 -07003673 panelAlpha.setDuration(material ? revealDuration : 150);
3674 panelAlpha.setInterpolator(decelerateInterpolator);
3675 panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen2854d252014-08-27 16:04:07 -07003676 mStateAnimation.play(panelAlpha);
3677 }
3678
3679 if (page != null) {
Adam Cohen80e6beb2015-02-13 16:14:33 -08003680 layerViews.put(page, BUILD_AND_SET_LAYER);
Adam Cohen2854d252014-08-27 16:04:07 -07003681
3682 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3683 0, yDrift);
3684 page.setTranslationY(0);
3685 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3686 pageDrift.setInterpolator(decelerateInterpolator);
3687 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3688 mStateAnimation.play(pageDrift);
3689
3690 page.setAlpha(1f);
3691 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3692 itemsAlpha.setDuration(100);
3693 itemsAlpha.setInterpolator(decelerateInterpolator);
3694 mStateAnimation.play(itemsAlpha);
3695 }
3696
3697 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3698 pageIndicators.setAlpha(1f);
3699 ObjectAnimator indicatorsAlpha =
3700 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3701 indicatorsAlpha.setDuration(revealDuration);
3702 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3703 mStateAnimation.play(indicatorsAlpha);
3704
3705 width = revealView.getMeasuredWidth();
3706
3707 if (material) {
3708 if (!isWidgetTray) {
3709 allAppsButton.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003710 }
Adam Cohen2854d252014-08-27 16:04:07 -07003711 int allAppsButtonSize = LauncherAppState.getInstance().
3712 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3713 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3714 Animator reveal =
3715 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3716 height / 2, revealRadius, finalRadius);
3717 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3718 reveal.setDuration(revealDuration);
3719 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003720
Adam Cohen2854d252014-08-27 16:04:07 -07003721 reveal.addListener(new AnimatorListenerAdapter() {
3722 public void onAnimationEnd(Animator animation) {
3723 revealView.setVisibility(View.INVISIBLE);
3724 if (!isWidgetTray) {
3725 allAppsButton.setVisibility(View.VISIBLE);
3726 }
3727 }
3728 });
Adam Cohen9bfdb762014-07-21 17:44:06 -07003729
Adam Cohen2854d252014-08-27 16:04:07 -07003730 mStateAnimation.play(reveal);
3731 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003732
Adam Cohen2854d252014-08-27 16:04:07 -07003733 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3734 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3735 mAppsCustomizeContent.stopScrolling();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003736 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003737
3738 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003739 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003740 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003741 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003742 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3743 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003744 if (onCompleteRunnable != null) {
3745 onCompleteRunnable.run();
3746 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003747
Adam Cohen80e6beb2015-02-13 16:14:33 -08003748 for (View v : layerViews.keySet()) {
3749 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3750 v.setLayerType(View.LAYER_TYPE_NONE, null);
3751 }
Adam Cohen4e243a22014-08-10 18:30:55 -07003752 }
Adam Cohen80e6beb2015-02-13 16:14:33 -08003753
Adam Cohen9bfdb762014-07-21 17:44:06 -07003754 content.setPageBackgroundsVisible(true);
Adam Cohen8e894fa2014-09-08 19:45:43 +02003755 // Unhide side pages
3756 int count = content.getChildCount();
3757 for (int i = 0; i < count; i++) {
3758 View child = content.getChildAt(i);
3759 child.setVisibility(View.VISIBLE);
3760 }
3761
3762 // Reset page transforms
Adam Cohen493f6bc2014-09-18 08:11:05 -07003763 if (page != null) {
3764 page.setTranslationX(0);
3765 page.setTranslationY(0);
3766 page.setAlpha(1);
3767 }
Adam Cohen8e894fa2014-09-08 19:45:43 +02003768 content.setCurrentPage(content.getNextPage());
3769
Chet Haasebc2f0822012-10-26 17:59:53 -07003770 mAppsCustomizeContent.updateCurrentPageScroll();
Adam Cohen3f9c9712014-10-31 11:48:25 -07003771
3772 // This can hold unnecessary references to views.
3773 mStateAnimation = null;
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003774 }
3775 });
3776
Adam Cohen2854d252014-08-27 16:04:07 -07003777 final AnimatorSet stateAnimation = mStateAnimation;
3778 final Runnable startAnimRunnable = new Runnable() {
3779 public void run() {
3780 // Check that mStateAnimation hasn't changed while
3781 // we waited for a layout/draw pass
3782 if (mStateAnimation != stateAnimation)
3783 return;
3784 dispatchOnLauncherTransitionStart(fromView, animated, false);
3785 dispatchOnLauncherTransitionStart(toView, animated, false);
3786
Adam Cohen80e6beb2015-02-13 16:14:33 -08003787 for (View v : layerViews.keySet()) {
3788 if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
3789 v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3790 }
3791 }
3792
Kenny Guyd794a3f2014-09-16 15:17:58 +01003793 if (Utilities.isLmpOrAbove()) {
Adam Cohen80e6beb2015-02-13 16:14:33 -08003794 for (View v : layerViews.keySet()) {
3795 if (Utilities.isViewAttachedToWindow(v)) v.buildLayer();
Adam Cohen2854d252014-08-27 16:04:07 -07003796 }
3797 }
3798 mStateAnimation.start();
3799 }
3800 };
3801 fromView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003802 } else {
3803 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003804 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003805 dispatchOnLauncherTransitionStart(fromView, animated, true);
3806 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003807 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003808 dispatchOnLauncherTransitionStart(toView, animated, true);
3809 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003810 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003811 }
3812
Michael Jurkae326f182011-11-21 14:05:46 -08003813 @Override
3814 public void onTrimMemory(int level) {
3815 super.onTrimMemory(level);
Adam Cohen3f9c9712014-10-31 11:48:25 -07003816 if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
3817 // The widget preview db can result in holding onto over
3818 // 3MB of memory for caching which isn't necessary.
3819 SQLiteDatabase.releaseMemory();
3820
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003821 // This clears all widget bitmaps from the widget tray
Adam Cohen3f9c9712014-10-31 11:48:25 -07003822 if (mAppsCustomizeTabHost != null) {
Adam Cohenc8f4e1b2014-11-19 16:03:20 -08003823 mAppsCustomizeTabHost.trimMemory();
Adam Cohen3f9c9712014-10-31 11:48:25 -07003824 }
Michael Jurkae326f182011-11-21 14:05:46 -08003825 }
Robert Kozikowski67c30862015-03-30 23:46:46 +01003826 if (mLauncherCallbacks != null) {
3827 mLauncherCallbacks.onTrimMemory(level);
3828 }
Michael Jurkae326f182011-11-21 14:05:46 -08003829 }
3830
Adam Cohened307df2013-10-02 09:37:31 -07003831 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003832 showWorkspace(animated, null);
3833 }
3834
Adam Cohened307df2013-10-02 09:37:31 -07003835 protected void showWorkspace() {
3836 showWorkspace(true);
3837 }
3838
Adam Cohened66b2b2012-01-23 17:28:51 -08003839 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003840 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003841 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003842 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003843 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003844
Winson Chungc7d2b602012-05-16 17:02:20 -07003845 // Show the search bar (only animate if we were showing the drop target bar in spring
3846 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003847 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003848 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003849 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003850
Michael Jurkab3e22d92011-10-31 15:58:33 -07003851 // Set focus to the AppsCustomize button
3852 if (mAllAppsButton != null) {
3853 mAllAppsButton.requestFocus();
3854 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003855 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003856
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003857 // Change the state *after* we've called all the transition code
3858 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003859
Winson Chung5fb63472011-02-02 17:03:37 -08003860 // Resume the auto-advance of widgets
3861 mUserPresent = true;
3862 updateRunning();
3863
alanv1d4fde62012-10-17 13:15:47 -07003864 // Send an accessibility event to announce the context change
3865 getWindow().getDecorView()
3866 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003867
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003868 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003869 }
3870
Adam Cohened307df2013-10-02 09:37:31 -07003871 void showOverviewMode(boolean animated) {
3872 mWorkspace.setVisibility(View.VISIBLE);
3873 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3874 mState = State.WORKSPACE;
3875 onWorkspaceShown(animated);
3876 }
3877
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003878 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003879 }
3880
Winson Chung82963d52013-10-09 11:20:57 -07003881 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3882 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003883 if (mState != State.WORKSPACE) return;
3884
Winson Chung82963d52013-10-09 11:20:57 -07003885 if (resetPageToZero) {
3886 mAppsCustomizeTabHost.reset();
3887 }
Winson Chungc58497e2013-09-03 17:48:37 -07003888 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003889 mAppsCustomizeTabHost.post(new Runnable() {
3890 @Override
3891 public void run() {
3892 // We post this in-case the all apps view isn't yet constructed.
3893 mAppsCustomizeTabHost.requestFocus();
3894 }
3895 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003896
Michael Jurkab3e22d92011-10-31 15:58:33 -07003897 // Change the state *after* we've called all the transition code
3898 mState = State.APPS_CUSTOMIZE;
3899
3900 // Pause the auto-advance of widgets until we are out of AllApps
3901 mUserPresent = false;
3902 updateRunning();
3903 closeFolder();
3904
3905 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003906 getWindow().getDecorView()
3907 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003908 }
3909
Adam Cohen7777d962011-08-18 18:58:38 -07003910 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003911 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003912 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003913 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003914 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003915 }
Adam Cohen7777d962011-08-18 18:58:38 -07003916
Adam Cohenad4e15c2013-10-17 16:21:35 -07003917 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003918 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003919 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3920
Winson Chunge7a03942011-08-05 15:05:12 -07003921 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003922 @Override
3923 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003924 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003925 // Before we show workspace, hide all apps again because
3926 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3927 // clean up our state transition functions
3928 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003929 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003930 } else {
3931 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003932 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003933 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003934 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003935 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003936
Michael Jurkad3ef3062010-11-23 16:23:58 -08003937 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003938 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003939 final boolean animated = true;
3940 final boolean springLoaded = true;
3941 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003942 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003943 }
3944 // Otherwise, we are not in spring loaded mode, so don't do anything.
3945 }
3946
Michael Jurkab3e22d92011-10-31 15:58:33 -07003947 void lockAllApps() {
3948 // TODO
3949 }
3950
3951 void unlockAllApps() {
3952 // TODO
3953 }
3954
Sunny Goyal594d76d2014-11-06 10:12:54 -08003955 protected void disableVoiceButtonProxy(boolean disable) {
3956 // NO-OP
Winson Chungbb185bd2011-11-21 12:31:42 -08003957 }
3958
Cristina Stancu476493b2013-08-07 17:20:14 +01003959 public View getQsbBar() {
Adam Cohenc2d6e892014-10-16 09:49:24 -07003960 if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
3961 return mLauncherCallbacks.getQsbBar();
Adam Cohen9211d422014-10-07 18:14:53 -07003962 }
3963
Adam Cohen24ce0b32014-01-14 16:18:14 -08003964 if (mQsb == null) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003965 AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this);
3966 if (searchProvider == null) {
3967 return null;
3968 }
3969
3970 Bundle opts = new Bundle();
3971 opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
3972 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
3973
3974 SharedPreferences sp = getSharedPreferences(
3975 LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
3976 int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
Sunny Goyal416541c2014-11-14 11:59:57 -08003977 AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
Sunny Goyal594d76d2014-11-06 10:12:54 -08003978 if (!searchProvider.provider.flattenToString().equals(
3979 sp.getString(QSB_WIDGET_PROVIDER, null))
Sunny Goyal416541c2014-11-14 11:59:57 -08003980 || (widgetInfo == null)
3981 || !widgetInfo.provider.equals(searchProvider.provider)) {
Sunny Goyal594d76d2014-11-06 10:12:54 -08003982 // A valid widget is not already bound.
3983 if (widgetId > -1) {
3984 mAppWidgetHost.deleteAppWidgetId(widgetId);
3985 widgetId = -1;
3986 }
3987
3988 // Try to bind a new widget
3989 widgetId = mAppWidgetHost.allocateAppWidgetId();
3990
3991 if (!AppWidgetManagerCompat.getInstance(this)
3992 .bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
3993 mAppWidgetHost.deleteAppWidgetId(widgetId);
3994 widgetId = -1;
3995 }
3996
3997 sp.edit()
3998 .putInt(QSB_WIDGET_ID, widgetId)
3999 .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
4000 .commit();
4001 }
4002
4003 if (widgetId != -1) {
4004 mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider);
4005 mQsb.updateAppWidgetOptions(opts);
4006 mQsb.setPadding(0, 0, 0, 0);
4007 mSearchDropTargetBar.addView(mQsb);
4008 }
Cristina Stancu476493b2013-08-07 17:20:14 +01004009 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08004010 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01004011 }
4012
Michael Jurkad7c28052012-04-27 15:43:36 -07004013 @Override
4014 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004015 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004016 final List<CharSequence> text = event.getText();
4017 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004018 // Populate event with a fake title based on the current state.
4019 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004020 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004021 } else {
4022 text.add(getString(R.string.all_apps_home_button_label));
4023 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004024 return result;
4025 }
4026
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004027 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004028 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004029 */
4030 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4031 @Override
4032 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004033 closeSystemDialogs();
4034 }
4035 }
4036
4037 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004038 * Receives notifications whenever the appwidgets are reset.
4039 */
4040 private class AppWidgetResetObserver extends ContentObserver {
4041 public AppWidgetResetObserver() {
4042 super(new Handler());
4043 }
4044
4045 @Override
4046 public void onChange(boolean selfChange) {
4047 onAppWidgetReset();
4048 }
4049 }
4050
4051 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004052 * If the activity is currently paused, signal that we need to run the passed Runnable
4053 * in onResume.
4054 *
4055 * This needs to be called from incoming places where resources might have been loaded
4056 * while we are paused. That is becaues the Configuration might be wrong
4057 * when we're not running, and if it comes back to what it was when we
4058 * were paused, we are not restarted.
4059 *
4060 * Implementation of the method from LauncherModel.Callbacks.
4061 *
4062 * @return true if we are currently paused. The caller might be able to
4063 * skip some work in that case since we will come back again.
4064 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004065 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004066 if (mPaused) {
4067 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004068 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004069 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004070 }
4071 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004072 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004073 return true;
4074 } else {
4075 return false;
4076 }
4077 }
4078
Michael Jurkac402cd92013-05-20 15:49:32 +02004079 private boolean waitUntilResume(Runnable run) {
4080 return waitUntilResume(run, false);
4081 }
4082
Michael Jurka1e2f4652013-07-08 18:03:46 -07004083 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004084 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004085 }
4086
Michael Jurka7607c2f2013-04-03 14:33:19 -07004087 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004088 * If the activity is currently paused, signal that we need to re-run the loader
4089 * in onResume.
4090 *
4091 * This needs to be called from incoming places where resources might have been loaded
4092 * while we are paused. That is becaues the Configuration might be wrong
4093 * when we're not running, and if it comes back to what it was when we
4094 * were paused, we are not restarted.
4095 *
4096 * Implementation of the method from LauncherModel.Callbacks.
4097 *
4098 * @return true if we are currently paused. The caller might be able to
4099 * skip some work in that case since we will come back again.
4100 */
4101 public boolean setLoadOnResume() {
4102 if (mPaused) {
4103 Log.i(TAG, "setLoadOnResume");
4104 mOnResumeNeedsLoad = true;
4105 return true;
4106 } else {
4107 return false;
4108 }
4109 }
4110
4111 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004112 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004113 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004114 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004115 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004116 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004117 } else {
4118 return SCREEN_COUNT / 2;
4119 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004120 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004121
Joe Onorato9c1289c2009-08-17 11:03:03 -04004122 /**
4123 * Refreshes the shortcuts shown on the workspace.
4124 *
4125 * Implementation of the method from LauncherModel.Callbacks.
4126 */
4127 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004128 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004129
Michael Jurka7607c2f2013-04-03 14:33:19 -07004130 // If we're starting binding all over again, clear any bind calls we'd postponed in
4131 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4132 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004133 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004134
Winson Chungd64d1762013-08-20 14:37:16 -07004135 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004136 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004137 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004138
Michael Jurka05bf644e2011-11-30 20:28:53 -08004139 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004140 if (mHotseat != null) {
4141 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004142 }
4143 }
4144
Adam Cohendcd297f2013-06-18 13:13:40 -07004145 @Override
4146 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004147 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004148
Adam Cohen5084cba2013-09-03 12:01:16 -07004149 // If there are no screens, we need to have an empty screen
4150 if (orderedScreenIds.size() == 0) {
4151 mWorkspace.addExtraEmptyScreen();
4152 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004153
4154 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004155 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004156 if (hasCustomContentToLeft()) {
4157 mWorkspace.createCustomContentContainer();
4158 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004159 }
Winson Chung64359a52013-07-08 17:17:08 -07004160 }
4161
4162 @Override
4163 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004164 // Log to disk
4165 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4166 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4167 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004168 int count = orderedScreenIds.size();
4169 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004170 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004171 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004172 }
4173
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08004174 @Override
4175 public void bindAddPendingItem(final PendingAddItemInfo info, final long container,
4176 final long screenId, final int[] cell, final int spanX, final int spanY) {
4177 showWorkspace(true, new Runnable() {
4178
4179 @Override
4180 public void run() {
4181 mWorkspace.snapToPage(mWorkspace.getPageIndexForScreenId(screenId));
4182 addPendingItem(info, container, screenId, cell, spanX, spanY);
4183 }
4184 });
4185 }
4186
Adam Cohen39a06042013-07-19 14:30:12 -07004187 private boolean shouldShowWeightWatcher() {
4188 String spKey = LauncherAppState.getSharedPreferencesKey();
4189 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07004190 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004191
4192 return show;
4193 }
4194
4195 private void toggleShowWeightWatcher() {
4196 String spKey = LauncherAppState.getSharedPreferencesKey();
4197 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4198 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4199
4200 show = !show;
4201
4202 SharedPreferences.Editor editor = sp.edit();
4203 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4204 editor.commit();
4205
4206 if (mWeightWatcher != null) {
4207 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4208 }
4209 }
4210
Winson Chungd64d1762013-08-20 14:37:16 -07004211 public void bindAppsAdded(final ArrayList<Long> newScreens,
4212 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004213 final ArrayList<ItemInfo> addAnimated,
4214 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004215 Runnable r = new Runnable() {
4216 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004217 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004218 }
4219 };
4220 if (waitUntilResume(r)) {
4221 return;
4222 }
4223
Winson Chungd64d1762013-08-20 14:37:16 -07004224 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004225 if (newScreens != null) {
4226 bindAddScreens(newScreens);
4227 }
Winson Chungd64d1762013-08-20 14:37:16 -07004228
4229 // We add the items without animation on non-visible pages, and with
4230 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004231 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004232 bindItems(addNotAnimated, 0,
4233 addNotAnimated.size(), false);
4234 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004235 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004236 bindItems(addAnimated, 0,
4237 addAnimated.size(), true);
4238 }
Winson Chungc58497e2013-09-03 17:48:37 -07004239
Winson Chung87412982013-10-03 18:34:14 -07004240 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004241 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004242
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004243 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004244 addedApps != null && mAppsCustomizeContent != null) {
4245 mAppsCustomizeContent.addApps(addedApps);
4246 }
Winson Chungd64d1762013-08-20 14:37:16 -07004247 }
4248
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004249 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004250 * Bind the items start-end from the list.
4251 *
4252 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004253 */
Winson Chung64359a52013-07-08 17:17:08 -07004254 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4255 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004256 Runnable r = new Runnable() {
4257 public void run() {
4258 bindItems(shortcuts, start, end, forceAnimateIcons);
4259 }
4260 };
4261 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004262 return;
4263 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004264
Winson Chungf0c6ae02012-03-21 16:10:31 -07004265 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004266 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4267 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004268 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004269 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004270 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004271 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004272 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004273
4274 // Short circuit if we are loading dock items for a configuration which has no dock
4275 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4276 mHotseat == null) {
4277 continue;
4278 }
4279
Joe Onorato9c1289c2009-08-17 11:03:03 -04004280 switch (item.itemType) {
4281 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4282 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004283 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004284 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004285
Winson Chung64359a52013-07-08 17:17:08 -07004286 /*
4287 * TODO: FIX collision case
4288 */
Winson Chungce376632013-07-11 16:12:41 -07004289 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4290 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4291 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004292 View v = cl.getChildAt(item.cellX, item.cellY);
4293 Object tag = v.getTag();
4294 String desc = "Collision while binding workspace item: " + item
4295 + ". Collides with " + tag;
4296 if (LauncherAppState.isDogfoodBuild()) {
4297 throw (new RuntimeException(desc));
4298 } else {
4299 Log.d(TAG, desc);
4300 }
Winson Chungce376632013-07-11 16:12:41 -07004301 }
Winson Chung64359a52013-07-08 17:17:08 -07004302 }
4303
Adam Cohendcd297f2013-06-18 13:13:40 -07004304 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4305 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004306 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004307 // Animate all the applications up now
4308 shortcut.setAlpha(0f);
4309 shortcut.setScaleX(0f);
4310 shortcut.setScaleY(0f);
4311 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004312 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004313 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004314 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004315 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004316 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004317 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004318 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004319 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4320 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004321 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004322 default:
4323 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004324 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004325 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004326
Winson Chung997a9232013-07-24 15:33:46 -07004327 if (animateIcons) {
4328 // Animate to the correct page
4329 if (newShortcutsScreenId > -1) {
4330 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004331 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004332 final Runnable startBounceAnimRunnable = new Runnable() {
4333 public void run() {
4334 anim.playTogether(bounceAnims);
4335 anim.start();
4336 }
4337 };
Winson Chung997a9232013-07-24 15:33:46 -07004338 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004339 // We post the animation slightly delayed to prevent slowdowns
4340 // when we are loading right after we return to launcher.
4341 mWorkspace.postDelayed(new Runnable() {
4342 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004343 if (mWorkspace != null) {
4344 mWorkspace.snapToPage(newScreenIndex);
4345 mWorkspace.postDelayed(startBounceAnimRunnable,
4346 NEW_APPS_ANIMATION_DELAY);
4347 }
Winson Chung94d67682013-09-25 16:29:40 -07004348 }
4349 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004350 } else {
4351 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004352 }
4353 }
Winson Chung64359a52013-07-08 17:17:08 -07004354 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004355 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004356 }
4357
Joe Onorato9c1289c2009-08-17 11:03:03 -04004358 /**
4359 * Implementation of the method from LauncherModel.Callbacks.
4360 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004361 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004362 Runnable r = new Runnable() {
4363 public void run() {
4364 bindFolders(folders);
4365 }
4366 };
4367 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004368 return;
4369 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004370 sFolders.clear();
4371 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004372 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004373
4374 /**
4375 * Add the views for a widget to the workspace.
4376 *
4377 * Implementation of the method from LauncherModel.Callbacks.
4378 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004379 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004380 Runnable r = new Runnable() {
4381 public void run() {
4382 bindAppWidget(item);
4383 }
4384 };
4385 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004386 return;
4387 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004388
Daniel Sandler843e8602010-06-07 14:59:01 -04004389 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4390 if (DEBUG_WIDGETS) {
4391 Log.d(TAG, "bindAppWidget: " + item);
4392 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004393 final Workspace workspace = mWorkspace;
4394
Adam Cohen59400422014-03-05 18:07:04 -08004395 LauncherAppWidgetProviderInfo appWidgetInfo =
Robin Lee2dd9f012015-03-16 19:41:43 +00004396 LauncherModel.getProviderInfo(this, item.providerName, item.user);
Adam Cohen59400422014-03-05 18:07:04 -08004397
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004398 if (!mIsSafeModeEnabled
4399 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
4400 && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
Sunny Goyalff572272014-07-23 13:58:07 -07004401 if (appWidgetInfo == null) {
4402 if (DEBUG_WIDGETS) {
4403 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4404 + " belongs to component " + item.providerName
4405 + ", as the povider is null");
4406 }
4407 LauncherModel.deleteItemFromDatabase(this, item);
4408 return;
4409 }
4410 // Note: This assumes that the id remap broadcast is received before this step.
4411 // If that is not the case, the id remap will be ignored and user may see the
4412 // click to setup view.
Adam Cohen59400422014-03-05 18:07:04 -08004413 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null);
Sunny Goyalff572272014-07-23 13:58:07 -07004414 pendingInfo.spanX = item.spanX;
4415 pendingInfo.spanY = item.spanY;
4416 pendingInfo.minSpanX = item.minSpanX;
4417 pendingInfo.minSpanY = item.minSpanY;
4418 Bundle options =
4419 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4420
Sunny Goyalff572272014-07-23 13:58:07 -07004421 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004422 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4423 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004424
4425 // TODO consider showing a permission dialog when the widget is clicked.
4426 if (!success) {
4427 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4428 if (DEBUG_WIDGETS) {
4429 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4430 + " belongs to component " + item.providerName
4431 + ", as the launcher is unable to bing a new widget id");
4432 }
4433 LauncherModel.deleteItemFromDatabase(this, item);
4434 return;
4435 }
4436
4437 item.appWidgetId = newWidgetId;
4438
4439 // If the widget has a configure activity, it is still needs to set it up, otherwise
4440 // the widget is ready to go.
4441 item.restoreStatus = (appWidgetInfo.configure == null)
4442 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4443 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4444
4445 LauncherModel.updateItemInDatabase(this, item);
4446 }
4447
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004448 if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004449 final int appWidgetId = item.appWidgetId;
Sunny Goyal651077b2014-06-30 14:15:31 -07004450 if (DEBUG_WIDGETS) {
Adam Cohen59400422014-03-05 18:07:04 -08004451 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component "
4452 + appWidgetInfo.provider);
Sunny Goyal651077b2014-06-30 14:15:31 -07004453 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004454
Sunny Goyal651077b2014-06-30 14:15:31 -07004455 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4456 } else {
4457 appWidgetInfo = null;
Sunny Goyal9b4b0812014-10-08 10:47:28 -07004458 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
4459 mIsSafeModeEnabled);
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004460 view.updateIcon(mIconCache);
4461 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004462 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004463 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004464 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004465
Joe Onorato9c1289c2009-08-17 11:03:03 -04004466 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004467 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004468
Adam Cohendcd297f2013-06-18 13:13:40 -07004469 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004470 item.cellY, item.spanX, item.spanY, false);
Adam Cohen59400422014-03-05 18:07:04 -08004471 if (!item.isCustomWidget()) {
4472 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4473 }
Adam Cohended9f8d2010-11-03 13:25:16 -07004474
Joe Onorato9c1289c2009-08-17 11:03:03 -04004475 workspace.requestLayout();
4476
Daniel Sandler843e8602010-06-07 14:59:01 -04004477 if (DEBUG_WIDGETS) {
4478 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4479 + (SystemClock.uptimeMillis()-start) + "ms");
4480 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004481 }
4482
Sunny Goyalff572272014-07-23 13:58:07 -07004483 /**
4484 * Restores a pending widget.
4485 *
4486 * @param appWidgetId The app widget id
4487 * @param cellInfo The position on screen where to create the widget.
4488 */
4489 private void completeRestoreAppWidget(final int appWidgetId) {
4490 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4491 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4492 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4493 return;
4494 }
4495
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004496 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004497 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4498
4499 mWorkspace.reinflateWidgetsIfNecessary();
4500 LauncherModel.updateItemInDatabase(this, info);
4501 }
4502
Adam Cohen1462de32012-07-24 22:34:36 -07004503 public void onPageBoundSynchronously(int page) {
4504 mSynchronouslyBoundPages.add(page);
4505 }
4506
Joe Onorato9c1289c2009-08-17 11:03:03 -04004507 /**
4508 * Callback saying that there aren't any more items to bind.
4509 *
4510 * Implementation of the method from LauncherModel.Callbacks.
4511 */
Adam Cohene25af792013-06-06 23:08:25 -07004512 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004513 Runnable r = new Runnable() {
4514 public void run() {
4515 finishBindingItems(upgradePath);
4516 }
4517 };
4518 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004519 return;
4520 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004521 if (mSavedState != null) {
4522 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004523 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004524 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004525 mSavedState = null;
4526 }
4527
Adam Cohen1462de32012-07-24 22:34:36 -07004528 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004529
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004530 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004531 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004532
4533 // If we received the result of any pending adds while the loader was running (e.g. the
4534 // widget configuration forced an orientation change), process them now.
4535 if (sPendingAddItem != null) {
4536 final long screenId = completeAdd(sPendingAddItem);
4537
4538 // TODO: this moves the user to the page where the pending item was added. Ideally,
4539 // the screen would be guaranteed to exist after bind, and the page would be set through
4540 // the workspace restore process.
4541 mWorkspace.post(new Runnable() {
4542 @Override
4543 public void run() {
4544 mWorkspace.snapToScreenId(screenId);
4545 }
4546 });
4547 sPendingAddItem = null;
4548 }
4549
Adam Cohene25af792013-06-06 23:08:25 -07004550 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004551 mWorkspace.getUniqueComponents(true, null);
4552 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004553 }
Sunny Goyale755d462014-07-22 13:48:29 -07004554 PackageInstallerCompat.getInstance(this).onFinishBind();
Adam Cohen9211d422014-10-07 18:14:53 -07004555
4556 if (mLauncherCallbacks != null) {
4557 mLauncherCallbacks.finishBindingItems(upgradePath);
4558 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004559 }
4560
Adam Cohen3ed316a2014-07-23 18:21:20 -07004561 private void sendLoadingCompleteBroadcastIfNecessary() {
4562 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4563 String permission =
4564 getResources().getString(R.string.receive_first_load_broadcast_permission);
4565 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4566 sendBroadcast(intent, permission);
4567 SharedPreferences.Editor editor = mSharedPrefs.edit();
4568 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4569 editor.apply();
4570 }
4571 }
4572
Winson Chunga0b7e862013-09-05 16:03:15 -07004573 public boolean isAllAppsButtonRank(int rank) {
4574 if (mHotseat != null) {
4575 return mHotseat.isAllAppsButtonRank(rank);
4576 }
4577 return false;
4578 }
4579
Winson Chunga2413752012-04-03 14:22:34 -07004580 private boolean canRunNewAppsAnimation() {
4581 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4582 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4583 }
4584
Winson Chungc9168342013-06-26 14:54:55 -07004585 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4586 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4587 PropertyValuesHolder.ofFloat("alpha", 1f),
4588 PropertyValuesHolder.ofFloat("scaleX", 1f),
4589 PropertyValuesHolder.ofFloat("scaleY", 1f));
4590 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4591 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4592 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4593 return bounceAnim;
4594 }
4595
Adam Cohen27772732013-11-11 14:00:56 +00004596 public boolean useVerticalBarLayout() {
4597 return LauncherAppState.getInstance().getDynamicGrid().
4598 getDeviceProfile().isVerticalBarLayout();
4599 }
4600
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004601 protected Rect getSearchBarBounds() {
4602 return LauncherAppState.getInstance().getDynamicGrid().
4603 getDeviceProfile().getSearchBarBounds();
4604 }
4605
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004606 public void bindSearchablesChanged() {
Sunny Goyal594d76d2014-11-06 10:12:54 -08004607 if (mSearchDropTargetBar == null) {
4608 return;
Winson Chungadf0c182012-08-23 14:59:07 -07004609 }
Sunny Goyal594d76d2014-11-06 10:12:54 -08004610 if (mQsb != null) {
4611 mSearchDropTargetBar.removeView(mQsb);
4612 mQsb = null;
4613 }
4614 mSearchDropTargetBar.setQsbSearchBar(getQsbBar());
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004615 }
4616
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004617 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004618 * Add the icons for all apps.
4619 *
4620 * Implementation of the method from LauncherModel.Callbacks.
4621 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004622 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004623 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004624 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4625 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4626 getHotseat().addAllAppsFolder(mIconCache, apps,
4627 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4628 }
4629 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004630 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004631 if (mAppsCustomizeContent != null) {
4632 mAppsCustomizeContent.onPackagesUpdated(
Hyunyoung Songfe1dcbf2015-03-11 16:36:52 -07004633 LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */));
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004634 }
Winson Chungc58497e2013-09-03 17:48:37 -07004635 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004636 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004637 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004638 mAppsCustomizeContent.onPackagesUpdated(
Hyunyoung Songfe1dcbf2015-03-11 16:36:52 -07004639 LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */));
Winson Chungc58497e2013-09-03 17:48:37 -07004640 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004641 }
Adam Cohen9211d422014-10-07 18:14:53 -07004642 if (mLauncherCallbacks != null) {
4643 mLauncherCallbacks.bindAllApplications(apps);
4644 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004645 }
4646
4647 /**
4648 * A package was updated.
4649 *
4650 * Implementation of the method from LauncherModel.Callbacks.
4651 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004652 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004653 Runnable r = new Runnable() {
4654 public void run() {
4655 bindAppsUpdated(apps);
4656 }
4657 };
4658 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004659 return;
4660 }
4661
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004662 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004663 mAppsCustomizeContent != null) {
4664 mAppsCustomizeContent.updateApps(apps);
4665 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004666 }
4667
Sunny Goyal4390ace2014-10-13 11:33:11 -07004668 @Override
4669 public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
4670 Runnable r = new Runnable() {
4671 public void run() {
4672 bindWidgetsRestored(widgets);
4673 }
4674 };
4675 if (waitUntilResume(r)) {
4676 return;
4677 }
4678 mWorkspace.widgetsRestored(widgets);
4679 }
4680
Joe Onorato9c1289c2009-08-17 11:03:03 -04004681 /**
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004682 * Some shortcuts were updated in the background.
4683 *
4684 * Implementation of the method from LauncherModel.Callbacks.
4685 */
Sunny Goyal4390ace2014-10-13 11:33:11 -07004686 @Override
4687 public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
4688 final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004689 Runnable r = new Runnable() {
4690 public void run() {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004691 bindShortcutsChanged(updated, removed, user);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004692 }
4693 };
4694 if (waitUntilResume(r)) {
4695 return;
4696 }
4697
Sunny Goyal4390ace2014-10-13 11:33:11 -07004698 if (!updated.isEmpty()) {
4699 mWorkspace.updateShortcuts(updated);
4700 }
4701
4702 if (!removed.isEmpty()) {
4703 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4704 for (ShortcutInfo si : removed) {
4705 removedComponents.add(si.getTargetComponent());
4706 }
4707 mWorkspace.removeItemsByComponentName(removedComponents, user);
4708 // Notify the drag controller
4709 mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
Sunny Goyalb50cc8c2014-10-06 16:23:56 -07004710 }
4711 }
4712
4713 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004714 * Update the state of a package, typically related to install state.
4715 *
4716 * Implementation of the method from LauncherModel.Callbacks.
4717 */
Sunny Goyale755d462014-07-22 13:48:29 -07004718 @Override
4719 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004720 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004721 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004722 }
4723 }
4724
4725 /**
Sunny Goyala22666f2014-09-18 13:25:15 -07004726 * Update the label and icon of all the icons in a package
4727 *
4728 * Implementation of the method from LauncherModel.Callbacks.
4729 */
4730 @Override
4731 public void updatePackageBadge(String packageName) {
4732 if (mWorkspace != null) {
4733 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4734 }
4735 }
4736
4737 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004738 * A package was uninstalled. We take both the super set of packageNames
4739 * in addition to specific applications to remove, the reason being that
4740 * this can be called when a package is updated as well. In that scenario,
4741 * we only remove specific components from the workspace, where as
4742 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004743 *
Sunny Goyal1a745e82014-10-02 15:58:31 -07004744 * @param reason if non-zero, the icons are not permanently removed, rather marked as disabled.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004745 * Implementation of the method from LauncherModel.Callbacks.
4746 */
Sunny Goyal1a745e82014-10-02 15:58:31 -07004747 @Override
Winson Chung83892cc2013-05-01 16:53:33 -07004748 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Sunny Goyal1a745e82014-10-02 15:58:31 -07004749 final ArrayList<AppInfo> appInfos, final UserHandleCompat user, final int reason) {
Winson Chungd64d1762013-08-20 14:37:16 -07004750 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004751 public void run() {
Sunny Goyal1a745e82014-10-02 15:58:31 -07004752 bindComponentsRemoved(packageNames, appInfos, user, reason);
Winson Chung83892cc2013-05-01 16:53:33 -07004753 }
Winson Chungd64d1762013-08-20 14:37:16 -07004754 };
4755 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004756 return;
4757 }
4758
Sunny Goyal1a745e82014-10-02 15:58:31 -07004759 if (reason == 0) {
Sunny Goyal4390ace2014-10-13 11:33:11 -07004760 HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
4761 for (AppInfo info : appInfos) {
4762 removedComponents.add(info.componentName);
4763 }
Sunny Goyal1a745e82014-10-02 15:58:31 -07004764 if (!packageNames.isEmpty()) {
4765 mWorkspace.removeItemsByPackageName(packageNames, user);
4766 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004767 if (!removedComponents.isEmpty()) {
4768 mWorkspace.removeItemsByComponentName(removedComponents, user);
Sunny Goyal1a745e82014-10-02 15:58:31 -07004769 }
Sunny Goyal4390ace2014-10-13 11:33:11 -07004770 // Notify the drag controller
4771 mDragController.onAppsRemoved(packageNames, removedComponents);
4772
Sunny Goyal1a745e82014-10-02 15:58:31 -07004773 } else {
4774 mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
Joe Onorato36115782010-06-17 13:28:48 -04004775 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004776
Winson Chungdf95eb12013-10-16 14:57:07 -07004777 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004778 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004779 mAppsCustomizeContent != null) {
4780 mAppsCustomizeContent.removeApps(appInfos);
4781 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004782 }
Joe Onoratobe386092009-11-17 17:32:16 -08004783
4784 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004785 * A number of packages were updated.
4786 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004787 private ArrayList<Object> mWidgetsAndShortcuts;
4788 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004789 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004790 bindPackagesUpdated(mWidgetsAndShortcuts);
4791 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004792 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004793 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004794 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4795 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4796 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004797 return;
4798 }
4799
Winson Chung64359a52013-07-08 17:17:08 -07004800 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004801 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004802 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004803 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004804 }
4805
Winson Chung400438b2011-01-16 17:53:48 -08004806 private int mapConfigurationOriActivityInfoOri(int configOri) {
4807 final Display d = getWindowManager().getDefaultDisplay();
4808 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4809 switch (d.getRotation()) {
4810 case Surface.ROTATION_0:
4811 case Surface.ROTATION_180:
4812 // We are currently in the same basic orientation as the natural orientation
4813 naturalOri = configOri;
4814 break;
4815 case Surface.ROTATION_90:
4816 case Surface.ROTATION_270:
4817 // We are currently in the other basic orientation to the natural orientation
4818 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4819 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4820 break;
4821 }
4822
4823 int[] oriMap = {
4824 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4825 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4826 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4827 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4828 };
4829 // Since the map starts at portrait, we need to offset if this device's natural orientation
4830 // is landscape.
4831 int indexOffset = 0;
4832 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4833 indexOffset = 1;
4834 }
4835 return oriMap[(d.getRotation() + indexOffset) % 4];
4836 }
Adam Cohen446e9402011-09-15 18:21:21 -07004837
Winson Chung4b919f82012-05-01 10:44:08 -07004838 public void lockScreenOrientation() {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004839 if (Utilities.isRotationEnabled(this)) {
Sunny Goyal7470c812015-02-10 14:28:44 -08004840 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
4841 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4842 .getConfiguration().orientation));
4843 } else {
4844 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
4845 }
Winson Chung4b919f82012-05-01 10:44:08 -07004846 }
4847 }
4848 public void unlockScreenOrientation(boolean immediate) {
Sunny Goyal4bbf4192014-11-11 12:23:59 -08004849 if (Utilities.isRotationEnabled(this)) {
Winson Chung4b919f82012-05-01 10:44:08 -07004850 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004851 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004852 } else {
4853 mHandler.postDelayed(new Runnable() {
4854 public void run() {
4855 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4856 }
4857 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004858 }
Winson Chung4b919f82012-05-01 10:44:08 -07004859 }
Winson Chung400438b2011-01-16 17:53:48 -08004860 }
4861
Winson Chunge43a1e72014-01-15 10:33:02 -08004862 protected boolean isLauncherPreinstalled() {
Adam Cohen9211d422014-10-07 18:14:53 -07004863 if (mLauncherCallbacks != null) {
4864 return mLauncherCallbacks.isLauncherPreinstalled();
4865 }
Winson Chunge43a1e72014-01-15 10:33:02 -08004866 PackageManager pm = getPackageManager();
4867 try {
4868 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4869 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4870 return true;
4871 } else {
4872 return false;
4873 }
4874 } catch (NameNotFoundException e) {
4875 e.printStackTrace();
4876 return false;
4877 }
4878 }
4879
Adam Cohenea90f832014-05-21 15:03:34 -07004880 /**
4881 * This method indicates whether or not we should suggest default wallpaper dimensions
4882 * when our wallpaper cropper was not yet used to set a wallpaper.
4883 */
4884 protected boolean overrideWallpaperDimensions() {
Adam Cohen9211d422014-10-07 18:14:53 -07004885 if (mLauncherCallbacks != null) {
4886 return mLauncherCallbacks.overrideWallpaperDimensions();
4887 }
Adam Cohenea90f832014-05-21 15:03:34 -07004888 return true;
4889 }
4890
Adam Cohen432609a2014-03-13 17:03:22 -07004891 /**
4892 * To be overridden by subclasses to indicate that there is an activity to launch
4893 * before showing the standard launcher experience.
4894 */
4895 protected boolean hasFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004896 if (mLauncherCallbacks != null) {
4897 return mLauncherCallbacks.hasFirstRunActivity();
4898 }
Adam Cohen432609a2014-03-13 17:03:22 -07004899 return false;
4900 }
4901
4902 /**
4903 * To be overridden by subclasses to launch any first run activity
4904 */
4905 protected Intent getFirstRunActivity() {
Adam Cohen9211d422014-10-07 18:14:53 -07004906 if (mLauncherCallbacks != null) {
4907 return mLauncherCallbacks.getFirstRunActivity();
4908 }
Adam Cohen432609a2014-03-13 17:03:22 -07004909 return null;
4910 }
4911
Winson Chunga6945242014-01-08 14:04:34 -08004912 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004913 return !ActivityManager.isRunningInTestHarness() &&
4914 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004915 }
4916
Adam Cohen4a9423d2014-03-28 14:22:31 -07004917 protected boolean hasRunFirstRunActivity() {
4918 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4919 }
4920
Adam Cohen432609a2014-03-13 17:03:22 -07004921 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004922 if (shouldRunFirstRunActivity() &&
4923 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004924 Intent firstRunIntent = getFirstRunActivity();
4925 if (firstRunIntent != null) {
4926 startActivity(firstRunIntent);
4927 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004928 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004929 }
4930 }
Adam Cohen432609a2014-03-13 17:03:22 -07004931 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004932 }
4933
4934 private void markFirstRunActivityShown() {
4935 SharedPreferences.Editor editor = mSharedPrefs.edit();
4936 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4937 editor.apply();
4938 }
4939
Adam Cohen432609a2014-03-13 17:03:22 -07004940 /**
4941 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4942 * screen that must be displayed and dismissed.
4943 */
4944 protected boolean hasDismissableIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004945 if (mLauncherCallbacks != null) {
4946 return mLauncherCallbacks.hasDismissableIntroScreen();
4947 }
Adam Cohen432609a2014-03-13 17:03:22 -07004948 return false;
4949 }
4950
4951 /**
4952 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4953 */
4954 protected View getIntroScreen() {
Adam Cohen9211d422014-10-07 18:14:53 -07004955 if (mLauncherCallbacks != null) {
4956 return mLauncherCallbacks.getIntroScreen();
4957 }
Adam Cohen432609a2014-03-13 17:03:22 -07004958 return null;
4959 }
4960
4961 /**
4962 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4963 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4964 */
4965 private boolean shouldShowIntroScreen() {
4966 return hasDismissableIntroScreen() &&
4967 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4968 }
4969
4970 protected void showIntroScreen() {
4971 View introScreen = getIntroScreen();
4972 changeWallpaperVisiblity(false);
4973 if (introScreen != null) {
4974 mDragLayer.showOverlayView(introScreen);
4975 }
Adam Cohenc3e12c72014-10-31 16:15:36 -07004976 if (mLauncherOverlayContainer != null) {
4977 mLauncherOverlayContainer.setVisibility(View.INVISIBLE);
4978 }
Adam Cohen432609a2014-03-13 17:03:22 -07004979 }
4980
4981 public void dismissIntroScreen() {
4982 markIntroScreenDismissed();
4983 if (showFirstRunActivity()) {
4984 // We delay hiding the intro view until the first run activity is showing. This
4985 // avoids a blip.
4986 mWorkspace.postDelayed(new Runnable() {
4987 @Override
4988 public void run() {
4989 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004990 if (mLauncherOverlayContainer != null) {
4991 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
4992 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07004993 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004994 }
4995 }, ACTIVITY_START_DELAY);
4996 } else {
4997 mDragLayer.dismissOverlayView();
Adam Cohenc3e12c72014-10-31 16:15:36 -07004998 if (mLauncherOverlayContainer != null) {
4999 mLauncherOverlayContainer.setVisibility(View.VISIBLE);
5000 }
Sunny Goyal88d60f12014-09-08 03:47:29 -07005001 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07005002 }
5003 changeWallpaperVisiblity(true);
5004 }
5005
5006 private void markIntroScreenDismissed() {
5007 SharedPreferences.Editor editor = mSharedPrefs.edit();
5008 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
5009 editor.apply();
5010 }
5011
Sunny Goyal88d60f12014-09-08 03:47:29 -07005012 private void showFirstRunClings() {
5013 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
5014 // on the device, then we always show the first run cling experience (or if there is no
5015 // launcher2). Otherwise, we prompt the user upon started for migration
5016 LauncherClings launcherClings = new LauncherClings(this);
5017 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
5018 if (mModel.canMigrateFromOldLauncherDb(this)) {
5019 launcherClings.showMigrationCling();
5020 } else {
Sunny Goyalaf0628f2014-09-19 10:14:48 -07005021 launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07005022 }
5023 }
5024 }
5025
Winson Chunga6945242014-01-08 14:04:34 -08005026 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005027 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5028 if (mHotseat != null) mHotseat.setAlpha(1f);
5029 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5030 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005031 }
5032
5033 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005034 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5035 if (mHotseat != null) mHotseat.setAlpha(0f);
5036 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5037 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005038 }
5039
Mathew Inwood72fbec12013-11-19 15:45:07 +00005040 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01005041 // Called from search suggestion, not supported in other profiles.
5042 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5043 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5044 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5045 myUser);
5046 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00005047 return null;
5048 }
Kenny Guyed131872014-04-30 03:02:21 +01005049 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005050 }
5051
5052 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5053 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01005054 // Called from search suggestion, not supported in other profiles.
5055 return createShortcutDragInfo(shortcutIntent, caption, icon,
5056 UserHandleCompat.myUserHandle());
5057 }
5058
5059 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5060 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01005061 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01005062 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01005063 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005064 }
5065
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005066 protected void moveWorkspaceToDefaultScreen() {
5067 mWorkspace.moveToDefaultScreen(false);
5068 }
5069
Mathew Inwood72fbec12013-11-19 15:45:07 +00005070 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5071 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005072 mWorkspace.onExternalDragStartedWithItem(dragView);
5073 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005074 }
5075
Anjali Koppalf5d29132014-02-28 13:33:27 -08005076 @Override
5077 public void onPageSwitch(View newPage, int newPageIndex) {
Adam Cohen9211d422014-10-07 18:14:53 -07005078 if (mLauncherCallbacks != null) {
5079 mLauncherCallbacks.onPageSwitch(newPage, newPageIndex);
5080 }
Anjali Koppalf5d29132014-02-28 13:33:27 -08005081 }
5082
Winson Chung80baf5a2010-08-09 16:03:15 -07005083 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005084 * Prints out out state for debugging.
5085 */
5086 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005087 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005088 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005089 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5090 Log.d(TAG, "mRestoring=" + mRestoring);
5091 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5092 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005093 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005094 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005095
Winson Chung785d2eb2011-04-14 16:08:02 -07005096 if (mAppsCustomizeContent != null) {
5097 mAppsCustomizeContent.dumpState();
5098 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005099 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005100 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005101
5102 @Override
5103 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5104 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005105 synchronized (sDumpLogs) {
5106 writer.println(" ");
5107 writer.println("Debug logs: ");
5108 for (int i = 0; i < sDumpLogs.size(); i++) {
5109 writer.println(" " + sDumpLogs.get(i));
5110 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005111 }
Adam Cohen9211d422014-10-07 18:14:53 -07005112 if (mLauncherCallbacks != null) {
5113 mLauncherCallbacks.dump(prefix, fd, writer, args);
5114 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005115 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005116
5117 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005118 if (DEBUG_DUMP_LOG) {
5119 synchronized (sDumpLogs) {
5120 Log.d(TAG, "");
5121 Log.d(TAG, "*********************");
5122 Log.d(TAG, "Launcher debug logs: ");
5123 for (int i = 0; i < sDumpLogs.size(); i++) {
5124 Log.d(TAG, " " + sDumpLogs.get(i));
5125 }
5126 Log.d(TAG, "*********************");
5127 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005128 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005129 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005130 }
5131
5132 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005133 addDumpLog(tag, log, null, debugLog);
5134 }
5135
5136 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005137 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005138 if (e != null) {
5139 Log.d(tag, log, e);
5140 } else {
5141 Log.d(tag, log);
5142 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005143 }
Winson Chungede41292013-09-19 16:27:36 -07005144 if (DEBUG_DUMP_LOG) {
5145 sDateStamp.setTime(System.currentTimeMillis());
5146 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005147 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5148 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005149 }
Winson Chungede41292013-09-19 16:27:36 -07005150 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005151 }
5152
Adam Cohen59400422014-03-05 18:07:04 -08005153 public static CustomAppWidget getCustomAppWidget(String name) {
5154 return sCustomAppWidgets.get(name);
5155 }
5156
5157 public static HashMap<String, CustomAppWidget> getCustomAppWidgets() {
5158 return sCustomAppWidgets;
5159 }
5160
Winson Chungede41292013-09-19 16:27:36 -07005161 public void dumpLogsToLocalData() {
5162 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005163 new AsyncTask<Void, Void, Void>() {
5164 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005165 boolean success = false;
5166 sDateStamp.setTime(sRunStart);
5167 String FILENAME = sDateStamp.getMonth() + "-"
5168 + sDateStamp.getDay() + "_"
5169 + sDateStamp.getHours() + "-"
5170 + sDateStamp.getMinutes() + "_"
5171 + sDateStamp.getSeconds() + ".txt";
5172
5173 FileOutputStream fos = null;
5174 File outFile = null;
5175 try {
5176 outFile = new File(getFilesDir(), FILENAME);
5177 outFile.createNewFile();
5178 fos = new FileOutputStream(outFile);
5179 } catch (Exception e) {
5180 e.printStackTrace();
5181 }
5182 if (fos != null) {
5183 PrintWriter writer = new PrintWriter(fos);
5184
5185 writer.println(" ");
5186 writer.println("Debug logs: ");
5187 synchronized (sDumpLogs) {
5188 for (int i = 0; i < sDumpLogs.size(); i++) {
5189 writer.println(" " + sDumpLogs.get(i));
5190 }
5191 }
5192 writer.close();
5193 }
5194 try {
5195 if (fos != null) {
5196 fos.close();
5197 success = true;
5198 }
5199 } catch (IOException e) {
5200 e.printStackTrace();
5201 }
Michael Jurka43467462013-11-14 12:03:58 +01005202 return null;
Winson Chungede41292013-09-19 16:27:36 -07005203 }
Michael Jurka43467462013-11-14 12:03:58 +01005204 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005205 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005206 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005207}
Michael Jurka2763be32011-02-24 11:19:57 -08005208
Michael Jurkaabded662011-03-04 12:06:57 -08005209interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005210 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005211 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005212 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005213 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005214 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005215}
Dan Sandlerd5024042014-01-09 15:01:33 -05005216
5217interface DebugIntents {
5218 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5219 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005220}