blob: 64f2180f84d82d5b8b4752f6c07fed8bad9e9662 [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;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080046import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070054import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070055import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040059import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070060import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020062import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070064import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070065import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040066import android.os.SystemClock;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Sunny Goyale755d462014-07-22 13:48:29 -070085import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewGroup;
87import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080088import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Sunny Goyal651077b2014-06-30 14:15:31 -070089import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070090import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080091import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070092import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080093import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070095import android.widget.Advanceable;
96import android.widget.FrameLayout;
97import android.widget.ImageView;
98import android.widget.TextView;
99import 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;
Kenny Guyed131872014-04-30 03:02:21 +0100103import com.android.launcher3.compat.LauncherActivityInfoCompat;
104import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700105import com.android.launcher3.compat.PackageInstallerCompat;
106import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100107import com.android.launcher3.compat.UserHandleCompat;
108import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700109
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.io.DataInputStream;
111import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700113import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700115import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700117import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000118import java.lang.reflect.Field;
119import java.lang.reflect.InvocationTargetException;
120import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700121import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700122import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700123import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700124import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700126import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000127import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700128
Winson Chunga6945242014-01-08 14:04:34 -0800129
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130/**
131 * Default launcher application.
132 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100133public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700134 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700135 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800136 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700137 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138
Daniel Sandlerf061f822013-06-27 13:59:36 -0400139 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400140 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700141 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700143 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700144
Dan Sandlerd5024042014-01-09 15:01:33 -0500145 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
146
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700148 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700150 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700151 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
Michael Jurka8b805b12012-04-18 14:23:14 -0700153 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700154 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700155
Mathew Inwood876a8462013-06-14 14:12:41 +0100156 /**
157 * IntentStarter uses request codes starting with this. This must be greater than all activity
158 * request codes used internally.
159 */
160 protected static final int REQUEST_LAST = 100;
161
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
163
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800164 static final int SCREEN_COUNT = 5;
165 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Romain Guy98d01652009-06-30 16:21:04 -0700167 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800168 // To turn on these properties, type
169 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
170 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
171 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800172 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Winson Chung2672ff92012-05-04 16:22:30 -0700174 // The Intent extra that defines whether to ignore the launch animation
175 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400176 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700177
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178 // Type: int
179 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700180 // Type: int
181 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700183 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
184 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
186 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700187 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700189 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 // Type: boolean
191 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
192 // Type: long
193 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700194 // Type: int
195 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
196 // Type: int
197 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
198 // Type: parcelable
199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000200 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800201 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000202 // Type: int[]
203 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
Adam Cohen432609a2014-03-13 17:03:22 -0700205 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800206 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
207
Adam Cohen3ed316a2014-07-23 18:21:20 -0700208 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
209 static final String ACTION_FIRST_LOAD_COMPLETE =
210 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
211
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100212 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700213 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100214 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700215 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100216 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700217
Adam Cohen39a06042013-07-19 14:30:12 -0700218 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700219 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700220
Winson Chunga6945242014-01-08 14:04:34 -0800221 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
222
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700223 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700224 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700225 private State mState = State.WORKSPACE;
226 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700227
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700228 private boolean mIsSafeModeEnabled;
229
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700231 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
232 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700233 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800236 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000238 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
239 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
240
Winson Chunga2413752012-04-03 14:22:34 -0700241 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700242 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
243 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700244 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700245 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700246
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800247 private final BroadcastReceiver mCloseSystemDialogsReceiver
248 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800249 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
250
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 private LayoutInflater mInflater;
252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700254 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800255 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800256 private DragLayer mDragLayer;
257 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700258 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800259 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700261 private AppWidgetManager mAppWidgetManager;
262 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700263
Michael Jurkac9d95c52011-08-29 14:03:34 -0700264 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700265 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800266 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700267
Michael Jurka0280c3b2010-09-17 15:00:07 -0700268 private int[] mTmpAddItemCellCoordinates = new int[2];
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private FolderInfo mFolderInfo;
271
Winson Chung3d503fb2011-07-13 17:25:49 -0700272 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800273 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700274
Michael Jurka838a4ca2011-02-07 13:33:06 -0800275 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700276
Winson Chungc51db6a2011-10-05 11:44:49 -0700277 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700278 private AppsCustomizeTabHost mAppsCustomizeTabHost;
279 private AppsCustomizePagedView mAppsCustomizeContent;
280 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800281 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700284 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
285 // scroll issues (because the workspace may not have been measured yet) and extra work.
286 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
287 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288
289 private SpannableStringBuilder mDefaultKeySsb = null;
290
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291 private boolean mWorkspaceLoading = true;
292
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800293 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 private boolean mRestoring;
295 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700296 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297
Michael Jurka1e2f4652013-07-08 18:03:46 -0700298 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700299 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
300
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800301 private Bundle mSavedInstanceState;
302
Joe Onorato9c1289c2009-08-17 11:03:03 -0400303 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800304 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800305 private boolean mUserPresent = true;
306 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700307 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800308 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400309
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700310 private static LocaleConfiguration sLocaleConfiguration = null;
311
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700312 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700313
Adam Cohen61f560d2013-09-30 15:58:20 -0700314 private View.OnTouchListener mHapticFeedbackTouchListener;
315
Adam Cohended9f8d2010-11-03 13:25:16 -0700316 // Related to the auto-advancing of widgets
317 private final int ADVANCE_MSG = 1;
318 private final int mAdvanceInterval = 20000;
319 private final int mAdvanceStagger = 250;
320 private long mAutoAdvanceSentTime;
321 private long mAutoAdvanceTimeLeft = -1;
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
Michael Jurka4ef207b2010-11-29 17:05:45 -0800329 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700330 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
331 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
Winson Chungd64a6662013-09-30 11:06:59 -0700332
Craig Mautner360310b2012-10-26 15:13:08 -0700333 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700334
Adam Cohen1462de32012-07-24 22:34:36 -0700335 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700336 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700337
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700338 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700339 static Date sDateStamp = new Date();
340 static DateFormat sDateFormat =
341 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
342 static long sRunStart = System.currentTimeMillis();
343 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700344
Winson Chung46353de2012-02-16 14:05:10 -0800345 // We only want to get the SharedPreferences once since it does an FS stat each time we get
346 // it from the context.
347 private SharedPreferences mSharedPrefs;
348
Adam Cohene25af792013-06-06 23:08:25 -0700349 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
350
Winson Chungf0c6ae02012-03-21 16:10:31 -0700351 // Holds the page that we need to animate to, and the icon views that we need to animate up
352 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700353 private ImageView mFolderIconImageView;
354 private Bitmap mFolderIconBitmap;
355 private Canvas mFolderIconCanvas;
356 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700357
Michael Jurkaddd62e92011-02-16 17:49:14 -0800358 private BubbleTextView mWaitingForResume;
359
Michael Jurkac1f5d262011-09-30 19:32:27 -0700360 private Runnable mBuildLayersRunnable = new Runnable() {
361 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700362 if (mWorkspace != null) {
363 mWorkspace.buildPageHardwareLayers();
364 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700365 }
366 };
367
Adam Cohendb364c32014-05-20 14:23:40 -0700368 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800369
Michael Jurka7267fa52013-09-26 15:29:57 -0700370 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800371
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800372 private static class PendingAddArguments {
373 int requestCode;
374 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700375 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700376 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800377 int cellX;
378 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700379 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800380 }
381
Daniel Sandlerff02d492013-08-05 02:12:05 -0400382 private Stats mStats;
383
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800384 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800385 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700386 }
387
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 @Override
389 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700390 if (DEBUG_STRICT_MODE) {
391 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
392 .detectDiskReads()
393 .detectDiskWrites()
394 .detectNetwork() // or .detectAll() for all detectable problems
395 .penaltyLog()
396 .build());
397 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
398 .detectLeakedSqlLiteObjects()
399 .detectLeakedClosableObjects()
400 .penaltyLog()
401 .penaltyDeath()
402 .build());
403 }
404
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400406
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400407 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400408 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700409 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700410 // Determine the dynamic grid properties
411 Point smallestSize = new Point();
412 Point largestSize = new Point();
413 Point realSize = new Point();
414 Display display = getWindowManager().getDefaultDisplay();
415 display.getCurrentSizeRange(smallestSize, largestSize);
416 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700417 DisplayMetrics dm = new DisplayMetrics();
418 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700419
Winson Chung5f8afe62013-08-12 16:19:28 -0700420 // Lazy-initialize the dynamic grid
421 DeviceProfile grid = app.initDynamicGrid(this,
422 Math.min(smallestSize.x, smallestSize.y),
423 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700424 realSize.x, realSize.y,
425 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700426
427 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400428 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700429 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700430 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800431 mModel = app.setLauncher(this);
432 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700433 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400434 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800435 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700437
Daniel Sandlerff02d492013-08-05 02:12:05 -0400438 mStats = new Stats(this);
439
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700440 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700441
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700442 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
443 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700444
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700445 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
446 // this also ensures that any synchronous binding below doesn't re-trigger another
447 // LauncherModel load.
448 mPaused = false;
449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200451 android.os.Debug.startMethodTracing(
452 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453 }
454
455 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700457
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100459 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800461 registerContentObservers();
462
Joe Onorato7c312c12009-08-13 21:36:53 -0700463 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 mSavedState = savedInstanceState;
466 restoreState(mSavedState);
467
468 if (PROFILE_STARTUP) {
469 android.os.Debug.stopMethodTracing();
470 }
471
472 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700473 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700474 // If the user leaves launcher, then we should just load items asynchronously when
475 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500476 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700477 } else {
478 // We only load the page synchronously if the user rotates (or triggers a
479 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800480 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700481 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800482 }
483
484 // For handling default keys
485 mDefaultKeySsb = new SpannableStringBuilder();
486 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800487
488 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
489 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800490
Adam Cohenf9426d52012-06-04 17:26:21 -0700491 updateGlobalIcons();
492
493 // On large interfaces, we want the screen to auto-rotate based on the current orientation
494 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700495
Adam Cohen432609a2014-03-13 17:03:22 -0700496 if (shouldShowIntroScreen()) {
497 showIntroScreen();
498 } else {
499 showFirstRunActivity();
500 }
501
Winson Chunge43a1e72014-01-15 10:33:02 -0800502 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
503 // on the device, then we always show the first run cling experience (or if there is no
504 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800505 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
506 if (mModel.canMigrateFromOldLauncherDb(this)) {
507 mLauncherClings.showMigrationCling();
508 } else {
509 mLauncherClings.showFirstRunCling();
510 }
Winson Chunga6945242014-01-08 14:04:34 -0800511 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800512 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800513 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700514 }
515
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700516 @Override
517 public void onLauncherProviderChange() { }
518
Winson Chung98ca0f72013-07-29 12:58:51 -0700519 /** To be overriden by subclasses to hint to Launcher that we have custom content */
520 protected boolean hasCustomContentToLeft() {
521 return false;
522 }
523
Dave Hawkeya8881582013-09-17 15:55:33 -0600524 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500525 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600526 * {@link #addToCustomContentPage}. This will only be invoked if
527 * {@link #hasCustomContentToLeft()} is {@code true}.
528 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500529 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600530 }
531
532 /**
533 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
534 * ensure the custom content page is added or removed if necessary.
535 */
536 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600537 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600538 // Not bound yet, wait for bindScreens to be called.
539 return;
540 }
541
542 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
543 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500544 mWorkspace.createCustomContentContainer();
545 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600546 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
547 mWorkspace.removeCustomContentPage();
548 }
549 }
550
Adam Cohenf9426d52012-06-04 17:26:21 -0700551 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700552 boolean searchVisible = false;
553 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800554 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700555 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700556 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700557 searchVisible = updateGlobalSearchIcon();
558 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700559 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700560 if (sGlobalSearchIcon[coi] != null) {
561 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700562 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700563 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700564 if (sVoiceSearchIcon[coi] != null) {
565 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700566 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700567 }
Winson Chungadf0c182012-08-23 14:59:07 -0700568 if (mSearchDropTargetBar != null) {
569 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
570 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 }
Romain Guycbb89e42009-06-08 15:52:54 -0700572
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574 if (sLocaleConfiguration == null) {
575 new AsyncTask<Void, Void, LocaleConfiguration>() {
576 @Override
577 protected LocaleConfiguration doInBackground(Void... unused) {
578 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
579 readConfiguration(Launcher.this, localeConfiguration);
580 return localeConfiguration;
581 }
582
583 @Override
584 protected void onPostExecute(LocaleConfiguration result) {
585 sLocaleConfiguration = result;
586 checkForLocaleChange(); // recursive, but now with a locale configuration
587 }
588 }.execute();
589 return;
590 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700591
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592 final Configuration configuration = getResources().getConfiguration();
593
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700594 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800595 final String locale = configuration.locale.toString();
596
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700597 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800598 final int mcc = configuration.mcc;
599
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700600 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 final int mnc = configuration.mnc;
602
Romain Guy84f296c2009-11-04 15:00:44 -0800603 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800604
Romain Guy84f296c2009-11-04 15:00:44 -0800605 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606 sLocaleConfiguration.locale = locale;
607 sLocaleConfiguration.mcc = mcc;
608 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700609
Joe Onorato0589f0f2010-02-08 13:44:00 -0800610 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700611
612 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100613 new AsyncTask<Void, Void, Void>() {
614 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700615 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100616 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 }
Michael Jurka43467462013-11-14 12:03:58 +0100618 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700619 }
620 }
621
622 private static class LocaleConfiguration {
623 public String locale;
624 public int mcc = -1;
625 public int mnc = -1;
626 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700627
Romain Guy98d01652009-06-30 16:21:04 -0700628 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
629 DataInputStream in = null;
630 try {
631 in = new DataInputStream(context.openFileInput(PREFERENCES));
632 configuration.locale = in.readUTF();
633 configuration.mcc = in.readInt();
634 configuration.mnc = in.readInt();
635 } catch (FileNotFoundException e) {
636 // Ignore
637 } catch (IOException e) {
638 // Ignore
639 } finally {
640 if (in != null) {
641 try {
642 in.close();
643 } catch (IOException e) {
644 // Ignore
645 }
646 }
647 }
648 }
649
650 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
651 DataOutputStream out = null;
652 try {
653 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
654 out.writeUTF(configuration.locale);
655 out.writeInt(configuration.mcc);
656 out.writeInt(configuration.mnc);
657 out.flush();
658 } catch (FileNotFoundException e) {
659 // Ignore
660 } catch (IOException e) {
661 //noinspection ResultOfMethodCallIgnored
662 context.getFileStreamPath(PREFERENCES).delete();
663 } finally {
664 if (out != null) {
665 try {
666 out.close();
667 } catch (IOException e) {
668 // Ignore
669 }
670 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 }
672 }
673
Anton Hanssona2f665f2013-09-26 12:18:32 +0100674 public Stats getStats() {
675 return mStats;
676 }
677
Bjorn Bringertc459e522013-06-07 19:36:01 +0100678 public LayoutInflater getInflater() {
679 return mInflater;
680 }
681
Winson Chung36a62fe2012-05-06 18:04:42 -0700682 boolean isDraggingEnabled() {
683 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
684 // that is subsequently removed from the workspace in startBinding().
685 return !mModel.isLoadingWorkspace();
686 }
687
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800688 static int getScreen() {
689 synchronized (sLock) {
690 return sScreen;
691 }
692 }
693
694 static void setScreen(int screen) {
695 synchronized (sLock) {
696 sScreen = screen;
697 }
698 }
699
Winson Chung557d6ed2011-07-08 15:34:52 -0700700 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000701 * Copied from View -- the View version of the method isn't called
702 * anywhere else in our process and only exists for API level 17+,
703 * so it's ok to keep our own version with no API requirement.
704 */
705 public static int generateViewId() {
706 for (;;) {
707 final int result = sNextGeneratedId.get();
708 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
709 int newValue = result + 1;
710 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
711 if (sNextGeneratedId.compareAndSet(result, newValue)) {
712 return result;
713 }
714 }
715 }
716
717 public int getViewIdForItem(ItemInfo info) {
718 // This cast is safe given the > 2B range for int.
719 int itemId = (int) info.id;
720 if (mItemIdToViewId.containsKey(itemId)) {
721 return mItemIdToViewId.get(itemId);
722 }
723 int viewId = generateViewId();
724 mItemIdToViewId.put(itemId, viewId);
725 return viewId;
726 }
727
728 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700729 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
730 * a configuration step, this allows the proper animations to run after other transitions.
731 */
Adam Cohendb364c32014-05-20 14:23:40 -0700732 private long completeAdd(PendingAddArguments args) {
733
734 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800735 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800736 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700737 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700738 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700739 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800740 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700741 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700742 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700743 case REQUEST_RECONFIGURE_APPWIDGET:
744 completeRestoreAppWidget(args.appWidgetId);
745 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800746 }
Michael Jurka27614d22012-04-02 06:40:22 -0700747 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
748 // if you turned the screen off and then back while in All Apps, Launcher would not
749 // return to the workspace. Clearing mAddInfo.container here fixes this issue
750 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700751 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 }
753
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800754 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700755 protected void onActivityResult(
756 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700757 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700758 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700759 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800760 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700761
Adam Cohenad4e15c2013-10-17 16:21:35 -0700762 Runnable exitSpringLoaded = new Runnable() {
763 @Override
764 public void run() {
765 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
766 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
767 }
768 };
769
Michael Jurka8b805b12012-04-18 14:23:14 -0700770 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700771 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700772 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
773 if (resultCode == RESULT_CANCELED) {
774 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700775 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700776 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700777 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700778 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
779 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700780 }
781 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200782 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
783 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
784 mWorkspace.exitOverviewMode(false);
785 }
786 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700787 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200788
Adam Cohened66b2b2012-01-23 17:28:51 -0800789 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
790 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700791
Adam Cohendb364c32014-05-20 14:23:40 -0700792 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800793 // We have special handling for widgets
794 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800795 final int appWidgetId;
796 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
797 : -1;
798 if (widgetId < 0) {
799 appWidgetId = pendingAddWidgetId;
800 } else {
801 appWidgetId = widgetId;
802 }
803
Adam Cohenad4e15c2013-10-17 16:21:35 -0700804 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800805 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700806 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
807 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700808 result = RESULT_CANCELED;
809 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700810 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700811 @Override
812 public void run() {
813 exitSpringLoadedDragModeDelayed(false, 0, null);
814 }
815 };
Adam Cohendb364c32014-05-20 14:23:40 -0700816 if (workspaceLocked) {
817 // No need to remove the empty screen if we're mid-binding, as the
818 // the bind will not add the empty screen.
819 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
820 } else {
821 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
822 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
823 }
Winson Chung5aaab772012-04-27 15:24:02 -0700824 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700825 if (!workspaceLocked) {
826 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
827 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
828
829 dropLayout.setDropPending(true);
830 final Runnable onComplete = new Runnable() {
831 @Override
832 public void run() {
833 completeTwoStageWidgetDrop(resultCode, appWidgetId);
834 dropLayout.setDropPending(false);
835 }
836 };
837 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
838 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
839 } else {
840 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
841 mPendingAddInfo);
842 sPendingAddItem = args;
843 }
Winson Chung5aaab772012-04-27 15:24:02 -0700844 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800845 return;
846 }
847
Sunny Goyalff572272014-07-23 13:58:07 -0700848 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
849 if (resultCode == RESULT_OK) {
850 // Update the widget view.
851 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
852 pendingAddWidgetId, mPendingAddInfo);
853 if (workspaceLocked) {
854 sPendingAddItem = args;
855 } else {
856 completeAdd(args);
857 }
858 }
859 // Leave the widget in the pending state if the user canceled the configure.
860 return;
861 }
862
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800863 // The pattern used here is that a user PICKs a specific application,
864 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700865
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
867 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700868 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700869 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
870 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800871 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700872 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800873 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700874 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700875 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
876 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 }
Adam Cohen00074722013-10-11 17:46:09 -0700878 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700879 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700880 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800881 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800882 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800883 }
884
Adam Cohendb364c32014-05-20 14:23:40 -0700885 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
886 appWidgetId, ItemInfo info) {
887 PendingAddArguments args = new PendingAddArguments();
888 args.requestCode = requestCode;
889 args.intent = data;
890 args.container = info.container;
891 args.screenId = info.screenId;
892 args.cellX = info.cellX;
893 args.cellY = info.cellY;
894 args.appWidgetId = appWidgetId;
895 return args;
896 }
897
898 /**
899 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
900 *
901 * @param screenId the screen id to check
902 * @return the new screen, or screenId if it exists
903 */
904 private long ensurePendingDropLayoutExists(long screenId) {
905 CellLayout dropLayout =
906 (CellLayout) mWorkspace.getScreenWithId(screenId);
907 if (dropLayout == null) {
908 // it's possible that the add screen was removed because it was
909 // empty and a re-bind occurred
910 mWorkspace.addExtraEmptyScreen();
911 return mWorkspace.commitExtraEmptyScreen();
912 } else {
913 return screenId;
914 }
915 }
916
Adam Cohened66b2b2012-01-23 17:28:51 -0800917 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700918 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700919 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800920 Runnable onCompleteRunnable = null;
921 int animationType = 0;
922
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700923 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800924 if (resultCode == RESULT_OK) {
925 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
926 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700927 mPendingAddWidgetInfo);
928 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800929 onCompleteRunnable = new Runnable() {
930 @Override
931 public void run() {
932 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700933 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700934 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
935 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800936 }
937 };
938 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800939 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800940 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800941 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700942 if (mDragLayer.getAnimatedView() != null) {
943 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
944 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
945 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700946 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700947 // The animated view may be null in the case of a rotation during widget configuration
948 onCompleteRunnable.run();
949 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 }
951
952 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700953 protected void onStop() {
954 super.onStop();
955 FirstFrameAnimatorHelper.setIsVisible(false);
956 }
957
958 @Override
959 protected void onStart() {
960 super.onStart();
961 FirstFrameAnimatorHelper.setIsVisible(true);
962 }
963
964 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800965 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200966 long startTime = 0;
967 if (DEBUG_RESUME_TIME) {
968 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400969 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200970 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800971 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700972
Winson Chung4a2afa32012-07-19 14:53:05 -0700973 // Restore the previous launcher state
974 if (mOnResumeState == State.WORKSPACE) {
975 showWorkspace(false);
976 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800977 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700978 }
979 mOnResumeState = State.NONE;
980
Craig Mautner360310b2012-10-26 15:13:08 -0700981 // Background was set to gradient in onPause(), restore to black if in all apps.
982 setWorkspaceBackground(mState == State.WORKSPACE);
983
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800984 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700985 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700986 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500987 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400988 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700989 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800990 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700991 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200992 // We might have postponed some bind calls until onResume (see waitUntilResume) --
993 // execute them here
994 long startTimeCallbacks = 0;
995 if (DEBUG_RESUME_TIME) {
996 startTimeCallbacks = System.currentTimeMillis();
997 }
998
999 if (mAppsCustomizeContent != null) {
1000 mAppsCustomizeContent.setBulkBind(true);
1001 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001002 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1003 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001004 }
1005 if (mAppsCustomizeContent != null) {
1006 mAppsCustomizeContent.setBulkBind(false);
1007 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001008 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001009 if (DEBUG_RESUME_TIME) {
1010 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1011 (System.currentTimeMillis() - startTimeCallbacks));
1012 }
Michael Jurka447bf842013-05-15 14:52:15 +02001013 }
Michael Jurka54554252013-08-01 12:52:23 +02001014 if (mOnResumeCallbacks.size() > 0) {
1015 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1016 mOnResumeCallbacks.get(i).run();
1017 }
1018 mOnResumeCallbacks.clear();
1019 }
Winson Chunge4e50662012-01-23 14:45:13 -08001020
1021 // Reset the pressed state of icons that were locked in the press state while activities
1022 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001023 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001024 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001025 mWaitingForResume.setStayPressed(false);
1026 }
Winson Chunge4e50662012-01-23 14:45:13 -08001027 if (mAppsCustomizeContent != null) {
1028 // Resets the previous all apps icon press state
1029 mAppsCustomizeContent.resetDrawableState();
1030 }
Winson Chung82963d52013-10-09 11:20:57 -07001031
Adam Cohen06dff352012-06-01 17:17:08 -07001032 // It is possible that widgets can receive updates while launcher is not in the foreground.
1033 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1034 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1035 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001036 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001037
Winson Chung780fe592013-09-26 14:48:44 -07001038 // Process any items that were added while Launcher was away.
1039 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1040
Winson Chung5841efa2013-09-30 18:06:44 -07001041 // Update the voice search button proxy
1042 updateVoiceButtonProxyVisible(false);
1043
Adam Cohenf9426d52012-06-04 17:26:21 -07001044 // Again, as with the above scenario, it's possible that one or more of the global icons
1045 // were updated in the wrong orientation.
1046 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001047 if (DEBUG_RESUME_TIME) {
1048 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1049 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001050
1051 if (mWorkspace.getCustomContentCallbacks() != null) {
1052 // If we are resuming and the custom content is the current page, we call onShow().
1053 // It is also poassible that onShow will instead be called slightly after first layout
1054 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1055 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001056 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001057 }
1058 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001059 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001060 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001061
1062 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001063 }
1064
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001065 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001066 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001067 // Ensure that items added to Launcher are queued until Launcher returns
1068 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001069 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001070
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001071 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001072 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001073 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001074 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001075
1076 // We call onHide() aggressively. The custom content callbacks should be able to
1077 // debounce excess onHide calls.
1078 if (mWorkspace.getCustomContentCallbacks() != null) {
1079 mWorkspace.getCustomContentCallbacks().onHide();
1080 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001081 }
Romain Guycbb89e42009-06-08 15:52:54 -07001082
Adam Cohenbffe7452013-07-22 18:21:45 -07001083 QSBScroller mQsbScroller = new QSBScroller() {
1084 int scrollY = 0;
1085
1086 @Override
1087 public void setScrollY(int scroll) {
1088 scrollY = scroll;
1089
1090 if (mWorkspace.isOnOrMovingToCustomContent()) {
1091 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001092 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001093 }
1094 }
1095 };
1096
1097 public void resetQSBScroll() {
1098 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001099 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001100 }
1101
1102 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001103 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1104 // by a onResume or by scrolling otherwise.
1105 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001106
1107 // Custom content is completely hidden
1108 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001109
1110 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1111 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001112
1113 // Indicates whether the user is allowed to scroll away from the custom content.
1114 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001115 }
1116
Jorim Jaggid017f882014-01-14 17:08:48 -08001117 protected boolean hasSettings() {
1118 return false;
1119 }
1120
Adam Cohenbffe7452013-07-22 18:21:45 -07001121 public interface QSBScroller {
1122 public void setScrollY(int scrollY);
1123 }
1124
Winson Chung98ca0f72013-07-29 12:58:51 -07001125 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001126 CustomContentCallbacks callbacks, String description) {
1127 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001128 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001129 }
1130
Adam Cohenedb40762013-07-18 16:45:45 -07001131 // The custom content needs to offset its content to account for the QSB
1132 public int getTopOffsetForCustomContent() {
1133 return mWorkspace.getPaddingTop();
1134 }
1135
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001136 @Override
1137 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001138 // Flag the loader to stop early before switching
1139 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001140 if (mAppsCustomizeContent != null) {
1141 mAppsCustomizeContent.surrender();
1142 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001143 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001144 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001145
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001146 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001147 @Override
1148 public void onWindowFocusChanged(boolean hasFocus) {
1149 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001150 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001151 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001152
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001153 private boolean acceptFilter() {
1154 final InputMethodManager inputManager = (InputMethodManager)
1155 getSystemService(Context.INPUT_METHOD_SERVICE);
1156 return !inputManager.isFullscreenMode();
1157 }
1158
1159 @Override
1160 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001161 final int uniChar = event.getUnicodeChar();
1162 final boolean handled = super.onKeyDown(keyCode, event);
1163 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1164 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1166 keyCode, event);
1167 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001168 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001169 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001170 // showSearchDialog()
1171 // If there are multiple keystrokes before the search dialog takes focus,
1172 // onSearchRequested() will be called for every keystroke,
1173 // but it is idempotent, so it's fine.
1174 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 }
1176 }
1177
Joe Onorato8a9625e2010-01-28 15:55:35 -08001178 // Eat the long press event so the keyboard doesn't come up.
1179 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1180 return true;
1181 }
1182
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001183 return handled;
1184 }
1185
Karl Rosaen138a0412009-04-23 19:00:21 -07001186 private String getTypedText() {
1187 return mDefaultKeySsb.toString();
1188 }
1189
1190 private void clearTypedText() {
1191 mDefaultKeySsb.clear();
1192 mDefaultKeySsb.clearSpans();
1193 Selection.setSelection(mDefaultKeySsb, 0);
1194 }
1195
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001197 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1198 * State
1199 */
1200 private static State intToState(int stateOrdinal) {
1201 State state = State.WORKSPACE;
1202 final State[] stateValues = State.values();
1203 for (int i = 0; i < stateValues.length; i++) {
1204 if (stateValues[i].ordinal() == stateOrdinal) {
1205 state = stateValues[i];
1206 break;
1207 }
1208 }
1209 return state;
1210 }
1211
1212 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 * Restores the previous state, if it exists.
1214 *
1215 * @param savedState The previous state.
1216 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001217 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 private void restoreState(Bundle savedState) {
1219 if (savedState == null) {
1220 return;
1221 }
1222
Michael Jurka883f55b2010-10-21 15:47:14 -07001223 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001224 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001225 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001226 }
1227
Adam Cohen21cd0022013-10-09 18:57:02 -07001228 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1229 PagedView.INVALID_RESTORE_PAGE);
1230 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001231 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 }
1233
Winson Chung3d503fb2011-07-13 17:25:49 -07001234 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001235 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001236
Winson Chung3d503fb2011-07-13 17:25:49 -07001237 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1238 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001239 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001240 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1241 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001242 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1243 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1244 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001245 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001246 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001247 mRestoring = true;
1248 }
1249
1250 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1251 if (renameFolder) {
1252 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001253 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 mRestoring = true;
1255 }
Winson Chunga12a2502010-12-20 14:41:35 -08001256
Winson Chung785d2eb2011-04-14 16:08:02 -07001257 // Restore the AppsCustomize tab
1258 if (mAppsCustomizeTabHost != null) {
1259 String curTab = savedState.getString("apps_customize_currentTab");
1260 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001261 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001262 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001263 mAppsCustomizeContent.loadAssociatedPages(
1264 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001265 }
1266
Winson Chung5afbf7b2011-07-25 11:53:08 -07001267 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1268 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001269 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001270 mItemIdToViewId = (HashMap<Integer, Integer>)
1271 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 }
1273
1274 /**
1275 * Finds all the views we need and configure them properly.
1276 */
1277 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001278 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001279
Craig Mautner360310b2012-10-26 15:13:08 -07001280 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001281 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1282 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001283 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001284 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001285
John Spurlock77e1f472013-09-11 10:09:51 -04001286 mLauncherView.setSystemUiVisibility(
1287 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001288 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289
Winson Chung4c98d922011-05-31 16:50:48 -07001290 // Setup the drag layer
1291 mDragLayer.setup(this, dragController);
1292
Winson Chung3d503fb2011-07-13 17:25:49 -07001293 // Setup the hotseat
1294 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1295 if (mHotseat != null) {
1296 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001297 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001298 }
1299
Jorim Jaggid017f882014-01-14 17:08:48 -08001300 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001301 View widgetButton = findViewById(R.id.widget_button);
1302 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001303 @Override
1304 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001305 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001306 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001307 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001308 }
1309 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001310 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1311
1312 View wallpaperButton = findViewById(R.id.wallpaper_button);
1313 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001314 @Override
1315 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001316 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001317 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001318 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001319 }
1320 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001321 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1322
1323 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001324 if (hasSettings()) {
1325 settingsButton.setOnClickListener(new OnClickListener() {
1326 @Override
1327 public void onClick(View arg0) {
1328 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001329 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001330 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001331 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001332 });
1333 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1334 } else {
1335 settingsButton.setVisibility(View.GONE);
1336 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1337 lp.gravity = Gravity.END | Gravity.TOP;
1338 widgetButton.requestLayout();
1339 }
1340
Adam Cohendbdff6b2013-09-18 19:09:15 -07001341 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001342
Winson Chung4c98d922011-05-31 16:50:48 -07001343 // Setup the workspace
1344 mWorkspace.setHapticFeedbackEnabled(false);
1345 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001346 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001347 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001348
Winson Chungf0ea4d32011-06-06 14:27:16 -07001349 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001350 mSearchDropTargetBar = (SearchDropTargetBar)
1351 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001352
Winson Chungf0ea4d32011-06-06 14:27:16 -07001353 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001354 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001355 mAppsCustomizeContent = (AppsCustomizePagedView)
1356 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1357 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001358
Winson Chung3d503fb2011-07-13 17:25:49 -07001359 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001360 dragController.setDragScoller(mWorkspace);
1361 dragController.setScrollView(mDragLayer);
1362 dragController.setMoveTarget(mWorkspace);
1363 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001364 if (mSearchDropTargetBar != null) {
1365 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001366 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001367
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001368 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001369 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001370 mWeightWatcher = new WeightWatcher(this);
1371 mWeightWatcher.setAlpha(0.5f);
1372 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001373 new FrameLayout.LayoutParams(
1374 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001375 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001376 Gravity.BOTTOM)
1377 );
Adam Cohen39a06042013-07-19 14:30:12 -07001378
1379 boolean show = shouldShowWeightWatcher();
1380 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001381 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001382 }
1383
1384 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001385 * Sets the all apps button. This method is called from {@link Hotseat}.
1386 */
1387 public void setAllAppsButton(View allAppsButton) {
1388 mAllAppsButton = allAppsButton;
1389 }
1390
1391 public View getAllAppsButton() {
1392 return mAllAppsButton;
1393 }
1394
1395 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001396 * Creates a view representing a shortcut.
1397 *
1398 * @param info The data structure describing the shortcut.
1399 *
1400 * @return A View inflated from R.layout.application.
1401 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001402 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001404 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001405 }
1406
1407 /**
1408 * Creates a view representing a shortcut inflated from the specified resource.
1409 *
1410 * @param layoutResId The id of the XML layout used to create the shortcut.
1411 * @param parent The group the shortcut belongs to.
1412 * @param info The data structure describing the shortcut.
1413 *
1414 * @return A View inflated from layoutResId.
1415 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001416 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001417 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001418 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 return favorite;
1421 }
1422
1423 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 * Add a shortcut to the workspace.
1425 *
1426 * @param data The intent describing the shortcut.
1427 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001428 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001429 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001430 int cellY) {
1431 int[] cellXY = mTmpAddItemCellCoordinates;
1432 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001433 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001434
Michael Jurkad3ef3062010-11-23 16:23:58 -08001435 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001436
Adam Cohen558baaf2011-08-15 15:22:57 -07001437 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001438 if (info == null) {
1439 return;
1440 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001441 final View view = createShortcut(info);
1442
Adam Cohenfbba09b2011-07-18 21:43:05 -07001443 // First we check if we already know the exact location where we want to add this item.
1444 if (cellX >= 0 && cellY >= 0) {
1445 cellXY[0] = cellX;
1446 cellXY[1] = cellY;
1447 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001448
1449 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001450 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001451 true, null,null)) {
1452 return;
1453 }
1454 DragObject dragObject = new DragObject();
1455 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001456 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1457 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001458 return;
1459 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001460 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001461 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001462 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001463 foundCellSpan = (result != null);
1464 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001465 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001466 }
1467
1468 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001469 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001470 return;
1471 }
1472
Adam Cohendcd297f2013-06-18 13:13:40 -07001473 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474
1475 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001476 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001477 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 }
1479 }
1480
Adam Cohen2f093b62012-04-30 18:59:53 -07001481 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1482 int minHeight) {
1483 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001484 // We want to account for the extra amount of padding that we are adding to the widget
1485 // to ensure that it gets the full amount of space that it has requested
1486 int requiredWidth = minWidth + padding.left + padding.right;
1487 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001488 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001489 }
1490
Adam Cohen2f093b62012-04-30 18:59:53 -07001491 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1492 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001493 }
1494
Adam Cohen2f093b62012-04-30 18:59:53 -07001495 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1496 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001497 }
1498
Adam Cohen2f093b62012-04-30 18:59:53 -07001499 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1500 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001501 }
1502
Adam Cohen2f093b62012-04-30 18:59:53 -07001503 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1504 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001505 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001506 }
1507
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001509 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001511 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001512 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001514 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001515 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1516 if (appWidgetInfo == null) {
1517 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1518 }
Romain Guycbb89e42009-06-08 15:52:54 -07001519
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001520 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001521 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001522
Adam Cohen2f093b62012-04-30 18:59:53 -07001523 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1524 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001525
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001526 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001527 // We have saved the position to which the widget was dragged-- this really only matters
1528 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001529 int[] cellXY = mTmpAddItemCellCoordinates;
1530 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001531 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001532 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001533 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1534 cellXY[0] = mPendingAddInfo.cellX;
1535 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001536 spanXY[0] = mPendingAddInfo.spanX;
1537 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001538 foundCellSpan = true;
1539 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001540 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001541 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001542 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1543 spanXY[1], cellXY, finalSpan);
1544 spanXY[0] = finalSpan[0];
1545 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001546 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001547 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001548 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001549 }
1550
Michael Jurka0280c3b2010-09-17 15:00:07 -07001551 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001552 if (appWidgetId != -1) {
1553 // Deleting an app widget ID is a void call but writes to disk before returning
1554 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001555 new AsyncTask<Void, Void, Void>() {
1556 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001557 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001558 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001559 }
Michael Jurka43467462013-11-14 12:03:58 +01001560 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001561 }
Winson Chung93eef082012-03-23 15:59:27 -07001562 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001563 return;
1564 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001566 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001567 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1568 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001569 launcherInfo.spanX = spanXY[0];
1570 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001571 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1572 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001573
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001575 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576
1577 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001578 if (hostView == null) {
1579 // Perform actual inflation because we're live
1580 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1581 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1582 } else {
1583 // The AppWidgetHostView has already been inflated and instantiated
1584 launcherInfo.hostView = hostView;
1585 }
Romain Guycbb89e42009-06-08 15:52:54 -07001586
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001588 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001589 launcherInfo.notifyWidgetSizeChanged(this);
1590
Adam Cohendcd297f2013-06-18 13:13:40 -07001591 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001592 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001593
1594 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001596 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 }
Romain Guycbb89e42009-06-08 15:52:54 -07001598
Adam Cohended9f8d2010-11-03 13:25:16 -07001599 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1600 @Override
1601 public void onReceive(Context context, Intent intent) {
1602 final String action = intent.getAction();
1603 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1604 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001605 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001606 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001607
Winson Chungc100e8e2011-08-09 16:02:43 -07001608 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001609 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001610 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001611 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001612 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001613 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1614 mUserPresent = true;
1615 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001616 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1617 mModel.resetLoadedState(false, true);
1618 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1619 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1620 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1621 mModel.resetLoadedState(false, true);
1622 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1623 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1624 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001625 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1626 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1627 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001628 }
1629 }
1630 };
1631
1632 @Override
1633 public void onAttachedToWindow() {
1634 super.onAttachedToWindow();
1635
1636 // Listen for broadcasts related to user-presence
1637 final IntentFilter filter = new IntentFilter();
1638 filter.addAction(Intent.ACTION_SCREEN_OFF);
1639 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001640 // For handling managed profiles
1641 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1642 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001643 if (ENABLE_DEBUG_INTENTS) {
1644 filter.addAction(DebugIntents.DELETE_DATABASE);
1645 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1646 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001647 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001648 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001649 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001650 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001651 mVisible = true;
1652 }
1653
Adam Cohen0b395352014-06-09 22:54:36 +00001654 /**
1655 * Sets up transparent navigation and status bars in LMP.
1656 * This method is a no-op for other platform versions.
1657 */
1658 @TargetApi(19)
1659 private void setupTransparentSystemBarsForLmp() {
1660 // TODO(sansid): use the APIs directly when compiling against L sdk.
1661 // Currently we use reflection to access the flags and the API to set the transparency
1662 // on the System bars.
1663 if (Utilities.isLmp()) {
1664 try {
1665 getWindow().getAttributes().systemUiVisibility |=
1666 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1667 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1668 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1669 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1670 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1671 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1672 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1673 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1674
1675 Method setStatusBarColorMethod =
1676 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1677 Method setNavigationBarColorMethod =
1678 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1679 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1680 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1681 } catch (NoSuchFieldException e) {
1682 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1683 } catch (NoSuchMethodException ex) {
1684 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1685 } catch (IllegalAccessException e) {
1686 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1687 } catch (IllegalArgumentException e) {
1688 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1689 } catch (InvocationTargetException e) {
1690 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1691 } finally {}
1692 }
1693 }
1694
Adam Cohended9f8d2010-11-03 13:25:16 -07001695 @Override
1696 public void onDetachedFromWindow() {
1697 super.onDetachedFromWindow();
1698 mVisible = false;
1699
Adam Cohend113e0c2010-11-11 10:48:05 -08001700 if (mAttached) {
1701 unregisterReceiver(mReceiver);
1702 mAttached = false;
1703 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001704 updateRunning();
1705 }
1706
1707 public void onWindowVisibilityChanged(int visibility) {
1708 mVisible = visibility == View.VISIBLE;
1709 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001710 // The following code used to be in onResume, but it turns out onResume is called when
1711 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1712 // is a more appropriate event to handle
1713 if (mVisible) {
1714 mAppsCustomizeTabHost.onWindowVisible();
1715 if (!mWorkspaceLoading) {
1716 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001717 // We want to let Launcher draw itself at least once before we force it to build
1718 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001719 // apps is nice and speedy.
1720 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001721 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001722 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001723 if (mStarted) return;
1724 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001725 // We delay the layer building a bit in order to give
1726 // other message processing a time to run. In particular
1727 // this avoids a delay in hiding the IME if it was
1728 // currently shown, because doing that may involve
1729 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001730 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001731 final ViewTreeObserver.OnDrawListener listener = this;
1732 mWorkspace.post(new Runnable() {
1733 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001734 if (mWorkspace != null &&
1735 mWorkspace.getViewTreeObserver() != null) {
1736 mWorkspace.getViewTreeObserver().
1737 removeOnDrawListener(listener);
1738 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001739 }
1740 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001741 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001742 }
1743 });
1744 }
1745 clearTypedText();
1746 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001747 }
1748
1749 private void sendAdvanceMessage(long delay) {
1750 mHandler.removeMessages(ADVANCE_MSG);
1751 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1752 mHandler.sendMessageDelayed(msg, delay);
1753 mAutoAdvanceSentTime = System.currentTimeMillis();
1754 }
1755
1756 private void updateRunning() {
1757 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1758 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1759 mAutoAdvanceRunning = autoAdvanceRunning;
1760 if (autoAdvanceRunning) {
1761 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1762 sendAdvanceMessage(delay);
1763 } else {
1764 if (!mWidgetsToAdvance.isEmpty()) {
1765 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1766 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1767 }
1768 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001769 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001770 }
1771 }
1772 }
1773
1774 private final Handler mHandler = new Handler() {
1775 @Override
1776 public void handleMessage(Message msg) {
1777 if (msg.what == ADVANCE_MSG) {
1778 int i = 0;
1779 for (View key: mWidgetsToAdvance.keySet()) {
1780 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1781 final int delay = mAdvanceStagger * i;
1782 if (v instanceof Advanceable) {
1783 postDelayed(new Runnable() {
1784 public void run() {
1785 ((Advanceable) v).advance();
1786 }
1787 }, delay);
1788 }
1789 i++;
1790 }
1791 sendAdvanceMessage(mAdvanceInterval);
1792 }
1793 }
1794 };
1795
1796 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001797 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001798 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1799 if (v instanceof Advanceable) {
1800 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001801 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001802 updateRunning();
1803 }
1804 }
1805
1806 void removeWidgetToAutoAdvance(View hostView) {
1807 if (mWidgetsToAdvance.containsKey(hostView)) {
1808 mWidgetsToAdvance.remove(hostView);
1809 updateRunning();
1810 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001811 }
1812
Joe Onorato9c1289c2009-08-17 11:03:03 -04001813 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001814 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001815 launcherInfo.hostView = null;
1816 }
1817
Winson Chung93eef082012-03-23 15:59:27 -07001818 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1819 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1820 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001821 }
1822
Winson Chunga6945242014-01-08 14:04:34 -08001823 public DragLayer getDragLayer() {
1824 return mDragLayer;
1825 }
1826
1827 public Workspace getWorkspace() {
1828 return mWorkspace;
1829 }
1830
1831 public Hotseat getHotseat() {
1832 return mHotseat;
1833 }
1834
Jorim Jaggid017f882014-01-14 17:08:48 -08001835 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001836 return mOverviewPanel;
1837 }
1838
1839 public SearchDropTargetBar getSearchBar() {
1840 return mSearchDropTargetBar;
1841 }
1842
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001843 public LauncherAppWidgetHost getAppWidgetHost() {
1844 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
Romain Guycbb89e42009-06-08 15:52:54 -07001846
Winson Chunga9abd0e2010-10-27 17:18:37 -07001847 public LauncherModel getModel() {
1848 return mModel;
1849 }
1850
Winson Chunga6945242014-01-08 14:04:34 -08001851 public LauncherClings getLauncherClings() {
1852 return mLauncherClings;
1853 }
1854
1855 protected SharedPreferences getSharedPrefs() {
1856 return mSharedPrefs;
1857 }
1858
Bjorn Bringertc459e522013-06-07 19:36:01 +01001859 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001860 getWindow().closeAllPanels();
1861
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001862 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001863 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001864 }
1865
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001866 @Override
1867 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001868 long startTime = 0;
1869 if (DEBUG_RESUME_TIME) {
1870 startTime = System.currentTimeMillis();
1871 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 super.onNewIntent(intent);
1873
1874 // Close the menu
1875 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001876 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001877 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001878
Adam Cohened307df2013-10-02 09:37:31 -07001879 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1880 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1881 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001882
Adam Cohen6fecd412013-10-02 17:41:50 -07001883 if (mWorkspace == null) {
1884 // Can be cases where mWorkspace is null, this prevents a NPE
1885 return;
1886 }
1887 Folder openFolder = mWorkspace.getOpenFolder();
1888 // In all these cases, only animate if we're already on home
1889 mWorkspace.exitWidgetResizeMode();
1890 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001891 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001892 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001893 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001894
Adam Cohen6fecd412013-10-02 17:41:50 -07001895 closeFolder();
1896 exitSpringLoadedDragMode();
1897
1898 // If we are already on home, then just animate back to the workspace,
1899 // otherwise, just wait until onResume to set the state back to Workspace
1900 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001901 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001902 } else {
1903 mOnResumeState = State.WORKSPACE;
1904 }
1905
1906 final View v = getWindow().peekDecorView();
1907 if (v != null && v.getWindowToken() != null) {
1908 InputMethodManager imm = (InputMethodManager)getSystemService(
1909 INPUT_METHOD_SERVICE);
1910 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1911 }
1912
1913 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001914 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001915 mAppsCustomizeTabHost.reset();
1916 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001917
1918 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919 }
Adam Cohened307df2013-10-02 09:37:31 -07001920
Michael Jurka447bf842013-05-15 14:52:15 +02001921 if (DEBUG_RESUME_TIME) {
1922 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1923 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001924 }
1925
Adam Coppa120b8e2013-11-12 16:26:04 +00001926 /**
1927 * Override point for subclasses to prevent movement to the default screen when the home
1928 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1929 */
1930 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1931 return true;
1932 }
1933
1934 /**
1935 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1936 */
1937 protected void onHomeIntent() {
1938 // Do nothing
1939 }
1940
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001942 public void onRestoreInstanceState(Bundle state) {
1943 super.onRestoreInstanceState(state);
1944 for (int page: mSynchronouslyBoundPages) {
1945 mWorkspace.restoreInstanceStateForChild(page);
1946 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 }
1948
1949 @Override
1950 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001951 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001952 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1953 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001954 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001955 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001956
Michael Jurka883f55b2010-10-21 15:47:14 -07001957 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001958 // We close any open folder since it will not be re-opened, and we need to make sure
1959 // this state is reflected.
1960 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961
Adam Cohendcd297f2013-06-18 13:13:40 -07001962 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mWaitingForResult) {
1964 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001965 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1967 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001968 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1969 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1970 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001971 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972 }
1973
1974 if (mFolderInfo != null && mWaitingForResult) {
1975 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1976 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1977 }
Michael Jurka946ad472010-07-09 18:05:18 -07001978
Winson Chung785d2eb2011-04-14 16:08:02 -07001979 // Save the current AppsCustomize tab
1980 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001981 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1982 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001983 if (currentTabTag != null) {
1984 outState.putString("apps_customize_currentTab", currentTabTag);
1985 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001986 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1987 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001988 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001989 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990 }
1991
1992 @Override
1993 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001995
Winson Chunge7a03942011-08-05 15:05:12 -07001996 // Remove all pending runnables
1997 mHandler.removeMessages(ADVANCE_MSG);
1998 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001999 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002000
Winson Chungcd2b0142011-06-08 16:02:26 -07002001 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002002 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002003 mModel.stopLoader();
2004 app.setLauncher(null);
2005
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002007 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002009 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002011 mAppWidgetHost = null;
2012
2013 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014
2015 TextKeyListener.getInstance().release();
2016
Winson Chung81b52252012-08-27 15:34:29 -07002017 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2018 // to prevent leaking Launcher activities on orientation change.
2019 if (mModel != null) {
2020 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2021 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002022
2023 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002024 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002025
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002026 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002027 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002028 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002029 mWorkspace = null;
2030 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002031
Sunny Goyale755d462014-07-22 13:48:29 -07002032 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002033 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 }
2035
Adam Cohena9cf38f2011-05-02 15:36:58 -07002036 public DragController getDragController() {
2037 return mDragController;
2038 }
2039
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 @Override
2041 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002042 if (requestCode >= 0) {
2043 setWaitingForResult(true);
2044 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 super.startActivityForResult(intent, requestCode);
2046 }
2047
Winson Chung70d72102011-08-12 11:24:35 -07002048 /**
2049 * Indicates that we want global search for this activity by setting the globalSearch
2050 * argument for {@link #startSearch} to true.
2051 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002053 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002055
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002056 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002057
Karl Rosaen138a0412009-04-23 19:00:21 -07002058 if (initialQuery == null) {
2059 // Use any text typed in the launcher as the initial query
2060 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002061 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 if (appSearchData == null) {
2063 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002064 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 }
Winson Chungadf0c182012-08-23 14:59:07 -07002066 Rect sourceBounds = new Rect();
2067 if (mSearchDropTargetBar != null) {
2068 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2069 }
Romain Guycbb89e42009-06-08 15:52:54 -07002070
Bjorn Bringertc459e522013-06-07 19:36:01 +01002071 startSearch(initialQuery, selectInitialQuery,
2072 appSearchData, sourceBounds);
2073 }
2074
2075 public void startSearch(String initialQuery,
2076 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002077 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002078 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002079 }
2080
2081 /**
2082 * Starts the global search activity. This code is a copied from SearchManager
2083 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002084 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002085 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002086 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002087 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2088 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2089 if (globalSearchActivity == null) {
2090 Log.w(TAG, "No global search activity found.");
2091 return;
2092 }
2093 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2094 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2095 intent.setComponent(globalSearchActivity);
2096 // Make sure that we have a Bundle to put source in
2097 if (appSearchData == null) {
2098 appSearchData = new Bundle();
2099 } else {
2100 appSearchData = new Bundle(appSearchData);
2101 }
2102 // Set source to package name of app that starts global search, if not set already.
2103 if (!appSearchData.containsKey("source")) {
2104 appSearchData.putString("source", getPackageName());
2105 }
2106 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2107 if (!TextUtils.isEmpty(initialQuery)) {
2108 intent.putExtra(SearchManager.QUERY, initialQuery);
2109 }
2110 if (selectInitialQuery) {
2111 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2112 }
2113 intent.setSourceBounds(sourceBounds);
2114 try {
2115 startActivity(intent);
2116 } catch (ActivityNotFoundException ex) {
2117 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2118 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002119 }
2120
Yura4f93ec62014-02-04 14:15:21 +00002121 public boolean isOnCustomContent() {
2122 return mWorkspace.isOnOrMovingToCustomContent();
2123 }
2124
Winson Chung70d72102011-08-12 11:24:35 -07002125 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002126 public boolean onPrepareOptionsMenu(Menu menu) {
2127 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002128 if (!isOnCustomContent()) {
2129 // Close any open folders
2130 closeFolder();
2131 // Stop resizing any widgets
2132 mWorkspace.exitWidgetResizeMode();
2133 if (!mWorkspace.isInOverviewMode()) {
2134 // Show the overview mode
2135 showOverviewMode(true);
2136 } else {
2137 showWorkspace(true);
2138 }
Winson Chunge0298742014-01-17 12:03:00 -08002139 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002140 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002141 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002142
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002143 @Override
2144 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002145 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002146 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002147 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002148 }
2149
Joe Onorato9c1289c2009-08-17 11:03:03 -04002150 public boolean isWorkspaceLocked() {
2151 return mWorkspaceLoading || mWaitingForResult;
2152 }
2153
Adam Cohen517a7f52014-03-01 12:12:59 -08002154 public boolean isWorkspaceLoading() {
2155 return mWorkspaceLoading;
2156 }
2157
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002158 private void setWorkspaceLoading(boolean value) {
2159 boolean isLocked = isWorkspaceLocked();
2160 mWorkspaceLoading = value;
2161 if (isLocked != isWorkspaceLocked()) {
2162 onWorkspaceLockedChanged();
2163 }
2164 }
2165
2166 private void setWaitingForResult(boolean value) {
2167 boolean isLocked = isWorkspaceLocked();
2168 mWaitingForResult = value;
2169 if (isLocked != isWorkspaceLocked()) {
2170 onWorkspaceLockedChanged();
2171 }
2172 }
2173
2174 protected void onWorkspaceLockedChanged() { }
2175
Michael Jurka0280c3b2010-09-17 15:00:07 -07002176 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002177 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002178 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002179 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2180 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002181 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002182 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002183 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002184
Adam Cohenad4e15c2013-10-17 16:21:35 -07002185 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2186 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2187 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2188 }
2189
2190 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2191 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2192 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002193 if (appWidgetInfo.configure != null) {
2194 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002195 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002196
Bjorn Bringert7984c942009-12-09 15:38:25 +00002197 // Launch over to configure widget, if needed
2198 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002199 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002200 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002201 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002202 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002203 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002204 Runnable onComplete = new Runnable() {
2205 @Override
2206 public void run() {
2207 // Exit spring loaded mode if necessary after adding the widget
2208 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2209 null);
2210 }
2211 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002212 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002213 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002214 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002215 }
2216 }
Romain Guycbb89e42009-06-08 15:52:54 -07002217
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002218 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002219 // Close any folders that may be open.
2220 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002221 mWorkspace.moveToCustomContentScreen(animate);
2222 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002223 /**
2224 * Process a shortcut drop.
2225 *
2226 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002227 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002228 * @param cell The cell it should be added to, optional
2229 * @param position The location on the screen where it was dropped, optional
2230 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002231 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002232 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002233 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002234 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002235 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002236 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002237
2238 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002239 mPendingAddInfo.cellX = cell[0];
2240 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002241 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002242
2243 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2244 createShortcutIntent.setComponent(componentName);
2245 processShortcut(createShortcutIntent);
2246 }
2247
Adam Cohenfbba09b2011-07-18 21:43:05 -07002248 /**
2249 * Process a widget drop.
2250 *
2251 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002252 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253 * @param cell The cell it should be added to, optional
2254 * @param position The location on the screen where it was dropped, optional
2255 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002256 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002257 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002258 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002259 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002260 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002261 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002262 mPendingAddInfo.minSpanX = info.minSpanX;
2263 mPendingAddInfo.minSpanY = info.minSpanY;
2264
Adam Cohenfbba09b2011-07-18 21:43:05 -07002265 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002266 mPendingAddInfo.cellX = cell[0];
2267 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002268 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002269 if (span != null) {
2270 mPendingAddInfo.spanX = span[0];
2271 mPendingAddInfo.spanY = span[1];
2272 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002273
Adam Cohened66b2b2012-01-23 17:28:51 -08002274 AppWidgetHostView hostView = info.boundWidget;
2275 int appWidgetId;
2276 if (hostView != null) {
2277 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002278 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002279 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002280 // In this case, we either need to start an activity to get permission to bind
2281 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002282 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002283 Bundle options = info.bindOptions;
2284
2285 boolean success = false;
2286 if (options != null) {
2287 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2288 info.componentName, options);
2289 } else {
2290 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2291 info.componentName);
2292 }
2293 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002294 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002295 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002296 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002297 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2298 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2299 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002300 // TODO: we need to make sure that this accounts for the options bundle.
2301 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002302 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2303 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002304 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002305 }
2306
Joe Onoratodeb98af2010-02-19 14:59:39 -08002307 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002308 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002309 }
2310
Winson Chung24ab2f12010-09-16 14:10:47 -07002311 void processWallpaper(Intent intent) {
2312 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2313 }
2314
Adam Cohendcd297f2013-06-18 13:13:40 -07002315 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002316 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002317 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002318 folderInfo.title = getText(R.string.folder_name);
2319
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002320 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002321 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002322 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002323 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002324
2325 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002326 FolderIcon newFolder =
2327 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002328 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002329 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002330 // Force measure the new folder icon
2331 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2332 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002333 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002334 }
Romain Guycbb89e42009-06-08 15:52:54 -07002335
Joe Onorato9c1289c2009-08-17 11:03:03 -04002336 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002337 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002338 }
2339
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002340 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002341 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002342 }
2343
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002344 /**
2345 * Registers various content observers. The current implementation registers
2346 * only a favorites observer to keep track of the favorites applications.
2347 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002348 private void registerContentObservers() {
2349 ContentResolver resolver = getContentResolver();
2350 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2351 true, mWidgetObserver);
2352 }
2353
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002354 @Override
2355 public boolean dispatchKeyEvent(KeyEvent event) {
2356 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2357 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002359 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002360 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002361 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002362 dumpState();
2363 return true;
2364 }
2365 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002366 }
2367 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2368 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002369 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 return true;
2371 }
2372 }
2373
2374 return super.dispatchKeyEvent(event);
2375 }
2376
Joe Onorato88ec0992009-11-19 13:16:06 -08002377 @Override
2378 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002379 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002380 if (mAppsCustomizeContent.getContentType() ==
2381 AppsCustomizePagedView.ContentType.Applications) {
2382 showWorkspace(true);
2383 } else {
2384 showOverviewMode(true);
2385 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002386 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002387 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002388 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002389 Folder openFolder = mWorkspace.getOpenFolder();
2390 if (openFolder.isEditingName()) {
2391 openFolder.dismissEditingName();
2392 } else {
2393 closeFolder();
2394 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002395 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002396 mWorkspace.exitWidgetResizeMode();
2397
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002398 // Back button is a no-op here, but give at least some feedback for the button press
2399 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002400 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002401 }
2402
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002403 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002404 * Re-listen when widgets are reset.
2405 */
2406 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002407 if (mAppWidgetHost != null) {
2408 mAppWidgetHost.startListening();
2409 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002410 }
2411
2412 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002413 * Launches the intent referred by the clicked shortcut.
2414 *
2415 * @param v The view representing the clicked shortcut.
2416 */
2417 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002418 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2419 // view has detached (it's possible for this to happen if the view is removed mid touch).
2420 if (v.getWindowToken() == null) {
2421 return;
2422 }
2423
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002424 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002425 return;
2426 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002427
Adam Cohen1697b792013-09-17 19:08:21 -07002428 if (v instanceof Workspace) {
2429 if (mWorkspace.isInOverviewMode()) {
2430 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002431 }
2432 return;
2433 }
2434
2435 if (v instanceof CellLayout) {
2436 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002437 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002438 }
2439 }
2440
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002441 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002442 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002443 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002444 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002445 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002446 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002447 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002448 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002449 onClickAllAppsButton(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002450 } else if (tag instanceof LauncherAppWidgetInfo) {
2451 if (v instanceof PendingAppWidgetHostView) {
2452 onClickPendingWidget((PendingAppWidgetHostView) v);
2453 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002454 }
2455 }
2456
Michael Jurka0e260592010-06-30 17:07:39 -07002457 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002458 return false;
2459 }
2460
Michael Jurkaaf442092010-06-10 17:01:57 -07002461 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002462 * Event handler for the app widget view which has not fully restored.
2463 */
2464 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2465 if (v.isReadyForClickSetup()) {
2466 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2467 int widgetId = info.appWidgetId;
2468 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2469 if (appWidgetInfo != null) {
2470 mPendingAddWidgetInfo = appWidgetInfo;
2471 mPendingAddInfo.copyFrom(info);
2472 mPendingAddWidgetId = widgetId;
2473
2474 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2475 intent.setComponent(appWidgetInfo.configure);
2476 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2477 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2478 }
2479 }
2480 }
2481
2482 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002483 * Event handler for the search button
2484 *
2485 * @param v The view that was clicked.
2486 */
2487 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002488 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2489
Amith Yamasania135ba82011-08-09 17:42:01 -07002490 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002491 }
2492
2493 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002494 * Event handler for the voice button
2495 *
2496 * @param v The view that was clicked.
2497 */
2498 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002499 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002500
Bjorn Bringertc459e522013-06-07 19:36:01 +01002501 startVoice();
2502 }
2503
2504 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002505 try {
2506 final SearchManager searchManager =
2507 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2508 ComponentName activityName = searchManager.getGlobalSearchActivity();
2509 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002510 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002511 if (activityName != null) {
2512 intent.setPackage(activityName.getPackageName());
2513 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002514 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002515 } catch (ActivityNotFoundException e) {
2516 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002517 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002518 startActivitySafely(null, intent, "onClickVoiceButton");
2519 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002520 }
2521
2522 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002523 * Event handler for the "grid" button that appears on the home screen, which
2524 * enters all apps mode.
2525 *
2526 * @param v The view that was clicked.
2527 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002528 protected void onClickAllAppsButton(View v) {
2529 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2530 if (isAllAppsVisible()) {
2531 showWorkspace(true);
2532 } else {
2533 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2534 }
2535 }
2536
2537 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002538 * Event handler for a paged view icon click.
2539 * @param v The view that was clicked.
2540 * @param appInfo The {link AppInfo} of the view.
2541 */
2542 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2543 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2544 startActivitySafely(v, appInfo.intent, appInfo);
2545 getStats().recordLaunch(appInfo.intent);
2546 }
2547
2548 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002549 * Event handler for an app shortcut click.
2550 *
2551 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2552 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002553 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002554 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2555 Object tag = v.getTag();
2556 if (!(tag instanceof ShortcutInfo)) {
2557 throw new IllegalArgumentException("Input must be a Shortcut");
2558 }
2559
2560 // Open shortcut
2561 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2562 final Intent intent = shortcut.intent;
2563
2564 // Check for special shortcuts
2565 if (intent.getComponent() != null) {
2566 final String shortcutClass = intent.getComponent().getClassName();
2567
2568 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2569 MemoryDumpActivity.startDump(this);
2570 return;
2571 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2572 toggleShowWeightWatcher();
2573 return;
2574 }
2575 }
2576
Chris Wren40c5ed32014-06-24 18:24:23 -04002577 // Check for abandoned promise
2578 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002579 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2580 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002581 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002582 builder.setPositiveButton(R.string.abandoned_search,
2583 new DialogInterface.OnClickListener() {
2584 public void onClick(DialogInterface dialog, int id) {
2585 startAppShortcutActivity(v);
2586 }
2587 }
2588 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002589 builder.setNeutralButton(R.string.abandoned_clean_this,
2590 new DialogInterface.OnClickListener() {
2591 public void onClick(DialogInterface dialog, int id) {
2592 final BubbleTextView bubble = (BubbleTextView) v;
2593 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2594 mWorkspace.removeAbandonedPromise(bubble, user);
2595 }
2596 });
2597 builder.create().show();
2598 return;
2599 }
2600
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002601 // Start activities
Chris Wren40c5ed32014-06-24 18:24:23 -04002602 startAppShortcutActivity(v);
2603 }
2604
2605 private void startAppShortcutActivity(View v) {
2606 Object tag = v.getTag();
2607 if (!(tag instanceof ShortcutInfo)) {
2608 throw new IllegalArgumentException("Input must be a Shortcut");
2609 }
2610 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2611 final Intent intent = shortcut.intent;
2612
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002613 int[] pos = new int[2];
2614 v.getLocationOnScreen(pos);
2615 intent.setSourceBounds(new Rect(pos[0], pos[1],
2616 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2617
2618 boolean success = startActivitySafely(v, intent, tag);
2619
2620 mStats.recordLaunch(intent, shortcut);
2621
2622 if (success && v instanceof BubbleTextView) {
2623 mWaitingForResume = (BubbleTextView) v;
2624 mWaitingForResume.setStayPressed(true);
2625 }
2626 }
2627
2628 /**
2629 * Event handler for a folder icon click.
2630 *
2631 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2632 */
2633 protected void onClickFolderIcon(View v) {
2634 if (LOGD) Log.d(TAG, "onClickFolder");
2635 if (!(v instanceof FolderIcon)){
2636 throw new IllegalArgumentException("Input must be a FolderIcon");
2637 }
2638
2639 FolderIcon folderIcon = (FolderIcon) v;
2640 final FolderInfo info = folderIcon.getFolderInfo();
2641 Folder openFolder = mWorkspace.getFolderForTag(info);
2642
2643 // If the folder info reports that the associated folder is open, then verify that
2644 // it is actually opened. There have been a few instances where this gets out of sync.
2645 if (info.opened && openFolder == null) {
2646 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2647 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2648 info.opened = false;
2649 }
2650
2651 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2652 // Close any open folder
2653 closeFolder();
2654 // Open the requested folder
2655 openFolder(folderIcon);
2656 } else {
2657 // Find the open folder...
2658 int folderScreen;
2659 if (openFolder != null) {
2660 folderScreen = mWorkspace.getPageForView(openFolder);
2661 // .. and close it
2662 closeFolder(openFolder);
2663 if (folderScreen != mWorkspace.getCurrentPage()) {
2664 // Close any folder open on the current screen
2665 closeFolder();
2666 // Pull the folder onto this screen
2667 openFolder(folderIcon);
2668 }
2669 }
2670 }
Michael Jurka5130e402011-10-13 04:55:35 -07002671 }
2672
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002673 /**
2674 * Event handler for the (Add) Widgets button that appears after a long press
2675 * on the home screen.
2676 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002677 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002678 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002679 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2680 }
2681
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002682 /**
2683 * Event handler for the wallpaper picker button that appears after a long press
2684 * on the home screen.
2685 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002686 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002687 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2688 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2689 pickWallpaper.setComponent(getWallpaperPickerComponent());
2690 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2691 }
2692
2693 /**
2694 * Event handler for a click on the settings button that appears after a long press
2695 * on the home screen.
2696 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002697 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002698 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2699 }
2700
Michael Jurka5130e402011-10-13 04:55:35 -07002701 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002702 // Provide the same haptic feedback that the system offers for virtual keys.
2703 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002704 }
2705
Adam Cohen61f560d2013-09-30 15:58:20 -07002706 public void performHapticFeedbackOnTouchDown(View v) {
2707 // Provide the same haptic feedback that the system offers for virtual keys.
2708 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2709 }
2710
2711 public View.OnTouchListener getHapticFeedbackTouchListener() {
2712 if (mHapticFeedbackTouchListener == null) {
2713 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2714 @Override
2715 public boolean onTouch(View v, MotionEvent event) {
2716 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2717 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2718 }
2719 return false;
2720 }
2721 };
2722 }
2723 return mHapticFeedbackTouchListener;
2724 }
2725
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002726 public void onDragStarted(View view) {}
2727
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002728 /**
2729 * Called when the user stops interacting with the launcher.
2730 * This implies that the user is now on the homescreen and is not doing housekeeping.
2731 */
2732 protected void onInteractionEnd() {}
2733
2734 /**
2735 * Called when the user starts interacting with the launcher.
2736 * The possible interactions are:
2737 * - open all apps
2738 * - reorder an app shortcut, or a widget
2739 * - open the overview mode.
2740 * This is a good time to stop doing things that only make sense
2741 * when the user is on the homescreen and not doing housekeeping.
2742 */
2743 protected void onInteractionBegin() {}
2744
Kenny Guyf07af7b2014-07-31 11:39:16 +01002745 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002746 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002747 try {
2748 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2749 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2750 launcherApps.showAppDetailsForProfile(componentName, user);
2751 } catch (SecurityException e) {
2752 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2753 Log.e(TAG, "Launcher does not have permission to launch settings");
2754 } catch (ActivityNotFoundException e) {
2755 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2756 Log.e(TAG, "Unable to launch settings");
2757 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002758 }
2759
Michael Jurka1e2f4652013-07-08 18:03:46 -07002760 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002761 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2762 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002763 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002764 // System applications cannot be installed. For now, show a toast explaining that.
2765 // We may give them the option of disabling apps this way.
2766 int messageId = R.string.uninstall_system_app_text;
2767 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002768 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002769 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002770 String packageName = componentName.getPackageName();
2771 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002772 Intent intent = new Intent(
2773 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002774 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2775 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002776 if (user != null) {
2777 user.addToIntent(intent, Intent.EXTRA_USER);
2778 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002779 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002780 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002781 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002782 }
2783
Michael Jurka86a720e2012-05-09 11:23:23 -07002784 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002785 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002786 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002787 // Only launch using the new animation if the shortcut has not opted out (this is a
2788 // private contract between launcher and may be ignored in the future).
2789 boolean useLaunchAnimation = (v != null) &&
2790 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002791 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2792 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002793
Kenny Guy1317e2d2014-05-08 18:52:50 +01002794 UserHandleCompat user = null;
2795 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2796 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2797 user = userManager.getUserForSerialNumber(serialNumber);
2798 }
2799
2800 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002801 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002802 ActivityOptions opts = Utilities.isLmp() ?
2803 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2804 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002805 optsBundle = opts.toBundle();
2806 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002807
2808 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2809 // Could be launching some bookkeeping activity
2810 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002811 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002812 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002813 launcherApps.startActivityForProfile(intent.getComponent(), user,
2814 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002815 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002816 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002817 } catch (SecurityException e) {
2818 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002819 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002820 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002821 "or use the exported attribute for this activity. "
2822 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002823 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002824 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002825 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002826
Michael Jurka86a720e2012-05-09 11:23:23 -07002827 boolean startActivitySafely(View v, Intent intent, Object tag) {
2828 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002829 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2830 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2831 return false;
2832 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002833 try {
2834 success = startActivity(v, intent, tag);
2835 } catch (ActivityNotFoundException e) {
2836 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2837 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2838 }
2839 return success;
2840 }
2841
Adam Cohen268c4752012-06-06 17:47:33 -07002842 /**
2843 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2844 * in the DragLayer in the exact absolute location of the original FolderIcon.
2845 */
2846 private void copyFolderIconToImage(FolderIcon fi) {
2847 final int width = fi.getMeasuredWidth();
2848 final int height = fi.getMeasuredHeight();
2849
2850 // Lazy load ImageView, Bitmap and Canvas
2851 if (mFolderIconImageView == null) {
2852 mFolderIconImageView = new ImageView(this);
2853 }
2854 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2855 mFolderIconBitmap.getHeight() != height) {
2856 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2857 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2858 }
2859
2860 DragLayer.LayoutParams lp;
2861 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2862 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2863 } else {
2864 lp = new DragLayer.LayoutParams(width, height);
2865 }
2866
Adam Cohen307fe232012-08-16 17:55:58 -07002867 // The layout from which the folder is being opened may be scaled, adjust the starting
2868 // view size by this scale factor.
2869 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002870 lp.customPosition = true;
2871 lp.x = mRectForFolderAnimation.left;
2872 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002873 lp.width = (int) (scale * width);
2874 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002875
2876 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2877 fi.draw(mFolderIconCanvas);
2878 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002879 if (fi.getFolder() != null) {
2880 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2881 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002882 }
Adam Cohen268c4752012-06-06 17:47:33 -07002883 // Just in case this image view is still in the drag layer from a previous animation,
2884 // we remove it and re-add it.
2885 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2886 mDragLayer.removeView(mFolderIconImageView);
2887 }
2888 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002889 if (fi.getFolder() != null) {
2890 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002891 }
Adam Cohen268c4752012-06-06 17:47:33 -07002892 }
2893
Adam Cohen2801caf2011-05-13 20:57:39 -07002894 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002895 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002896 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2897 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2898 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2899
Adam Cohenc51934b2011-07-26 21:07:43 -07002900 FolderInfo info = (FolderInfo) fi.getTag();
2901 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2902 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002903 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2904 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002905 }
2906
Adam Cohen268c4752012-06-06 17:47:33 -07002907 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2908 copyFolderIconToImage(fi);
2909 fi.setVisibility(View.INVISIBLE);
2910
Michael Jurka2ecf9952012-06-18 12:52:28 -07002911 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002912 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002913 if (Utilities.isLmp()) {
2914 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2915 }
2916 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002917 oa.start();
2918 }
2919
Adam Cohen268c4752012-06-06 17:47:33 -07002920 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002921 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002922 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2923 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2924 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2925
Adam Cohen268c4752012-06-06 17:47:33 -07002926 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002927
Adam Cohen268c4752012-06-06 17:47:33 -07002928 // We remove and re-draw the FolderIcon in-case it has changed
2929 mDragLayer.removeView(mFolderIconImageView);
2930 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002931 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002932 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002933 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002934 oa.addListener(new AnimatorListenerAdapter() {
2935 @Override
2936 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002937 if (cl != null) {
2938 cl.clearFolderLeaveBehind();
2939 // Remove the ImageView copy of the FolderIcon and make the original visible.
2940 mDragLayer.removeView(mFolderIconImageView);
2941 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002942 }
2943 }
2944 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002945 oa.start();
2946 }
2947
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002948 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002949 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002950 * is animated relative to the specified View. If the View is null, no animation
2951 * is played.
2952 *
2953 * @param folderInfo The FolderInfo describing the folder to open.
2954 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002955 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002956 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002957 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002958
Adam Cohena9cf38f2011-05-02 15:36:58 -07002959 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002960
Adam Cohen4554ee12011-08-03 16:13:21 -07002961 // Just verify that the folder hasn't already been added to the DragLayer.
2962 // There was a one-off crash where the folder had a parent already.
2963 if (folder.getParent() == null) {
2964 mDragLayer.addView(folder);
2965 mDragController.addDropTarget((DropTarget) folder);
2966 } else {
2967 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2968 folder.getParent() + ").");
2969 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002970 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002971 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002972
2973 // Notify the accessibility manager that this folder "window" has appeared and occluded
2974 // the workspace items
2975 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2976 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002977 }
2978
2979 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002980 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002981 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002982 if (folder.isEditingName()) {
2983 folder.dismissEditingName();
2984 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002985 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002986
2987 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002988 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002989 }
2990 }
2991
2992 void closeFolder(Folder folder) {
2993 folder.getInfo().opened = false;
2994
2995 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2996 if (parent != null) {
2997 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2998 shrinkAndFadeInFolderIcon(fi);
2999 }
3000 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003001
3002 // Notify the accessibility manager that this folder "window" has disappeard and no
3003 // longer occludeds the workspace items
3004 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003005 }
3006
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003007 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003008 if (!isDraggingEnabled()) return false;
3009 if (isWorkspaceLocked()) return false;
3010 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003011
Adam Cohen1697b792013-09-17 19:08:21 -07003012 if (v instanceof Workspace) {
3013 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003014 if (mWorkspace.enterOverviewMode()) {
3015 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3016 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3017 return true;
3018 } else {
3019 return false;
3020 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003021 } else {
3022 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003023 }
Adam Cohen1697b792013-09-17 19:08:21 -07003024 }
3025
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003026 CellLayout.CellInfo longClickCellInfo = null;
3027 View itemUnderLongClick = null;
3028 if (v.getTag() instanceof ItemInfo) {
3029 ItemInfo info = (ItemInfo) v.getTag();
3030 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3031 itemUnderLongClick = longClickCellInfo.cell;
3032 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003033 }
3034
Winson Chung3d503fb2011-07-13 17:25:49 -07003035 // The hotseat touch handling does not go through Workspace, and we always allow long press
3036 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003037 final boolean inHotseat = isHotseatLayout(v);
3038 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003039 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003040 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003041 // User long pressed on empty space
3042 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3043 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003044 if (mWorkspace.isInOverviewMode()) {
3045 mWorkspace.startReordering(v);
3046 } else {
3047 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003048 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003049 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003050 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3051 mHotseat.getOrderInHotseat(
3052 longClickCellInfo.cellX,
3053 longClickCellInfo.cellY));
3054 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003055 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003056 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003057 }
3058 }
3059 }
3060 return true;
3061 }
3062
Winson Chung3d503fb2011-07-13 17:25:49 -07003063 boolean isHotseatLayout(View layout) {
3064 return mHotseat != null && layout != null &&
3065 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3066 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003067
Winson Chung3d503fb2011-07-13 17:25:49 -07003068 /**
3069 * Returns the CellLayout of the specified container at the specified screen.
3070 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003071 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003072 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3073 if (mHotseat != null) {
3074 return mHotseat.getLayout();
3075 } else {
3076 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003077 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003078 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003079 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003080 }
3081 }
3082
Daniel Sandler843e8602010-06-07 14:59:01 -04003083 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003084 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003085 }
3086
Craig Mautner360310b2012-10-26 15:13:08 -07003087 private void setWorkspaceBackground(boolean workspace) {
3088 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003089 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003090 }
3091
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003092 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003093 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3094 int curflags = getWindow().getAttributes().flags
3095 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3096 if (wpflags != curflags) {
3097 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3098 }
Craig Mautner360310b2012-10-26 15:13:08 -07003099 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003100 }
3101
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003102 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3103 if (v instanceof LauncherTransitionable) {
3104 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3105 }
3106 }
3107
Michael Jurkabed61d22012-02-14 22:51:29 -08003108 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3109 if (v instanceof LauncherTransitionable) {
3110 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3111 }
Winson Chung70442722012-02-10 15:43:22 -08003112
3113 // Update the workspace transition step as well
3114 dispatchOnLauncherTransitionStep(v, 0f);
3115 }
3116
3117 private void dispatchOnLauncherTransitionStep(View v, float t) {
3118 if (v instanceof LauncherTransitionable) {
3119 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3120 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003121 }
3122
3123 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3124 if (v instanceof LauncherTransitionable) {
3125 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3126 }
Winson Chung70442722012-02-10 15:43:22 -08003127
3128 // Update the workspace transition step as well
3129 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003130 }
3131
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003132 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003133 * Things to test when changing the following seven functions.
3134 * - Home from workspace
3135 * - from center screen
3136 * - from other screens
3137 * - Home from all apps
3138 * - from center screen
3139 * - from other screens
3140 * - Back from all apps
3141 * - from center screen
3142 * - from other screens
3143 * - Launch app from workspace and quit
3144 * - with back
3145 * - with home
3146 * - Launch app from all apps and quit
3147 * - with back
3148 * - with home
3149 * - Go to a screen that's not the default, then all
3150 * apps, and launch and app, and go back
3151 * - with back
3152 * -with home
3153 * - On workspace, long press power and go back
3154 * - with back
3155 * - with home
3156 * - On all apps, long press power and go back
3157 * - with back
3158 * - with home
3159 * - On workspace, power off
3160 * - On all apps, power off
3161 * - Launch an app and turn off the screen while in that app
3162 * - Go back with home key
3163 * - Go back with back key TODO: make this not go to workspace
3164 * - From all apps
3165 * - From workspace
3166 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3167 * - From all apps
3168 * - From the center workspace
3169 * - From another workspace
3170 */
3171
3172 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003173 * Zoom the camera out from the workspace to reveal 'toView'.
3174 * Assumes that the view to show is anchored at either the very top or very bottom
3175 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003176 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003177 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003178 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3179 showAppsCustomizeHelper(animated, springLoaded, contentType);
3180 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003181
Winson Chungc58497e2013-09-03 17:48:37 -07003182 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3183 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003184 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003185 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003186 mStateAnimation.cancel();
3187 mStateAnimation = null;
3188 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003189
3190 boolean material = Utilities.isLmp();
3191
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003192 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003193
Winson Chungf0ea4d32011-06-06 14:27:16 -07003194 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3195 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003196 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003197 final int itemsAlphaStagger =
3198 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003199
Winson Chungf0ea4d32011-06-06 14:27:16 -07003200 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003201 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003202 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003203
Adam Cohen6c5891a2014-07-09 23:53:15 -07003204 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3205 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003206 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003207 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003208 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003209 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3210 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003211 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3212 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003213
3214 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003215 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003216
Adam Cohen9bfdb762014-07-21 17:44:06 -07003217 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3218 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003219
Adam Cohen9bfdb762014-07-21 17:44:06 -07003220 final View page = content.getPageAt(content.getCurrentPage());
3221 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003222
Adam Cohen63f1ec02014-08-12 09:23:13 -07003223 final float initialPanelAlpha = 1f;
3224
3225 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3226 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003227 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3228 } else {
3229 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3230 }
3231
Adam Cohen9bfdb762014-07-21 17:44:06 -07003232 // Hide the real page background, and swap in the fake one
3233 revealView.setVisibility(View.VISIBLE);
3234 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003235
Adam Cohen9bfdb762014-07-21 17:44:06 -07003236 int width = revealView.getMeasuredWidth();
3237 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003238
Adam Cohen9bfdb762014-07-21 17:44:06 -07003239 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003240 revealView.setTranslationY(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003241
Adam Cohen63f1ec02014-08-12 09:23:13 -07003242 // Get the y delta between the center of the page and the center of the all apps button
3243 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3244 getAllAppsButton(), null);
3245 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3246
3247 float initAlpha = isWidgetTray ? 0.3f : 1f;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003248 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003249 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003250 PropertyValuesHolder panelDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003251 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003252
Adam Cohen9bfdb762014-07-21 17:44:06 -07003253 ObjectAnimator panelAlphaAndDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003254 LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003255 panelAlphaAndDrift.setDuration(revealDuration);
3256 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003257
Adam Cohen9bfdb762014-07-21 17:44:06 -07003258 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003259
Adam Cohen4e243a22014-08-10 18:30:55 -07003260 if (page != null) {
3261 page.setVisibility(View.VISIBLE);
3262 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003263
Adam Cohen63f1ec02014-08-12 09:23:13 -07003264 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0);
Adam Cohen4e243a22014-08-10 18:30:55 -07003265 pageDrift.setDuration(revealDuration);
3266 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003267 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003268 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003269
Adam Cohen63f1ec02014-08-12 09:23:13 -07003270 page.setAlpha(0f);
3271 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003272 itemsAlpha.setDuration(revealDuration);
3273 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3274 itemsAlpha.setStartDelay(itemsAlphaStagger);
3275 mStateAnimation.play(itemsAlpha);
3276 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003277
Adam Cohen4e243a22014-08-10 18:30:55 -07003278 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3279 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003280 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003281 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003282 indicatorsAlpha.setDuration(revealDuration);
3283 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003284
Adam Cohen9bfdb762014-07-21 17:44:06 -07003285 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003286 final View allApps = getAllAppsButton();
3287 int allAppsButtonSize = LauncherAppState.getInstance().
3288 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3289 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003290 Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003291 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003292 reveal.setDuration(revealDuration);
3293 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003294
3295 reveal.addListener(new AnimatorListenerAdapter() {
3296 public void onAnimationStart(Animator animation) {
3297 if (!isWidgetTray) {
3298 allApps.setVisibility(View.INVISIBLE);
3299 }
3300 }
3301 public void onAnimationEnd(Animator animation) {
3302 if (!isWidgetTray) {
3303 allApps.setVisibility(View.VISIBLE);
3304 }
3305 }
3306 });
3307
Adam Cohen6c5891a2014-07-09 23:53:15 -07003308 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003309 }
Michael Jurka1899a362011-11-03 13:50:45 -07003310
Adam Cohen9bfdb762014-07-21 17:44:06 -07003311 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3312 @Override
3313 public void onAnimationEnd(Animator animation) {
3314 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3315 dispatchOnLauncherTransitionEnd(toView, animated, false);
3316
3317 revealView.setVisibility(View.INVISIBLE);
3318 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003319 if (page != null) {
3320 page.setLayerType(View.LAYER_TYPE_NONE, null);
3321 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003322 content.setPageBackgroundsVisible(true);
3323
3324 // Hide the search bar
3325 if (mSearchDropTargetBar != null) {
3326 mSearchDropTargetBar.hideSearchBar(false);
3327 }
3328 }
3329
3330 @Override
3331 public void onAnimationStart(Animator animation) {
3332 // Prepare the position
3333 toView.bringToFront();
3334 toView.setVisibility(View.VISIBLE);
3335 }
3336 });
3337
Michael Jurka1899a362011-11-03 13:50:45 -07003338 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003339 if (workspaceAnim != null) {
3340 mStateAnimation.play(workspaceAnim);
3341 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003342 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3343 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003344
3345 // If any of the objects being animated haven't been measured/laid out
3346 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003347 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003348 (mWorkspace.getMeasuredWidth() == 0) ||
3349 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003350 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003351 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003352
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003353 final AnimatorSet stateAnimation = mStateAnimation;
3354 final Runnable startAnimRunnable = new Runnable() {
3355 public void run() {
3356 // Check that mStateAnimation hasn't changed while
3357 // we waited for a layout/draw pass
3358 if (mStateAnimation != stateAnimation)
3359 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003360 dispatchOnLauncherTransitionStart(fromView, animated, false);
3361 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003362 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003363 }
3364 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003365 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003366 toView.bringToFront();
3367 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003368 final ViewTreeObserver observer = toView.getViewTreeObserver();
3369 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3370 public void onGlobalLayout() {
3371 startAnimRunnable.run();
3372 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3373 }
3374 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003375 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003376 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003377 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003378 } else {
3379 toView.setTranslationX(0.0f);
3380 toView.setTranslationY(0.0f);
3381 toView.setScaleX(1.0f);
3382 toView.setScaleY(1.0f);
3383 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003384 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003385
Daniel Sandlere4f98912013-06-25 15:13:26 -04003386 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003387 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003388 if (mSearchDropTargetBar != null) {
3389 mSearchDropTargetBar.hideSearchBar(false);
3390 }
Michael Jurkaabded662011-03-04 12:06:57 -08003391 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003392 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003393 dispatchOnLauncherTransitionStart(fromView, animated, false);
3394 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003395 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003396 dispatchOnLauncherTransitionStart(toView, animated, false);
3397 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003398 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003399 }
3400
3401 /**
3402 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003403 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003404 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003405 */
Adam Cohened307df2013-10-02 09:37:31 -07003406 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003407 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003408
Michael Jurkab3e22d92011-10-31 15:58:33 -07003409 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003410 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003411 mStateAnimation.cancel();
3412 mStateAnimation = null;
3413 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003414
3415 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003416 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003417
Winson Chungf0ea4d32011-06-06 14:27:16 -07003418 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003419 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003420 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003421 final int itemsAlphaStagger =
3422 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003423
Winson Chungf0ea4d32011-06-06 14:27:16 -07003424 final float scaleFactor = (float)
3425 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3426 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003427 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003428 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003429 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003430 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen63f1ec02014-08-12 09:23:13 -07003431 toState, animated);
Adam Cohened307df2013-10-02 09:37:31 -07003432 } else if (toState == Workspace.State.SPRING_LOADED ||
3433 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003434 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003435 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003436 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003437
Winson Chung4afe9b32011-07-27 17:46:20 -07003438 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003439 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003440 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003441
Adam Cohen9bfdb762014-07-21 17:44:06 -07003442 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3443 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003444
Adam Cohen9bfdb762014-07-21 17:44:06 -07003445 final View page = content.getPageAt(content.getNextPage());
3446 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003447
Adam Cohen4e243a22014-08-10 18:30:55 -07003448 AppsCustomizePagedView.ContentType contentType = content.getContentType();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003449 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3450
3451 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003452 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3453 } else {
3454 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3455 }
3456
Adam Cohen9bfdb762014-07-21 17:44:06 -07003457 int width = revealView.getMeasuredWidth();
3458 int height = revealView.getMeasuredHeight();
3459 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003460
Adam Cohen9bfdb762014-07-21 17:44:06 -07003461 // Hide the real page background, and swap in the fake one
3462 revealView.setVisibility(View.VISIBLE);
3463 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003464
Adam Cohen63f1ec02014-08-12 09:23:13 -07003465 final View allAppsButton = getAllAppsButton();
3466 revealView.setTranslationY(0);
3467 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3468 allAppsButton, null);
3469 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen6c5891a2014-07-09 23:53:15 -07003470
Adam Cohen9bfdb762014-07-21 17:44:06 -07003471 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003472
Adam Cohen63f1ec02014-08-12 09:23:13 -07003473 // The vertical motion of the apps panel should be delayed by one frame
3474 // from the conceal animation in order to give the right feel. We correpsondingly
3475 // shorten the duration so that the slide and conceal end at the same time.
3476 ObjectAnimator panelDrift = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
3477 panelDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3478 panelDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3479 panelDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3480 mStateAnimation.play(panelDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003481
Adam Cohen63f1ec02014-08-12 09:23:13 -07003482 if (isWidgetTray) {
3483 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f);
3484 panelAlpha.setDuration(revealDuration);
3485 panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3486 mStateAnimation.play(panelAlpha);
3487 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003488
Adam Cohen4e243a22014-08-10 18:30:55 -07003489 if (page != null) {
3490 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003491
Adam Cohen63f1ec02014-08-12 09:23:13 -07003492 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3493 0, yDrift);
3494 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003495 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003496 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003497 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003498
Adam Cohen4e243a22014-08-10 18:30:55 -07003499 page.setAlpha(1f);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003500 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3501 itemsAlpha.setDuration(100);
Adam Cohen4e243a22014-08-10 18:30:55 -07003502 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3503 mStateAnimation.play(itemsAlpha);
3504 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003505
Adam Cohen9bfdb762014-07-21 17:44:06 -07003506 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003507 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003508 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003509 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003510 indicatorsAlpha.setDuration(revealDuration);
3511 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3512 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003513
Adam Cohen9bfdb762014-07-21 17:44:06 -07003514 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003515
Adam Cohen9bfdb762014-07-21 17:44:06 -07003516 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003517 if (!isWidgetTray) {
3518 allAppsButton.setVisibility(View.INVISIBLE);
3519 }
3520 int allAppsButtonSize = LauncherAppState.getInstance().
3521 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3522 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003523 Animator reveal =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003524 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3525 height / 2, revealRadius, finalRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003526 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3527 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003528 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003529
3530 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003531 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003532 revealView.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003533 if (!isWidgetTray) {
3534 allAppsButton.setVisibility(View.VISIBLE);
3535 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003536 }
3537 });
3538
Adam Cohen6c5891a2014-07-09 23:53:15 -07003539 mStateAnimation.play(reveal);
3540 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003541
3542 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3543 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3544 mAppsCustomizeContent.stopScrolling();
3545
Adam Cohen6c5891a2014-07-09 23:53:15 -07003546 if (workspaceAnim != null) {
3547 mStateAnimation.play(workspaceAnim);
3548 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003549
3550 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003551 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003552 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003553 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003554 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3555 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003556 if (onCompleteRunnable != null) {
3557 onCompleteRunnable.run();
3558 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003559
3560 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003561 if (page != null) {
3562 page.setLayerType(View.LAYER_TYPE_NONE, null);
3563 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003564 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003565 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003566 }
3567 });
3568
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003569 dispatchOnLauncherTransitionStart(fromView, animated, true);
3570 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003571 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003572 } else {
3573 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003574 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003575 dispatchOnLauncherTransitionStart(fromView, animated, true);
3576 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003577 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003578 dispatchOnLauncherTransitionStart(toView, animated, true);
3579 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003580 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003581 }
3582
Michael Jurkae326f182011-11-21 14:05:46 -08003583 @Override
3584 public void onTrimMemory(int level) {
3585 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003586 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003587 mAppsCustomizeTabHost.onTrimMemory();
3588 }
3589 }
3590
Adam Cohened307df2013-10-02 09:37:31 -07003591 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003592 showWorkspace(animated, null);
3593 }
3594
Adam Cohened307df2013-10-02 09:37:31 -07003595 protected void showWorkspace() {
3596 showWorkspace(true);
3597 }
3598
Adam Cohened66b2b2012-01-23 17:28:51 -08003599 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003600 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003601 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003602 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003603 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003604
Winson Chungc7d2b602012-05-16 17:02:20 -07003605 // Show the search bar (only animate if we were showing the drop target bar in spring
3606 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003607 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003608 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003609 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003610
Michael Jurkab3e22d92011-10-31 15:58:33 -07003611 // Set focus to the AppsCustomize button
3612 if (mAllAppsButton != null) {
3613 mAllAppsButton.requestFocus();
3614 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003615 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003616
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003617 // Change the state *after* we've called all the transition code
3618 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003619
Winson Chung5fb63472011-02-02 17:03:37 -08003620 // Resume the auto-advance of widgets
3621 mUserPresent = true;
3622 updateRunning();
3623
alanv1d4fde62012-10-17 13:15:47 -07003624 // Send an accessibility event to announce the context change
3625 getWindow().getDecorView()
3626 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003627
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003628 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003629 }
3630
Adam Cohened307df2013-10-02 09:37:31 -07003631 void showOverviewMode(boolean animated) {
3632 mWorkspace.setVisibility(View.VISIBLE);
3633 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3634 mState = State.WORKSPACE;
3635 onWorkspaceShown(animated);
3636 }
3637
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003638 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003639 }
3640
Winson Chung82963d52013-10-09 11:20:57 -07003641 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3642 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003643 if (mState != State.WORKSPACE) return;
3644
Winson Chung82963d52013-10-09 11:20:57 -07003645 if (resetPageToZero) {
3646 mAppsCustomizeTabHost.reset();
3647 }
Winson Chungc58497e2013-09-03 17:48:37 -07003648 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003649 mAppsCustomizeTabHost.post(new Runnable() {
3650 @Override
3651 public void run() {
3652 // We post this in-case the all apps view isn't yet constructed.
3653 mAppsCustomizeTabHost.requestFocus();
3654 }
3655 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003656
Michael Jurkab3e22d92011-10-31 15:58:33 -07003657 // Change the state *after* we've called all the transition code
3658 mState = State.APPS_CUSTOMIZE;
3659
3660 // Pause the auto-advance of widgets until we are out of AllApps
3661 mUserPresent = false;
3662 updateRunning();
3663 closeFolder();
3664
3665 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003666 getWindow().getDecorView()
3667 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003668 }
3669
Adam Cohen7777d962011-08-18 18:58:38 -07003670 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003671 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003672 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003673 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003674 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003675 }
Adam Cohen7777d962011-08-18 18:58:38 -07003676
Adam Cohenad4e15c2013-10-17 16:21:35 -07003677 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003678 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003679 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3680
Winson Chunge7a03942011-08-05 15:05:12 -07003681 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003682 @Override
3683 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003684 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003685 // Before we show workspace, hide all apps again because
3686 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3687 // clean up our state transition functions
3688 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003689 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003690 } else {
3691 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003692 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003693 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003694 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003695 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003696
Michael Jurkad3ef3062010-11-23 16:23:58 -08003697 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003698 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003699 final boolean animated = true;
3700 final boolean springLoaded = true;
3701 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003702 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003703 }
3704 // Otherwise, we are not in spring loaded mode, so don't do anything.
3705 }
3706
Michael Jurkab3e22d92011-10-31 15:58:33 -07003707 void lockAllApps() {
3708 // TODO
3709 }
3710
3711 void unlockAllApps() {
3712 // TODO
3713 }
3714
Winson Chungf0ea4d32011-06-06 14:27:16 -07003715 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003716 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003717 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003718 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003719 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003720 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003721 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003722 int duration = 0;
3723 if (mSearchDropTargetBar != null) {
3724 duration = mSearchDropTargetBar.getTransitionInDuration();
3725 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003726 mHotseat.animate().alpha(1f).setDuration(duration);
3727 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003728 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003729 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003730 }
3731 }
3732 }
3733
3734 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003735 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003736 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003737 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003738 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003739 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003740 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003741 int duration = 0;
3742 if (mSearchDropTargetBar != null) {
3743 duration = mSearchDropTargetBar.getTransitionOutDuration();
3744 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003745 mHotseat.animate().alpha(0f).setDuration(duration);
3746 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003747 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003748 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003749 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003750 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003751 }
3752
Patrick Dubroy5f445422011-02-18 14:35:21 -08003753 /**
3754 * Add an item from all apps or customize onto the given workspace screen.
3755 * If layout is null, add to the current screen.
3756 */
3757 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003758 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003759 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003760 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003761 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003762
Winson Chungdff8ebb2011-09-08 17:25:31 -07003763 /** Maps the current orientation to an index for referencing orientation correct global icons */
3764 private int getCurrentOrientationIndexForGlobalIcons() {
3765 // default - 0, landscape - 1
3766 switch (getResources().getConfiguration().orientation) {
3767 case Configuration.ORIENTATION_LANDSCAPE:
3768 return 1;
3769 default:
3770 return 0;
3771 }
3772 }
3773
Michael Jurkaae65ee32012-04-30 11:45:54 -07003774 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003775 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003776 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003777 // Look for the toolbar icon specified in the activity meta-data
3778 Bundle metaData = packageManager.getActivityInfo(
3779 activityName, PackageManager.GET_META_DATA).metaData;
3780 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003781 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003782 if (iconResId != 0) {
3783 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003784 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003785 }
3786 }
3787 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003788 // This can happen if the activity defines an invalid drawable
3789 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3790 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003791 } catch (Resources.NotFoundException nfe) {
3792 // This can happen if the activity defines an invalid drawable
3793 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3794 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003795 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003796 return null;
3797 }
3798
3799 // if successful in getting icon, return it; otherwise, set button to use default drawable
3800 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003801 int buttonId, ComponentName activityName, int fallbackDrawableId,
3802 String toolbarResourceName) {
3803 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003804 Resources r = getResources();
3805 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3806 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003807
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003808 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003809 // If we were unable to find the icon via the meta-data, use a generic one
3810 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003811 toolbarIcon = r.getDrawable(fallbackDrawableId);
3812 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003813 if (button != null) {
3814 button.setCompoundDrawables(toolbarIcon, null, null, null);
3815 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003816 return null;
3817 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003818 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003819 if (button != null) {
3820 button.setCompoundDrawables(toolbarIcon, null, null, null);
3821 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003822 return toolbarIcon.getConstantState();
3823 }
3824 }
3825
3826 // if successful in getting icon, return it; otherwise, set button to use default drawable
3827 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003828 int buttonId, ComponentName activityName, int fallbackDrawableId,
3829 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003830 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003831 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003832
Michael Jurka19e0fc52011-07-22 18:00:21 -07003833 if (button != null) {
3834 // If we were unable to find the icon via the meta-data, use a
3835 // generic one
3836 if (toolbarIcon == null) {
3837 button.setImageResource(fallbackDrawableId);
3838 } else {
3839 button.setImageDrawable(toolbarIcon);
3840 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003841 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003842
3843 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3844
Michael Jurka0423dcf2010-10-05 14:56:18 -07003845 }
3846
Winson Chung1b884092012-06-08 17:13:02 -07003847 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003848 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003849 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003850 }
3851
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003852 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003853 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003854 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003855 }
3856
Winson Chungbb185bd2011-11-21 12:31:42 -08003857 private void invalidatePressedFocusedStates(View container, View button) {
3858 if (container instanceof HolographicLinearLayout) {
3859 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3860 layout.invalidatePressedFocusedStates();
3861 } else if (button instanceof HolographicImageView) {
3862 HolographicImageView view = (HolographicImageView) button;
3863 view.invalidatePressedFocusedStates();
3864 }
3865 }
3866
Cristina Stancu476493b2013-08-07 17:20:14 +01003867 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003868 if (mQsb == null) {
3869 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3870 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003871 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003872 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003873 }
3874
3875 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003876 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003877 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003878 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003879 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003880
Winson Chung1cad91e2011-05-25 17:41:01 -07003881 final SearchManager searchManager =
3882 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3883 ComponentName activityName = searchManager.getGlobalSearchActivity();
3884 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003885 int coi = getCurrentOrientationIndexForGlobalIcons();
3886 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003887 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3888 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3889 if (sGlobalSearchIcon[coi] == null) {
3890 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3891 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3892 TOOLBAR_ICON_METADATA_NAME);
3893 }
3894
Winson Chungc51db6a2011-10-05 11:44:49 -07003895 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3896 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003897 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003898 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003899 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003900 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003901 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3902 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003903 if (searchButton != null) searchButton.setVisibility(View.GONE);
3904 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003905 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003906 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003907 }
3908 }
3909
Cristina Stancu476493b2013-08-07 17:20:14 +01003910 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003911 final View searchButtonContainer = findViewById(R.id.search_button_container);
3912 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003913 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003914 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003915 }
3916
Cristina Stancu476493b2013-08-07 17:20:14 +01003917 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003918 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003919 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003920
Winson Chungc51db6a2011-10-05 11:44:49 -07003921 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003922 final SearchManager searchManager =
3923 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3924 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3925
3926 ComponentName activityName = null;
3927 if (globalSearchActivity != null) {
3928 // Check if the global search activity handles voice search
3929 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3930 intent.setPackage(globalSearchActivity.getPackageName());
3931 activityName = intent.resolveActivity(getPackageManager());
3932 }
3933
3934 if (activityName == null) {
3935 // Fallback: check if an activity other than the global search activity
3936 // resolves this
3937 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3938 activityName = intent.resolveActivity(getPackageManager());
3939 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003940 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003941 int coi = getCurrentOrientationIndexForGlobalIcons();
3942 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003943 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3944 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3945 if (sVoiceSearchIcon[coi] == null) {
3946 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3947 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3948 TOOLBAR_ICON_METADATA_NAME);
3949 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003950 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003951 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003952 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003953 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003954 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003955 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003956 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003957 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003958 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003959 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003960 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003961 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003962
Cristina Stancu476493b2013-08-07 17:20:14 +01003963 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003964 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3965 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003966 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003967 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003968 }
3969
Winson Chung5841efa2013-09-30 18:06:44 -07003970 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003971 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3972 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003973 boolean visible = !forceDisableVoiceButtonProxy &&
3974 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003975 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003976 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003977 }
3978 }
Winson Chung5841efa2013-09-30 18:06:44 -07003979
3980 /**
3981 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3982 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3983 */
3984 public void disableVoiceButtonProxy(boolean disabled) {
3985 updateVoiceButtonProxyVisible(disabled);
3986 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003987
Michael Jurkad7c28052012-04-27 15:43:36 -07003988 @Override
3989 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003990 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003991 final List<CharSequence> text = event.getText();
3992 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003993 // Populate event with a fake title based on the current state.
3994 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003995 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07003996 } else {
3997 text.add(getString(R.string.all_apps_home_button_label));
3998 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003999 return result;
4000 }
4001
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004002 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004003 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004004 */
4005 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4006 @Override
4007 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004008 closeSystemDialogs();
4009 }
4010 }
4011
4012 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004013 * Receives notifications whenever the appwidgets are reset.
4014 */
4015 private class AppWidgetResetObserver extends ContentObserver {
4016 public AppWidgetResetObserver() {
4017 super(new Handler());
4018 }
4019
4020 @Override
4021 public void onChange(boolean selfChange) {
4022 onAppWidgetReset();
4023 }
4024 }
4025
4026 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004027 * If the activity is currently paused, signal that we need to run the passed Runnable
4028 * in onResume.
4029 *
4030 * This needs to be called from incoming places where resources might have been loaded
4031 * while we are paused. That is becaues the Configuration might be wrong
4032 * when we're not running, and if it comes back to what it was when we
4033 * were paused, we are not restarted.
4034 *
4035 * Implementation of the method from LauncherModel.Callbacks.
4036 *
4037 * @return true if we are currently paused. The caller might be able to
4038 * skip some work in that case since we will come back again.
4039 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004040 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004041 if (mPaused) {
4042 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004043 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004044 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004045 }
4046 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004047 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004048 return true;
4049 } else {
4050 return false;
4051 }
4052 }
4053
Michael Jurkac402cd92013-05-20 15:49:32 +02004054 private boolean waitUntilResume(Runnable run) {
4055 return waitUntilResume(run, false);
4056 }
4057
Michael Jurka1e2f4652013-07-08 18:03:46 -07004058 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004059 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004060 }
4061
Michael Jurka7607c2f2013-04-03 14:33:19 -07004062 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004063 * If the activity is currently paused, signal that we need to re-run the loader
4064 * in onResume.
4065 *
4066 * This needs to be called from incoming places where resources might have been loaded
4067 * while we are paused. That is becaues the Configuration might be wrong
4068 * when we're not running, and if it comes back to what it was when we
4069 * were paused, we are not restarted.
4070 *
4071 * Implementation of the method from LauncherModel.Callbacks.
4072 *
4073 * @return true if we are currently paused. The caller might be able to
4074 * skip some work in that case since we will come back again.
4075 */
4076 public boolean setLoadOnResume() {
4077 if (mPaused) {
4078 Log.i(TAG, "setLoadOnResume");
4079 mOnResumeNeedsLoad = true;
4080 return true;
4081 } else {
4082 return false;
4083 }
4084 }
4085
4086 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004087 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004088 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004089 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004090 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004091 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004092 } else {
4093 return SCREEN_COUNT / 2;
4094 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004095 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004096
Joe Onorato9c1289c2009-08-17 11:03:03 -04004097 /**
4098 * Refreshes the shortcuts shown on the workspace.
4099 *
4100 * Implementation of the method from LauncherModel.Callbacks.
4101 */
4102 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004103 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004104
Michael Jurka7607c2f2013-04-03 14:33:19 -07004105 // If we're starting binding all over again, clear any bind calls we'd postponed in
4106 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4107 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004108 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004109
Winson Chungd64d1762013-08-20 14:37:16 -07004110 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004111 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004112 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004113
Michael Jurka05bf6442011-11-30 20:28:53 -08004114 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004115 if (mHotseat != null) {
4116 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004117 }
4118 }
4119
Adam Cohendcd297f2013-06-18 13:13:40 -07004120 @Override
4121 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004122 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004123
Adam Cohen5084cba2013-09-03 12:01:16 -07004124 // If there are no screens, we need to have an empty screen
4125 if (orderedScreenIds.size() == 0) {
4126 mWorkspace.addExtraEmptyScreen();
4127 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004128
4129 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004130 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004131 if (hasCustomContentToLeft()) {
4132 mWorkspace.createCustomContentContainer();
4133 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004134 }
Winson Chung64359a52013-07-08 17:17:08 -07004135 }
4136
4137 @Override
4138 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004139 // Log to disk
4140 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4141 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4142 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004143 int count = orderedScreenIds.size();
4144 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004145 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004146 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004147 }
4148
Adam Cohen39a06042013-07-19 14:30:12 -07004149 private boolean shouldShowWeightWatcher() {
4150 String spKey = LauncherAppState.getSharedPreferencesKey();
4151 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004152 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004153
4154 return show;
4155 }
4156
4157 private void toggleShowWeightWatcher() {
4158 String spKey = LauncherAppState.getSharedPreferencesKey();
4159 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4160 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4161
4162 show = !show;
4163
4164 SharedPreferences.Editor editor = sp.edit();
4165 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4166 editor.commit();
4167
4168 if (mWeightWatcher != null) {
4169 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4170 }
4171 }
4172
Winson Chungd64d1762013-08-20 14:37:16 -07004173 public void bindAppsAdded(final ArrayList<Long> newScreens,
4174 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004175 final ArrayList<ItemInfo> addAnimated,
4176 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004177 Runnable r = new Runnable() {
4178 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004179 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004180 }
4181 };
4182 if (waitUntilResume(r)) {
4183 return;
4184 }
4185
Winson Chungd64d1762013-08-20 14:37:16 -07004186 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004187 if (newScreens != null) {
4188 bindAddScreens(newScreens);
4189 }
Winson Chungd64d1762013-08-20 14:37:16 -07004190
4191 // We add the items without animation on non-visible pages, and with
4192 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004193 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004194 bindItems(addNotAnimated, 0,
4195 addNotAnimated.size(), false);
4196 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004197 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004198 bindItems(addAnimated, 0,
4199 addAnimated.size(), true);
4200 }
Winson Chungc58497e2013-09-03 17:48:37 -07004201
Winson Chung87412982013-10-03 18:34:14 -07004202 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004203 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004204
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004205 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004206 addedApps != null && mAppsCustomizeContent != null) {
4207 mAppsCustomizeContent.addApps(addedApps);
4208 }
Winson Chungd64d1762013-08-20 14:37:16 -07004209 }
4210
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004211 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004212 * Bind the items start-end from the list.
4213 *
4214 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004215 */
Winson Chung64359a52013-07-08 17:17:08 -07004216 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4217 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004218 Runnable r = new Runnable() {
4219 public void run() {
4220 bindItems(shortcuts, start, end, forceAnimateIcons);
4221 }
4222 };
4223 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004224 return;
4225 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004226
Winson Chungf0c6ae02012-03-21 16:10:31 -07004227 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004228 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4229 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004230 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004231 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004232 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004233 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004234 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004235
4236 // Short circuit if we are loading dock items for a configuration which has no dock
4237 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4238 mHotseat == null) {
4239 continue;
4240 }
4241
Joe Onorato9c1289c2009-08-17 11:03:03 -04004242 switch (item.itemType) {
4243 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4244 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004245 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004246 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004247
Winson Chung64359a52013-07-08 17:17:08 -07004248 /*
4249 * TODO: FIX collision case
4250 */
Winson Chungce376632013-07-11 16:12:41 -07004251 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4252 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4253 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004254 View v = cl.getChildAt(item.cellX, item.cellY);
4255 Object tag = v.getTag();
4256 String desc = "Collision while binding workspace item: " + item
4257 + ". Collides with " + tag;
4258 if (LauncherAppState.isDogfoodBuild()) {
4259 throw (new RuntimeException(desc));
4260 } else {
4261 Log.d(TAG, desc);
4262 }
Winson Chungce376632013-07-11 16:12:41 -07004263 }
Winson Chung64359a52013-07-08 17:17:08 -07004264 }
4265
Adam Cohendcd297f2013-06-18 13:13:40 -07004266 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4267 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004268 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004269 // Animate all the applications up now
4270 shortcut.setAlpha(0f);
4271 shortcut.setScaleX(0f);
4272 shortcut.setScaleY(0f);
4273 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004274 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004275 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004276 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004277 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004278 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004279 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004280 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004281 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4282 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004283 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004284 default:
4285 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004286 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004287 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004288
Winson Chung997a9232013-07-24 15:33:46 -07004289 if (animateIcons) {
4290 // Animate to the correct page
4291 if (newShortcutsScreenId > -1) {
4292 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004293 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004294 final Runnable startBounceAnimRunnable = new Runnable() {
4295 public void run() {
4296 anim.playTogether(bounceAnims);
4297 anim.start();
4298 }
4299 };
Winson Chung997a9232013-07-24 15:33:46 -07004300 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004301 // We post the animation slightly delayed to prevent slowdowns
4302 // when we are loading right after we return to launcher.
4303 mWorkspace.postDelayed(new Runnable() {
4304 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004305 if (mWorkspace != null) {
4306 mWorkspace.snapToPage(newScreenIndex);
4307 mWorkspace.postDelayed(startBounceAnimRunnable,
4308 NEW_APPS_ANIMATION_DELAY);
4309 }
Winson Chung94d67682013-09-25 16:29:40 -07004310 }
4311 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004312 } else {
4313 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004314 }
4315 }
Winson Chung64359a52013-07-08 17:17:08 -07004316 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004317 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004318 }
4319
Joe Onorato9c1289c2009-08-17 11:03:03 -04004320 /**
4321 * Implementation of the method from LauncherModel.Callbacks.
4322 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004323 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004324 Runnable r = new Runnable() {
4325 public void run() {
4326 bindFolders(folders);
4327 }
4328 };
4329 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004330 return;
4331 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004332 sFolders.clear();
4333 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004334 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004335
4336 /**
4337 * Add the views for a widget to the workspace.
4338 *
4339 * Implementation of the method from LauncherModel.Callbacks.
4340 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004341 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004342 Runnable r = new Runnable() {
4343 public void run() {
4344 bindAppWidget(item);
4345 }
4346 };
4347 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004348 return;
4349 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004350
Daniel Sandler843e8602010-06-07 14:59:01 -04004351 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4352 if (DEBUG_WIDGETS) {
4353 Log.d(TAG, "bindAppWidget: " + item);
4354 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004355 final Workspace workspace = mWorkspace;
4356
Sunny Goyalff572272014-07-23 13:58:07 -07004357 AppWidgetProviderInfo appWidgetInfo;
4358 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4359 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4360
4361 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4362 if (appWidgetInfo == null) {
4363 if (DEBUG_WIDGETS) {
4364 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4365 + " belongs to component " + item.providerName
4366 + ", as the povider is null");
4367 }
4368 LauncherModel.deleteItemFromDatabase(this, item);
4369 return;
4370 }
4371 // Note: This assumes that the id remap broadcast is received before this step.
4372 // If that is not the case, the id remap will be ignored and user may see the
4373 // click to setup view.
4374 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4375 pendingInfo.spanX = item.spanX;
4376 pendingInfo.spanY = item.spanY;
4377 pendingInfo.minSpanX = item.minSpanX;
4378 pendingInfo.minSpanY = item.minSpanY;
4379 Bundle options =
4380 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4381
4382 boolean success = false;
4383 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4384 if (options != null) {
4385 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4386 appWidgetInfo.provider, options);
4387 } else {
4388 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4389 appWidgetInfo.provider);
4390 }
4391
4392 // TODO consider showing a permission dialog when the widget is clicked.
4393 if (!success) {
4394 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4395 if (DEBUG_WIDGETS) {
4396 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4397 + " belongs to component " + item.providerName
4398 + ", as the launcher is unable to bing a new widget id");
4399 }
4400 LauncherModel.deleteItemFromDatabase(this, item);
4401 return;
4402 }
4403
4404 item.appWidgetId = newWidgetId;
4405
4406 // If the widget has a configure activity, it is still needs to set it up, otherwise
4407 // the widget is ready to go.
4408 item.restoreStatus = (appWidgetInfo.configure == null)
4409 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4410 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4411
4412 LauncherModel.updateItemInDatabase(this, item);
4413 }
4414
Sunny Goyal651077b2014-06-30 14:15:31 -07004415 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4416 final int appWidgetId = item.appWidgetId;
4417 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4418 if (DEBUG_WIDGETS) {
4419 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4420 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004421
Sunny Goyal651077b2014-06-30 14:15:31 -07004422 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4423 } else {
4424 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004425 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4426 view.updateIcon(mIconCache);
4427 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004428 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004429 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004430 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004431
Joe Onorato9c1289c2009-08-17 11:03:03 -04004432 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004433 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004434
Adam Cohendcd297f2013-06-18 13:13:40 -07004435 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004436 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004437 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4438
Joe Onorato9c1289c2009-08-17 11:03:03 -04004439 workspace.requestLayout();
4440
Daniel Sandler843e8602010-06-07 14:59:01 -04004441 if (DEBUG_WIDGETS) {
4442 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4443 + (SystemClock.uptimeMillis()-start) + "ms");
4444 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004445 }
4446
Sunny Goyalff572272014-07-23 13:58:07 -07004447 /**
4448 * Restores a pending widget.
4449 *
4450 * @param appWidgetId The app widget id
4451 * @param cellInfo The position on screen where to create the widget.
4452 */
4453 private void completeRestoreAppWidget(final int appWidgetId) {
4454 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4455 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4456 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4457 return;
4458 }
4459
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004460 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004461 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4462
4463 mWorkspace.reinflateWidgetsIfNecessary();
4464 LauncherModel.updateItemInDatabase(this, info);
4465 }
4466
Adam Cohen1462de32012-07-24 22:34:36 -07004467 public void onPageBoundSynchronously(int page) {
4468 mSynchronouslyBoundPages.add(page);
4469 }
4470
Joe Onorato9c1289c2009-08-17 11:03:03 -04004471 /**
4472 * Callback saying that there aren't any more items to bind.
4473 *
4474 * Implementation of the method from LauncherModel.Callbacks.
4475 */
Adam Cohene25af792013-06-06 23:08:25 -07004476 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004477 Runnable r = new Runnable() {
4478 public void run() {
4479 finishBindingItems(upgradePath);
4480 }
4481 };
4482 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004483 return;
4484 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004485 if (mSavedState != null) {
4486 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004487 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004488 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004489 mSavedState = null;
4490 }
4491
Adam Cohen1462de32012-07-24 22:34:36 -07004492 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004493
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004494 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004495 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004496
4497 // If we received the result of any pending adds while the loader was running (e.g. the
4498 // widget configuration forced an orientation change), process them now.
4499 if (sPendingAddItem != null) {
4500 final long screenId = completeAdd(sPendingAddItem);
4501
4502 // TODO: this moves the user to the page where the pending item was added. Ideally,
4503 // the screen would be guaranteed to exist after bind, and the page would be set through
4504 // the workspace restore process.
4505 mWorkspace.post(new Runnable() {
4506 @Override
4507 public void run() {
4508 mWorkspace.snapToScreenId(screenId);
4509 }
4510 });
4511 sPendingAddItem = null;
4512 }
4513
Adam Cohene25af792013-06-06 23:08:25 -07004514 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004515 mWorkspace.getUniqueComponents(true, null);
4516 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004517 }
Sunny Goyale755d462014-07-22 13:48:29 -07004518 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004519 }
4520
Adam Cohen3ed316a2014-07-23 18:21:20 -07004521 private void sendLoadingCompleteBroadcastIfNecessary() {
4522 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4523 String permission =
4524 getResources().getString(R.string.receive_first_load_broadcast_permission);
4525 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4526 sendBroadcast(intent, permission);
4527 SharedPreferences.Editor editor = mSharedPrefs.edit();
4528 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4529 editor.apply();
4530 }
4531 }
4532
Winson Chunga0b7e862013-09-05 16:03:15 -07004533 public boolean isAllAppsButtonRank(int rank) {
4534 if (mHotseat != null) {
4535 return mHotseat.isAllAppsButtonRank(rank);
4536 }
4537 return false;
4538 }
4539
Winson Chunga2413752012-04-03 14:22:34 -07004540 private boolean canRunNewAppsAnimation() {
4541 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4542 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4543 }
4544
Winson Chungc9168342013-06-26 14:54:55 -07004545 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4546 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4547 PropertyValuesHolder.ofFloat("alpha", 1f),
4548 PropertyValuesHolder.ofFloat("scaleX", 1f),
4549 PropertyValuesHolder.ofFloat("scaleY", 1f));
4550 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4551 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4552 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4553 return bounceAnim;
4554 }
4555
Adam Cohen27772732013-11-11 14:00:56 +00004556 public boolean useVerticalBarLayout() {
4557 return LauncherAppState.getInstance().getDynamicGrid().
4558 getDeviceProfile().isVerticalBarLayout();
4559 }
4560
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004561 protected Rect getSearchBarBounds() {
4562 return LauncherAppState.getInstance().getDynamicGrid().
4563 getDeviceProfile().getSearchBarBounds();
4564 }
4565
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004566 @Override
4567 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004568 boolean searchVisible = updateGlobalSearchIcon();
4569 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004570 if (mSearchDropTargetBar != null) {
4571 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4572 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004573 }
4574
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004575 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004576 * Add the icons for all apps.
4577 *
4578 * Implementation of the method from LauncherModel.Callbacks.
4579 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004580 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004581 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004582 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4583 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4584 getHotseat().addAllAppsFolder(mIconCache, apps,
4585 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4586 }
4587 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004588 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004589 if (mAppsCustomizeContent != null) {
4590 mAppsCustomizeContent.onPackagesUpdated(
4591 LauncherModel.getSortedWidgetsAndShortcuts(this));
4592 }
Winson Chungc58497e2013-09-03 17:48:37 -07004593 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004594 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004595 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004596 mAppsCustomizeContent.onPackagesUpdated(
4597 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004598 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004599 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004600 }
4601
4602 /**
4603 * A package was updated.
4604 *
4605 * Implementation of the method from LauncherModel.Callbacks.
4606 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004607 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004608 Runnable r = new Runnable() {
4609 public void run() {
4610 bindAppsUpdated(apps);
4611 }
4612 };
4613 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004614 return;
4615 }
4616
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004617 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004618 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004619 }
Winson Chungc58497e2013-09-03 17:48:37 -07004620
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004621 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004622 mAppsCustomizeContent != null) {
4623 mAppsCustomizeContent.updateApps(apps);
4624 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004625 }
4626
4627 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004628 * Update the state of a package, typically related to install state.
4629 *
4630 * Implementation of the method from LauncherModel.Callbacks.
4631 */
Sunny Goyale755d462014-07-22 13:48:29 -07004632 @Override
4633 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004634 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004635 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004636 }
4637 }
4638
4639 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004640 * A package was uninstalled. We take both the super set of packageNames
4641 * in addition to specific applications to remove, the reason being that
4642 * this can be called when a package is updated as well. In that scenario,
4643 * we only remove specific components from the workspace, where as
4644 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004645 *
4646 * Implementation of the method from LauncherModel.Callbacks.
4647 */
Winson Chung83892cc2013-05-01 16:53:33 -07004648 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004649 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004650 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004651 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004652 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004653 }
Winson Chungd64d1762013-08-20 14:37:16 -07004654 };
4655 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004656 return;
4657 }
4658
Winson Chungdf95eb12013-10-16 14:57:07 -07004659 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004660 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004661 }
4662 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004663 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004664 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004665
Winson Chunga1820962011-10-03 16:31:06 -07004666 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004667 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004668
Winson Chungdf95eb12013-10-16 14:57:07 -07004669 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004670 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004671 mAppsCustomizeContent != null) {
4672 mAppsCustomizeContent.removeApps(appInfos);
4673 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004674 }
Joe Onoratobe386092009-11-17 17:32:16 -08004675
4676 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004677 * A number of packages were updated.
4678 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004679 private ArrayList<Object> mWidgetsAndShortcuts;
4680 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004681 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004682 bindPackagesUpdated(mWidgetsAndShortcuts);
4683 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004684 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004685 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004686 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4687 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4688 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004689 return;
4690 }
4691
Winson Chung64359a52013-07-08 17:17:08 -07004692 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004693 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004694 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004695 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004696 }
4697
Winson Chung400438b2011-01-16 17:53:48 -08004698 private int mapConfigurationOriActivityInfoOri(int configOri) {
4699 final Display d = getWindowManager().getDefaultDisplay();
4700 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4701 switch (d.getRotation()) {
4702 case Surface.ROTATION_0:
4703 case Surface.ROTATION_180:
4704 // We are currently in the same basic orientation as the natural orientation
4705 naturalOri = configOri;
4706 break;
4707 case Surface.ROTATION_90:
4708 case Surface.ROTATION_270:
4709 // We are currently in the other basic orientation to the natural orientation
4710 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4711 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4712 break;
4713 }
4714
4715 int[] oriMap = {
4716 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4717 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4718 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4719 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4720 };
4721 // Since the map starts at portrait, we need to offset if this device's natural orientation
4722 // is landscape.
4723 int indexOffset = 0;
4724 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4725 indexOffset = 1;
4726 }
4727 return oriMap[(d.getRotation() + indexOffset) % 4];
4728 }
Adam Cohen446e9402011-09-15 18:21:21 -07004729
Winson Chung4b919f82012-05-01 10:44:08 -07004730 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004731 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004732 getResources().getBoolean(R.bool.allow_rotation);
4733 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004734 }
Winson Chung4b919f82012-05-01 10:44:08 -07004735 public void lockScreenOrientation() {
4736 if (isRotationEnabled()) {
4737 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4738 .getConfiguration().orientation));
4739 }
4740 }
4741 public void unlockScreenOrientation(boolean immediate) {
4742 if (isRotationEnabled()) {
4743 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004744 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004745 } else {
4746 mHandler.postDelayed(new Runnable() {
4747 public void run() {
4748 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4749 }
4750 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004751 }
Winson Chung4b919f82012-05-01 10:44:08 -07004752 }
Winson Chung400438b2011-01-16 17:53:48 -08004753 }
4754
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004755 /**
4756 * Called when the SearchBar hint should be changed.
4757 *
4758 * @param hint the hint to be displayed in the search bar.
4759 */
4760 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004761 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004762 }
4763
Winson Chunge43a1e72014-01-15 10:33:02 -08004764 protected boolean isLauncherPreinstalled() {
4765 PackageManager pm = getPackageManager();
4766 try {
4767 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4768 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4769 return true;
4770 } else {
4771 return false;
4772 }
4773 } catch (NameNotFoundException e) {
4774 e.printStackTrace();
4775 return false;
4776 }
4777 }
4778
Adam Cohenea90f832014-05-21 15:03:34 -07004779 /**
4780 * This method indicates whether or not we should suggest default wallpaper dimensions
4781 * when our wallpaper cropper was not yet used to set a wallpaper.
4782 */
4783 protected boolean overrideWallpaperDimensions() {
4784 return true;
4785 }
4786
Adam Cohen5eed5d82014-05-19 13:12:13 -07004787 protected boolean shouldClingFocusHotseatApp() {
4788 return false;
4789 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004790 protected String getFirstRunClingSearchBarHint() {
4791 return "";
4792 }
4793 protected String getFirstRunCustomContentHint() {
4794 return "";
4795 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004796 protected int getFirstRunFocusedHotseatAppDrawableId() {
4797 return -1;
4798 }
4799 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4800 return null;
4801 }
4802 protected int getFirstRunFocusedHotseatAppRank() {
4803 return -1;
4804 }
4805 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4806 return "";
4807 }
4808 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4809 return "";
4810 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004811
Winson Chungaf40f202013-09-18 18:26:31 -07004812 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004813 mLauncherClings.dismissFirstRunCling(v);
4814 }
4815 public void dismissMigrationClingCopyApps(View v) {
4816 mLauncherClings.dismissMigrationClingCopyApps(v);
4817 }
4818 public void dismissMigrationClingUseDefault(View v) {
4819 mLauncherClings.dismissMigrationClingUseDefault(v);
4820 }
4821 public void dismissMigrationWorkspaceCling(View v) {
4822 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004823 }
Winson Chung82f55532011-08-09 14:14:23 -07004824 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004825 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004826 }
4827 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004828 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004829 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004830 public void markFolderClingDismissedIfNecessary() {
4831 mLauncherClings.markFolderClingDismissedIfNecessary();
4832 }
Adam Cohen432609a2014-03-13 17:03:22 -07004833
4834 /**
4835 * To be overridden by subclasses to indicate that there is an activity to launch
4836 * before showing the standard launcher experience.
4837 */
4838 protected boolean hasFirstRunActivity() {
4839 return false;
4840 }
4841
4842 /**
4843 * To be overridden by subclasses to launch any first run activity
4844 */
4845 protected Intent getFirstRunActivity() {
4846 return null;
4847 }
4848
Winson Chunga6945242014-01-08 14:04:34 -08004849 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004850 return !ActivityManager.isRunningInTestHarness() &&
4851 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004852 }
4853
Adam Cohen4a9423d2014-03-28 14:22:31 -07004854 protected boolean hasRunFirstRunActivity() {
4855 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4856 }
4857
Adam Cohen432609a2014-03-13 17:03:22 -07004858 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004859 if (shouldRunFirstRunActivity() &&
4860 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004861 Intent firstRunIntent = getFirstRunActivity();
4862 if (firstRunIntent != null) {
4863 startActivity(firstRunIntent);
4864 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004865 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004866 }
4867 }
Adam Cohen432609a2014-03-13 17:03:22 -07004868 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004869 }
4870
4871 private void markFirstRunActivityShown() {
4872 SharedPreferences.Editor editor = mSharedPrefs.edit();
4873 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4874 editor.apply();
4875 }
4876
Adam Cohen432609a2014-03-13 17:03:22 -07004877 /**
4878 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4879 * screen that must be displayed and dismissed.
4880 */
4881 protected boolean hasDismissableIntroScreen() {
4882 return false;
4883 }
4884
4885 /**
4886 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4887 */
4888 protected View getIntroScreen() {
4889 return null;
4890 }
4891
4892 /**
4893 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4894 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4895 */
4896 private boolean shouldShowIntroScreen() {
4897 return hasDismissableIntroScreen() &&
4898 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4899 }
4900
4901 protected void showIntroScreen() {
4902 View introScreen = getIntroScreen();
4903 changeWallpaperVisiblity(false);
4904 if (introScreen != null) {
4905 mDragLayer.showOverlayView(introScreen);
4906 }
4907 }
4908
4909 public void dismissIntroScreen() {
4910 markIntroScreenDismissed();
4911 if (showFirstRunActivity()) {
4912 // We delay hiding the intro view until the first run activity is showing. This
4913 // avoids a blip.
4914 mWorkspace.postDelayed(new Runnable() {
4915 @Override
4916 public void run() {
4917 mDragLayer.dismissOverlayView();
4918 }
4919 }, ACTIVITY_START_DELAY);
4920 } else {
4921 mDragLayer.dismissOverlayView();
4922 }
4923 changeWallpaperVisiblity(true);
4924 }
4925
4926 private void markIntroScreenDismissed() {
4927 SharedPreferences.Editor editor = mSharedPrefs.edit();
4928 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4929 editor.apply();
4930 }
4931
Winson Chunga6945242014-01-08 14:04:34 -08004932 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004933 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4934 if (mHotseat != null) mHotseat.setAlpha(1f);
4935 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4936 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004937 }
4938
4939 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004940 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4941 if (mHotseat != null) mHotseat.setAlpha(0f);
4942 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4943 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004944 }
4945
Mathew Inwood72fbec12013-11-19 15:45:07 +00004946 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004947 // Called from search suggestion, not supported in other profiles.
4948 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4949 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4950 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4951 myUser);
4952 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004953 return null;
4954 }
Kenny Guyed131872014-04-30 03:02:21 +01004955 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004956 }
4957
4958 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4959 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004960 // Called from search suggestion, not supported in other profiles.
4961 return createShortcutDragInfo(shortcutIntent, caption, icon,
4962 UserHandleCompat.myUserHandle());
4963 }
4964
4965 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4966 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004967 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004968 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004969 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004970 }
4971
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004972 protected void moveWorkspaceToDefaultScreen() {
4973 mWorkspace.moveToDefaultScreen(false);
4974 }
4975
Mathew Inwood72fbec12013-11-19 15:45:07 +00004976 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4977 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004978 mWorkspace.onExternalDragStartedWithItem(dragView);
4979 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004980 }
4981
Anjali Koppalf5d29132014-02-28 13:33:27 -08004982 @Override
4983 public void onPageSwitch(View newPage, int newPageIndex) {
4984 }
4985
Winson Chung80baf5a2010-08-09 16:03:15 -07004986 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004987 * Prints out out state for debugging.
4988 */
4989 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004990 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004991 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004992 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4993 Log.d(TAG, "mRestoring=" + mRestoring);
4994 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4995 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004996 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004997 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004998
Winson Chung785d2eb2011-04-14 16:08:02 -07004999 if (mAppsCustomizeContent != null) {
5000 mAppsCustomizeContent.dumpState();
5001 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005002 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005003 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005004
5005 @Override
5006 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5007 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005008 synchronized (sDumpLogs) {
5009 writer.println(" ");
5010 writer.println("Debug logs: ");
5011 for (int i = 0; i < sDumpLogs.size(); i++) {
5012 writer.println(" " + sDumpLogs.get(i));
5013 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005014 }
5015 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005016
5017 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005018 if (DEBUG_DUMP_LOG) {
5019 synchronized (sDumpLogs) {
5020 Log.d(TAG, "");
5021 Log.d(TAG, "*********************");
5022 Log.d(TAG, "Launcher debug logs: ");
5023 for (int i = 0; i < sDumpLogs.size(); i++) {
5024 Log.d(TAG, " " + sDumpLogs.get(i));
5025 }
5026 Log.d(TAG, "*********************");
5027 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005028 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005029 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005030 }
5031
5032 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005033 addDumpLog(tag, log, null, debugLog);
5034 }
5035
5036 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005037 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005038 if (e != null) {
5039 Log.d(tag, log, e);
5040 } else {
5041 Log.d(tag, log);
5042 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005043 }
Winson Chungede41292013-09-19 16:27:36 -07005044 if (DEBUG_DUMP_LOG) {
5045 sDateStamp.setTime(System.currentTimeMillis());
5046 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005047 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5048 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005049 }
Winson Chungede41292013-09-19 16:27:36 -07005050 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005051 }
5052
Winson Chungede41292013-09-19 16:27:36 -07005053 public void dumpLogsToLocalData() {
5054 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005055 new AsyncTask<Void, Void, Void>() {
5056 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005057 boolean success = false;
5058 sDateStamp.setTime(sRunStart);
5059 String FILENAME = sDateStamp.getMonth() + "-"
5060 + sDateStamp.getDay() + "_"
5061 + sDateStamp.getHours() + "-"
5062 + sDateStamp.getMinutes() + "_"
5063 + sDateStamp.getSeconds() + ".txt";
5064
5065 FileOutputStream fos = null;
5066 File outFile = null;
5067 try {
5068 outFile = new File(getFilesDir(), FILENAME);
5069 outFile.createNewFile();
5070 fos = new FileOutputStream(outFile);
5071 } catch (Exception e) {
5072 e.printStackTrace();
5073 }
5074 if (fos != null) {
5075 PrintWriter writer = new PrintWriter(fos);
5076
5077 writer.println(" ");
5078 writer.println("Debug logs: ");
5079 synchronized (sDumpLogs) {
5080 for (int i = 0; i < sDumpLogs.size(); i++) {
5081 writer.println(" " + sDumpLogs.get(i));
5082 }
5083 }
5084 writer.close();
5085 }
5086 try {
5087 if (fos != null) {
5088 fos.close();
5089 success = true;
5090 }
5091 } catch (IOException e) {
5092 e.printStackTrace();
5093 }
Michael Jurka43467462013-11-14 12:03:58 +01005094 return null;
Winson Chungede41292013-09-19 16:27:36 -07005095 }
Michael Jurka43467462013-11-14 12:03:58 +01005096 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005097 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005098 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005099}
Michael Jurka2763be32011-02-24 11:19:57 -08005100
Michael Jurkaabded662011-03-04 12:06:57 -08005101interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005102 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005103 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005104 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005105 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005106 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005107}
Dan Sandlerd5024042014-01-09 15:01:33 -05005108
5109interface DebugIntents {
5110 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5111 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005112}