blob: 88a60d08c7a2b5322677e38f4990c8af972676c4 [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
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700384 FocusIndicatorView mFocusHandler;
385
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800386 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800387 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700388 }
389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 @Override
391 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700392 if (DEBUG_STRICT_MODE) {
393 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
394 .detectDiskReads()
395 .detectDiskWrites()
396 .detectNetwork() // or .detectAll() for all detectable problems
397 .penaltyLog()
398 .build());
399 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
400 .detectLeakedSqlLiteObjects()
401 .detectLeakedClosableObjects()
402 .penaltyLog()
403 .penaltyDeath()
404 .build());
405 }
406
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400408
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400409 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400410 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700411 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700412 // Determine the dynamic grid properties
413 Point smallestSize = new Point();
414 Point largestSize = new Point();
415 Point realSize = new Point();
416 Display display = getWindowManager().getDefaultDisplay();
417 display.getCurrentSizeRange(smallestSize, largestSize);
418 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700419 DisplayMetrics dm = new DisplayMetrics();
420 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700421
Winson Chung5f8afe62013-08-12 16:19:28 -0700422 // Lazy-initialize the dynamic grid
423 DeviceProfile grid = app.initDynamicGrid(this,
424 Math.min(smallestSize.x, smallestSize.y),
425 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700426 realSize.x, realSize.y,
427 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700428
429 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400430 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700431 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700432 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800433 mModel = app.setLauncher(this);
434 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700435 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400436 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800437 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800438 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700439
Daniel Sandlerff02d492013-08-05 02:12:05 -0400440 mStats = new Stats(this);
441
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700442 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700443
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700444 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
445 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700446
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700447 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
448 // this also ensures that any synchronous binding below doesn't re-trigger another
449 // LauncherModel load.
450 mPaused = false;
451
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200453 android.os.Debug.startMethodTracing(
454 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456
457 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100461 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800463 registerContentObservers();
464
Joe Onorato7c312c12009-08-13 21:36:53 -0700465 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700466
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 mSavedState = savedInstanceState;
468 restoreState(mSavedState);
469
470 if (PROFILE_STARTUP) {
471 android.os.Debug.stopMethodTracing();
472 }
473
474 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700475 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700476 // If the user leaves launcher, then we should just load items asynchronously when
477 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500478 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700479 } else {
480 // We only load the page synchronously if the user rotates (or triggers a
481 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800482 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700483 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800484 }
485
486 // For handling default keys
487 mDefaultKeySsb = new SpannableStringBuilder();
488 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800489
490 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
491 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800492
Adam Cohenf9426d52012-06-04 17:26:21 -0700493 updateGlobalIcons();
494
495 // On large interfaces, we want the screen to auto-rotate based on the current orientation
496 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700497
Adam Cohen432609a2014-03-13 17:03:22 -0700498 if (shouldShowIntroScreen()) {
499 showIntroScreen();
500 } else {
501 showFirstRunActivity();
502 }
503
Winson Chunge43a1e72014-01-15 10:33:02 -0800504 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
505 // on the device, then we always show the first run cling experience (or if there is no
506 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800507 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
508 if (mModel.canMigrateFromOldLauncherDb(this)) {
509 mLauncherClings.showMigrationCling();
510 } else {
511 mLauncherClings.showFirstRunCling();
512 }
Winson Chunga6945242014-01-08 14:04:34 -0800513 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800514 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800515 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700516 }
517
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700518 @Override
519 public void onLauncherProviderChange() { }
520
Winson Chung98ca0f72013-07-29 12:58:51 -0700521 /** To be overriden by subclasses to hint to Launcher that we have custom content */
522 protected boolean hasCustomContentToLeft() {
523 return false;
524 }
525
Dave Hawkeya8881582013-09-17 15:55:33 -0600526 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500527 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 * {@link #addToCustomContentPage}. This will only be invoked if
529 * {@link #hasCustomContentToLeft()} is {@code true}.
530 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500531 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600532 }
533
534 /**
535 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
536 * ensure the custom content page is added or removed if necessary.
537 */
538 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600539 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600540 // Not bound yet, wait for bindScreens to be called.
541 return;
542 }
543
544 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
545 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500546 mWorkspace.createCustomContentContainer();
547 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600548 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
549 mWorkspace.removeCustomContentPage();
550 }
551 }
552
Adam Cohenf9426d52012-06-04 17:26:21 -0700553 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700554 boolean searchVisible = false;
555 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800556 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700557 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700558 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700559 searchVisible = updateGlobalSearchIcon();
560 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700561 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700562 if (sGlobalSearchIcon[coi] != null) {
563 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700564 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700565 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700566 if (sVoiceSearchIcon[coi] != null) {
567 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700568 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700569 }
Winson Chungadf0c182012-08-23 14:59:07 -0700570 if (mSearchDropTargetBar != null) {
571 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
572 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 }
Romain Guycbb89e42009-06-08 15:52:54 -0700574
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 if (sLocaleConfiguration == null) {
577 new AsyncTask<Void, Void, LocaleConfiguration>() {
578 @Override
579 protected LocaleConfiguration doInBackground(Void... unused) {
580 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
581 readConfiguration(Launcher.this, localeConfiguration);
582 return localeConfiguration;
583 }
584
585 @Override
586 protected void onPostExecute(LocaleConfiguration result) {
587 sLocaleConfiguration = result;
588 checkForLocaleChange(); // recursive, but now with a locale configuration
589 }
590 }.execute();
591 return;
592 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700593
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594 final Configuration configuration = getResources().getConfiguration();
595
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700596 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 final String locale = configuration.locale.toString();
598
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700599 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800600 final int mcc = configuration.mcc;
601
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final int mnc = configuration.mnc;
604
Romain Guy84f296c2009-11-04 15:00:44 -0800605 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606
Romain Guy84f296c2009-11-04 15:00:44 -0800607 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 sLocaleConfiguration.locale = locale;
609 sLocaleConfiguration.mcc = mcc;
610 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700611
Joe Onorato0589f0f2010-02-08 13:44:00 -0800612 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613
614 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100615 new AsyncTask<Void, Void, Void>() {
616 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100618 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700619 }
Michael Jurka43467462013-11-14 12:03:58 +0100620 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700621 }
622 }
623
624 private static class LocaleConfiguration {
625 public String locale;
626 public int mcc = -1;
627 public int mnc = -1;
628 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700629
Romain Guy98d01652009-06-30 16:21:04 -0700630 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
631 DataInputStream in = null;
632 try {
633 in = new DataInputStream(context.openFileInput(PREFERENCES));
634 configuration.locale = in.readUTF();
635 configuration.mcc = in.readInt();
636 configuration.mnc = in.readInt();
637 } catch (FileNotFoundException e) {
638 // Ignore
639 } catch (IOException e) {
640 // Ignore
641 } finally {
642 if (in != null) {
643 try {
644 in.close();
645 } catch (IOException e) {
646 // Ignore
647 }
648 }
649 }
650 }
651
652 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
653 DataOutputStream out = null;
654 try {
655 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
656 out.writeUTF(configuration.locale);
657 out.writeInt(configuration.mcc);
658 out.writeInt(configuration.mnc);
659 out.flush();
660 } catch (FileNotFoundException e) {
661 // Ignore
662 } catch (IOException e) {
663 //noinspection ResultOfMethodCallIgnored
664 context.getFileStreamPath(PREFERENCES).delete();
665 } finally {
666 if (out != null) {
667 try {
668 out.close();
669 } catch (IOException e) {
670 // Ignore
671 }
672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674 }
675
Anton Hanssona2f665f2013-09-26 12:18:32 +0100676 public Stats getStats() {
677 return mStats;
678 }
679
Bjorn Bringertc459e522013-06-07 19:36:01 +0100680 public LayoutInflater getInflater() {
681 return mInflater;
682 }
683
Winson Chung36a62fe2012-05-06 18:04:42 -0700684 boolean isDraggingEnabled() {
685 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
686 // that is subsequently removed from the workspace in startBinding().
687 return !mModel.isLoadingWorkspace();
688 }
689
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 static int getScreen() {
691 synchronized (sLock) {
692 return sScreen;
693 }
694 }
695
696 static void setScreen(int screen) {
697 synchronized (sLock) {
698 sScreen = screen;
699 }
700 }
701
Winson Chung557d6ed2011-07-08 15:34:52 -0700702 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000703 * Copied from View -- the View version of the method isn't called
704 * anywhere else in our process and only exists for API level 17+,
705 * so it's ok to keep our own version with no API requirement.
706 */
707 public static int generateViewId() {
708 for (;;) {
709 final int result = sNextGeneratedId.get();
710 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
711 int newValue = result + 1;
712 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
713 if (sNextGeneratedId.compareAndSet(result, newValue)) {
714 return result;
715 }
716 }
717 }
718
719 public int getViewIdForItem(ItemInfo info) {
720 // This cast is safe given the > 2B range for int.
721 int itemId = (int) info.id;
722 if (mItemIdToViewId.containsKey(itemId)) {
723 return mItemIdToViewId.get(itemId);
724 }
725 int viewId = generateViewId();
726 mItemIdToViewId.put(itemId, viewId);
727 return viewId;
728 }
729
730 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700731 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
732 * a configuration step, this allows the proper animations to run after other transitions.
733 */
Adam Cohendb364c32014-05-20 14:23:40 -0700734 private long completeAdd(PendingAddArguments args) {
735
736 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700739 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700740 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700741 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700743 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700744 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700745 case REQUEST_RECONFIGURE_APPWIDGET:
746 completeRestoreAppWidget(args.appWidgetId);
747 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 }
Michael Jurka27614d22012-04-02 06:40:22 -0700749 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
750 // if you turned the screen off and then back while in All Apps, Launcher would not
751 // return to the workspace. Clearing mAddInfo.container here fixes this issue
752 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700753 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800754 }
755
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700757 protected void onActivityResult(
758 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700759 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700760 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700761 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800762 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700763
Adam Cohenad4e15c2013-10-17 16:21:35 -0700764 Runnable exitSpringLoaded = new Runnable() {
765 @Override
766 public void run() {
767 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
768 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
769 }
770 };
771
Michael Jurka8b805b12012-04-18 14:23:14 -0700772 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
775 if (resultCode == RESULT_CANCELED) {
776 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700777 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700778 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700779 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
781 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700782 }
783 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200784 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
785 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
786 mWorkspace.exitOverviewMode(false);
787 }
788 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700789 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200790
Adam Cohened66b2b2012-01-23 17:28:51 -0800791 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
792 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700793
Adam Cohendb364c32014-05-20 14:23:40 -0700794 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800795 // We have special handling for widgets
796 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800797 final int appWidgetId;
798 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
799 : -1;
800 if (widgetId < 0) {
801 appWidgetId = pendingAddWidgetId;
802 } else {
803 appWidgetId = widgetId;
804 }
805
Adam Cohenad4e15c2013-10-17 16:21:35 -0700806 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800807 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700808 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
809 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700810 result = RESULT_CANCELED;
811 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700812 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700813 @Override
814 public void run() {
815 exitSpringLoadedDragModeDelayed(false, 0, null);
816 }
817 };
Adam Cohendb364c32014-05-20 14:23:40 -0700818 if (workspaceLocked) {
819 // No need to remove the empty screen if we're mid-binding, as the
820 // the bind will not add the empty screen.
821 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
822 } else {
823 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
824 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
825 }
Winson Chung5aaab772012-04-27 15:24:02 -0700826 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700827 if (!workspaceLocked) {
828 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
829 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
830
831 dropLayout.setDropPending(true);
832 final Runnable onComplete = new Runnable() {
833 @Override
834 public void run() {
835 completeTwoStageWidgetDrop(resultCode, appWidgetId);
836 dropLayout.setDropPending(false);
837 }
838 };
839 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
840 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
841 } else {
842 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
843 mPendingAddInfo);
844 sPendingAddItem = args;
845 }
Winson Chung5aaab772012-04-27 15:24:02 -0700846 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800847 return;
848 }
849
Sunny Goyalff572272014-07-23 13:58:07 -0700850 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
851 if (resultCode == RESULT_OK) {
852 // Update the widget view.
853 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
854 pendingAddWidgetId, mPendingAddInfo);
855 if (workspaceLocked) {
856 sPendingAddItem = args;
857 } else {
858 completeAdd(args);
859 }
860 }
861 // Leave the widget in the pending state if the user canceled the configure.
862 return;
863 }
864
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 // The pattern used here is that a user PICKs a specific application,
866 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700867
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
869 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700870 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700871 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
872 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800873 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700874 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800875 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700876 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700877 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
878 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800879 }
Adam Cohen00074722013-10-11 17:46:09 -0700880 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700881 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700882 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800885 }
886
Adam Cohendb364c32014-05-20 14:23:40 -0700887 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
888 appWidgetId, ItemInfo info) {
889 PendingAddArguments args = new PendingAddArguments();
890 args.requestCode = requestCode;
891 args.intent = data;
892 args.container = info.container;
893 args.screenId = info.screenId;
894 args.cellX = info.cellX;
895 args.cellY = info.cellY;
896 args.appWidgetId = appWidgetId;
897 return args;
898 }
899
900 /**
901 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
902 *
903 * @param screenId the screen id to check
904 * @return the new screen, or screenId if it exists
905 */
906 private long ensurePendingDropLayoutExists(long screenId) {
907 CellLayout dropLayout =
908 (CellLayout) mWorkspace.getScreenWithId(screenId);
909 if (dropLayout == null) {
910 // it's possible that the add screen was removed because it was
911 // empty and a re-bind occurred
912 mWorkspace.addExtraEmptyScreen();
913 return mWorkspace.commitExtraEmptyScreen();
914 } else {
915 return screenId;
916 }
917 }
918
Adam Cohened66b2b2012-01-23 17:28:51 -0800919 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700920 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700921 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800922 Runnable onCompleteRunnable = null;
923 int animationType = 0;
924
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700925 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800926 if (resultCode == RESULT_OK) {
927 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
928 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700929 mPendingAddWidgetInfo);
930 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 onCompleteRunnable = new Runnable() {
932 @Override
933 public void run() {
934 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700935 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700936 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
937 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800938 }
939 };
940 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800941 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800942 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800943 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700944 if (mDragLayer.getAnimatedView() != null) {
945 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
946 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
947 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700948 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700949 // The animated view may be null in the case of a rotation during widget configuration
950 onCompleteRunnable.run();
951 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800952 }
953
954 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700955 protected void onStop() {
956 super.onStop();
957 FirstFrameAnimatorHelper.setIsVisible(false);
958 }
959
960 @Override
961 protected void onStart() {
962 super.onStart();
963 FirstFrameAnimatorHelper.setIsVisible(true);
964 }
965
966 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800967 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200968 long startTime = 0;
969 if (DEBUG_RESUME_TIME) {
970 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400971 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200972 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700974
Winson Chung4a2afa32012-07-19 14:53:05 -0700975 // Restore the previous launcher state
976 if (mOnResumeState == State.WORKSPACE) {
977 showWorkspace(false);
978 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800979 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700980 }
981 mOnResumeState = State.NONE;
982
Craig Mautner360310b2012-10-26 15:13:08 -0700983 // Background was set to gradient in onPause(), restore to black if in all apps.
984 setWorkspaceBackground(mState == State.WORKSPACE);
985
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800986 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700987 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700988 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500989 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400990 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700991 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700993 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200994 // We might have postponed some bind calls until onResume (see waitUntilResume) --
995 // execute them here
996 long startTimeCallbacks = 0;
997 if (DEBUG_RESUME_TIME) {
998 startTimeCallbacks = System.currentTimeMillis();
999 }
1000
1001 if (mAppsCustomizeContent != null) {
1002 mAppsCustomizeContent.setBulkBind(true);
1003 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001004 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1005 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001006 }
1007 if (mAppsCustomizeContent != null) {
1008 mAppsCustomizeContent.setBulkBind(false);
1009 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001010 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001011 if (DEBUG_RESUME_TIME) {
1012 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1013 (System.currentTimeMillis() - startTimeCallbacks));
1014 }
Michael Jurka447bf842013-05-15 14:52:15 +02001015 }
Michael Jurka54554252013-08-01 12:52:23 +02001016 if (mOnResumeCallbacks.size() > 0) {
1017 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1018 mOnResumeCallbacks.get(i).run();
1019 }
1020 mOnResumeCallbacks.clear();
1021 }
Winson Chunge4e50662012-01-23 14:45:13 -08001022
1023 // Reset the pressed state of icons that were locked in the press state while activities
1024 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001025 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001026 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001027 mWaitingForResume.setStayPressed(false);
1028 }
Winson Chunge4e50662012-01-23 14:45:13 -08001029 if (mAppsCustomizeContent != null) {
1030 // Resets the previous all apps icon press state
1031 mAppsCustomizeContent.resetDrawableState();
1032 }
Winson Chung82963d52013-10-09 11:20:57 -07001033
Adam Cohen06dff352012-06-01 17:17:08 -07001034 // It is possible that widgets can receive updates while launcher is not in the foreground.
1035 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1036 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1037 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001038 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001039
Winson Chung780fe592013-09-26 14:48:44 -07001040 // Process any items that were added while Launcher was away.
1041 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1042
Winson Chung5841efa2013-09-30 18:06:44 -07001043 // Update the voice search button proxy
1044 updateVoiceButtonProxyVisible(false);
1045
Adam Cohenf9426d52012-06-04 17:26:21 -07001046 // Again, as with the above scenario, it's possible that one or more of the global icons
1047 // were updated in the wrong orientation.
1048 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001049 if (DEBUG_RESUME_TIME) {
1050 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1051 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001052
1053 if (mWorkspace.getCustomContentCallbacks() != null) {
1054 // If we are resuming and the custom content is the current page, we call onShow().
1055 // It is also poassible that onShow will instead be called slightly after first layout
1056 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1057 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001058 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001059 }
1060 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001061 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001062 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001063
1064 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001065 }
1066
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001067 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001069 // Ensure that items added to Launcher are queued until Launcher returns
1070 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001071 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001072
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001073 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001074 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001075 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001076 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001077
1078 // We call onHide() aggressively. The custom content callbacks should be able to
1079 // debounce excess onHide calls.
1080 if (mWorkspace.getCustomContentCallbacks() != null) {
1081 mWorkspace.getCustomContentCallbacks().onHide();
1082 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001083 }
Romain Guycbb89e42009-06-08 15:52:54 -07001084
Adam Cohenbffe7452013-07-22 18:21:45 -07001085 QSBScroller mQsbScroller = new QSBScroller() {
1086 int scrollY = 0;
1087
1088 @Override
1089 public void setScrollY(int scroll) {
1090 scrollY = scroll;
1091
1092 if (mWorkspace.isOnOrMovingToCustomContent()) {
1093 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001094 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001095 }
1096 }
1097 };
1098
1099 public void resetQSBScroll() {
1100 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001101 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001102 }
1103
1104 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001105 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1106 // by a onResume or by scrolling otherwise.
1107 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001108
1109 // Custom content is completely hidden
1110 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001111
1112 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1113 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001114
1115 // Indicates whether the user is allowed to scroll away from the custom content.
1116 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001117 }
1118
Jorim Jaggid017f882014-01-14 17:08:48 -08001119 protected boolean hasSettings() {
1120 return false;
1121 }
1122
Adam Cohenbffe7452013-07-22 18:21:45 -07001123 public interface QSBScroller {
1124 public void setScrollY(int scrollY);
1125 }
1126
Winson Chung98ca0f72013-07-29 12:58:51 -07001127 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001128 CustomContentCallbacks callbacks, String description) {
1129 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001130 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001131 }
1132
Adam Cohenedb40762013-07-18 16:45:45 -07001133 // The custom content needs to offset its content to account for the QSB
1134 public int getTopOffsetForCustomContent() {
1135 return mWorkspace.getPaddingTop();
1136 }
1137
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001138 @Override
1139 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001140 // Flag the loader to stop early before switching
1141 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001142 if (mAppsCustomizeContent != null) {
1143 mAppsCustomizeContent.surrender();
1144 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001145 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001146 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001147
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001148 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001149 @Override
1150 public void onWindowFocusChanged(boolean hasFocus) {
1151 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001152 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001153 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001154
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001155 private boolean acceptFilter() {
1156 final InputMethodManager inputManager = (InputMethodManager)
1157 getSystemService(Context.INPUT_METHOD_SERVICE);
1158 return !inputManager.isFullscreenMode();
1159 }
1160
1161 @Override
1162 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001163 final int uniChar = event.getUnicodeChar();
1164 final boolean handled = super.onKeyDown(keyCode, event);
1165 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1166 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1168 keyCode, event);
1169 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001170 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001171 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001172 // showSearchDialog()
1173 // If there are multiple keystrokes before the search dialog takes focus,
1174 // onSearchRequested() will be called for every keystroke,
1175 // but it is idempotent, so it's fine.
1176 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 }
1178 }
1179
Joe Onorato8a9625e2010-01-28 15:55:35 -08001180 // Eat the long press event so the keyboard doesn't come up.
1181 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1182 return true;
1183 }
1184
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 return handled;
1186 }
1187
Karl Rosaen138a0412009-04-23 19:00:21 -07001188 private String getTypedText() {
1189 return mDefaultKeySsb.toString();
1190 }
1191
1192 private void clearTypedText() {
1193 mDefaultKeySsb.clear();
1194 mDefaultKeySsb.clearSpans();
1195 Selection.setSelection(mDefaultKeySsb, 0);
1196 }
1197
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001199 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1200 * State
1201 */
1202 private static State intToState(int stateOrdinal) {
1203 State state = State.WORKSPACE;
1204 final State[] stateValues = State.values();
1205 for (int i = 0; i < stateValues.length; i++) {
1206 if (stateValues[i].ordinal() == stateOrdinal) {
1207 state = stateValues[i];
1208 break;
1209 }
1210 }
1211 return state;
1212 }
1213
1214 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215 * Restores the previous state, if it exists.
1216 *
1217 * @param savedState The previous state.
1218 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001219 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001220 private void restoreState(Bundle savedState) {
1221 if (savedState == null) {
1222 return;
1223 }
1224
Michael Jurka883f55b2010-10-21 15:47:14 -07001225 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001226 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001227 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001228 }
1229
Adam Cohen21cd0022013-10-09 18:57:02 -07001230 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1231 PagedView.INVALID_RESTORE_PAGE);
1232 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001233 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234 }
1235
Winson Chung3d503fb2011-07-13 17:25:49 -07001236 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001237 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001238
Winson Chung3d503fb2011-07-13 17:25:49 -07001239 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1240 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001241 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001242 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1243 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001244 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1245 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1246 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001247 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001248 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 mRestoring = true;
1250 }
1251
1252 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1253 if (renameFolder) {
1254 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001255 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 mRestoring = true;
1257 }
Winson Chunga12a2502010-12-20 14:41:35 -08001258
Winson Chung785d2eb2011-04-14 16:08:02 -07001259 // Restore the AppsCustomize tab
1260 if (mAppsCustomizeTabHost != null) {
1261 String curTab = savedState.getString("apps_customize_currentTab");
1262 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001263 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001264 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001265 mAppsCustomizeContent.loadAssociatedPages(
1266 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001267 }
1268
Winson Chung5afbf7b2011-07-25 11:53:08 -07001269 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1270 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001271 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001272 mItemIdToViewId = (HashMap<Integer, Integer>)
1273 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001274 }
1275
1276 /**
1277 * Finds all the views we need and configure them properly.
1278 */
1279 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001280 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001281
Craig Mautner360310b2012-10-26 15:13:08 -07001282 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001283 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001284 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1285 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001286 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001287 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001288
John Spurlock77e1f472013-09-11 10:09:51 -04001289 mLauncherView.setSystemUiVisibility(
1290 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001291 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292
Winson Chung4c98d922011-05-31 16:50:48 -07001293 // Setup the drag layer
1294 mDragLayer.setup(this, dragController);
1295
Winson Chung3d503fb2011-07-13 17:25:49 -07001296 // Setup the hotseat
1297 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1298 if (mHotseat != null) {
1299 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001300 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001301 }
1302
Jorim Jaggid017f882014-01-14 17:08:48 -08001303 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001304 View widgetButton = findViewById(R.id.widget_button);
1305 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001306 @Override
1307 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001308 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001309 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001310 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001311 }
1312 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001313 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1314
1315 View wallpaperButton = findViewById(R.id.wallpaper_button);
1316 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001317 @Override
1318 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001319 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001320 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001321 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001322 }
1323 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001324 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1325
1326 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001327 if (hasSettings()) {
1328 settingsButton.setOnClickListener(new OnClickListener() {
1329 @Override
1330 public void onClick(View arg0) {
1331 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001332 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001333 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001334 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001335 });
1336 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1337 } else {
1338 settingsButton.setVisibility(View.GONE);
1339 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1340 lp.gravity = Gravity.END | Gravity.TOP;
1341 widgetButton.requestLayout();
1342 }
1343
Adam Cohendbdff6b2013-09-18 19:09:15 -07001344 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001345
Winson Chung4c98d922011-05-31 16:50:48 -07001346 // Setup the workspace
1347 mWorkspace.setHapticFeedbackEnabled(false);
1348 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001349 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001350 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001351
Winson Chungf0ea4d32011-06-06 14:27:16 -07001352 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001353 mSearchDropTargetBar = (SearchDropTargetBar)
1354 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001355
Winson Chungf0ea4d32011-06-06 14:27:16 -07001356 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001357 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001358 mAppsCustomizeContent = (AppsCustomizePagedView)
1359 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1360 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001361
Winson Chung3d503fb2011-07-13 17:25:49 -07001362 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001363 dragController.setDragScoller(mWorkspace);
1364 dragController.setScrollView(mDragLayer);
1365 dragController.setMoveTarget(mWorkspace);
1366 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001367 if (mSearchDropTargetBar != null) {
1368 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001369 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001370
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001371 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001372 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001373 mWeightWatcher = new WeightWatcher(this);
1374 mWeightWatcher.setAlpha(0.5f);
1375 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001376 new FrameLayout.LayoutParams(
1377 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001378 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001379 Gravity.BOTTOM)
1380 );
Adam Cohen39a06042013-07-19 14:30:12 -07001381
1382 boolean show = shouldShowWeightWatcher();
1383 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001384 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385 }
1386
1387 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001388 * Sets the all apps button. This method is called from {@link Hotseat}.
1389 */
1390 public void setAllAppsButton(View allAppsButton) {
1391 mAllAppsButton = allAppsButton;
1392 }
1393
1394 public View getAllAppsButton() {
1395 return mAllAppsButton;
1396 }
1397
1398 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 * Creates a view representing a shortcut.
1400 *
1401 * @param info The data structure describing the shortcut.
1402 *
1403 * @return A View inflated from R.layout.application.
1404 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001405 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001406 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001407 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 }
1409
1410 /**
1411 * Creates a view representing a shortcut inflated from the specified resource.
1412 *
1413 * @param layoutResId The id of the XML layout used to create the shortcut.
1414 * @param parent The group the shortcut belongs to.
1415 * @param info The data structure describing the shortcut.
1416 *
1417 * @return A View inflated from layoutResId.
1418 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001419 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001420 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001421 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001423 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 return favorite;
1425 }
1426
1427 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001428 * Add a shortcut to the workspace.
1429 *
1430 * @param data The intent describing the shortcut.
1431 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001433 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001434 int cellY) {
1435 int[] cellXY = mTmpAddItemCellCoordinates;
1436 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001437 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001438
Michael Jurkad3ef3062010-11-23 16:23:58 -08001439 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001440
Adam Cohen558baaf2011-08-15 15:22:57 -07001441 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001442 if (info == null) {
1443 return;
1444 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001445 final View view = createShortcut(info);
1446
Adam Cohenfbba09b2011-07-18 21:43:05 -07001447 // First we check if we already know the exact location where we want to add this item.
1448 if (cellX >= 0 && cellY >= 0) {
1449 cellXY[0] = cellX;
1450 cellXY[1] = cellY;
1451 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001452
1453 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001454 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001455 true, null,null)) {
1456 return;
1457 }
1458 DragObject dragObject = new DragObject();
1459 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001460 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1461 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001462 return;
1463 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001464 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001465 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001466 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001467 foundCellSpan = (result != null);
1468 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001469 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001470 }
1471
1472 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001473 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001474 return;
1475 }
1476
Adam Cohendcd297f2013-06-18 13:13:40 -07001477 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478
1479 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001480 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001482 }
1483 }
1484
Adam Cohen2f093b62012-04-30 18:59:53 -07001485 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1486 int minHeight) {
1487 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001488 // We want to account for the extra amount of padding that we are adding to the widget
1489 // to ensure that it gets the full amount of space that it has requested
1490 int requiredWidth = minWidth + padding.left + padding.right;
1491 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001492 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001493 }
1494
Adam Cohen2f093b62012-04-30 18:59:53 -07001495 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1496 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001497 }
1498
Adam Cohen2f093b62012-04-30 18:59:53 -07001499 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1500 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001501 }
1502
Adam Cohen2f093b62012-04-30 18:59:53 -07001503 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1504 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001505 }
1506
Adam Cohen2f093b62012-04-30 18:59:53 -07001507 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1508 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001509 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001510 }
1511
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001512 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001513 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001515 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001516 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001518 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001519 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1520 if (appWidgetInfo == null) {
1521 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1522 }
Romain Guycbb89e42009-06-08 15:52:54 -07001523
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001524 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001525 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001526
Adam Cohen2f093b62012-04-30 18:59:53 -07001527 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1528 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001529
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001530 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001531 // We have saved the position to which the widget was dragged-- this really only matters
1532 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001533 int[] cellXY = mTmpAddItemCellCoordinates;
1534 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001535 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001536 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001537 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1538 cellXY[0] = mPendingAddInfo.cellX;
1539 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001540 spanXY[0] = mPendingAddInfo.spanX;
1541 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001542 foundCellSpan = true;
1543 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001544 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001545 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001546 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1547 spanXY[1], cellXY, finalSpan);
1548 spanXY[0] = finalSpan[0];
1549 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001550 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001551 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001552 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001553 }
1554
Michael Jurka0280c3b2010-09-17 15:00:07 -07001555 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001556 if (appWidgetId != -1) {
1557 // Deleting an app widget ID is a void call but writes to disk before returning
1558 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001559 new AsyncTask<Void, Void, Void>() {
1560 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001561 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001562 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001563 }
Michael Jurka43467462013-11-14 12:03:58 +01001564 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001565 }
Winson Chung93eef082012-03-23 15:59:27 -07001566 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001567 return;
1568 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001570 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001571 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1572 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001573 launcherInfo.spanX = spanXY[0];
1574 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001575 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1576 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001577
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001578 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001579 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580
1581 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001582 if (hostView == null) {
1583 // Perform actual inflation because we're live
1584 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1585 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1586 } else {
1587 // The AppWidgetHostView has already been inflated and instantiated
1588 launcherInfo.hostView = hostView;
1589 }
Romain Guycbb89e42009-06-08 15:52:54 -07001590
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001592 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001593 launcherInfo.notifyWidgetSizeChanged(this);
1594
Adam Cohendcd297f2013-06-18 13:13:40 -07001595 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001596 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001597
1598 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001600 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 }
Romain Guycbb89e42009-06-08 15:52:54 -07001602
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1604 @Override
1605 public void onReceive(Context context, Intent intent) {
1606 final String action = intent.getAction();
1607 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1608 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001609 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001610 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001611
Winson Chungc100e8e2011-08-09 16:02:43 -07001612 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001613 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001614 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001615 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001616 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001617 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1618 mUserPresent = true;
1619 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001620 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1621 mModel.resetLoadedState(false, true);
1622 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1623 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1624 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1625 mModel.resetLoadedState(false, true);
1626 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1627 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1628 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001629 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1630 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1631 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001632 }
1633 }
1634 };
1635
1636 @Override
1637 public void onAttachedToWindow() {
1638 super.onAttachedToWindow();
1639
1640 // Listen for broadcasts related to user-presence
1641 final IntentFilter filter = new IntentFilter();
1642 filter.addAction(Intent.ACTION_SCREEN_OFF);
1643 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001644 // For handling managed profiles
1645 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1646 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001647 if (ENABLE_DEBUG_INTENTS) {
1648 filter.addAction(DebugIntents.DELETE_DATABASE);
1649 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1650 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001651 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001652 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001653 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001654 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001655 mVisible = true;
1656 }
1657
Adam Cohen0b395352014-06-09 22:54:36 +00001658 /**
1659 * Sets up transparent navigation and status bars in LMP.
1660 * This method is a no-op for other platform versions.
1661 */
1662 @TargetApi(19)
1663 private void setupTransparentSystemBarsForLmp() {
1664 // TODO(sansid): use the APIs directly when compiling against L sdk.
1665 // Currently we use reflection to access the flags and the API to set the transparency
1666 // on the System bars.
1667 if (Utilities.isLmp()) {
1668 try {
1669 getWindow().getAttributes().systemUiVisibility |=
1670 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1671 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1672 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1673 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1674 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1675 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1676 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1677 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1678
1679 Method setStatusBarColorMethod =
1680 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1681 Method setNavigationBarColorMethod =
1682 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1683 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1684 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1685 } catch (NoSuchFieldException e) {
1686 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1687 } catch (NoSuchMethodException ex) {
1688 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1689 } catch (IllegalAccessException e) {
1690 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1691 } catch (IllegalArgumentException e) {
1692 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1693 } catch (InvocationTargetException e) {
1694 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1695 } finally {}
1696 }
1697 }
1698
Adam Cohended9f8d2010-11-03 13:25:16 -07001699 @Override
1700 public void onDetachedFromWindow() {
1701 super.onDetachedFromWindow();
1702 mVisible = false;
1703
Adam Cohend113e0c2010-11-11 10:48:05 -08001704 if (mAttached) {
1705 unregisterReceiver(mReceiver);
1706 mAttached = false;
1707 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001708 updateRunning();
1709 }
1710
1711 public void onWindowVisibilityChanged(int visibility) {
1712 mVisible = visibility == View.VISIBLE;
1713 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001714 // The following code used to be in onResume, but it turns out onResume is called when
1715 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1716 // is a more appropriate event to handle
1717 if (mVisible) {
1718 mAppsCustomizeTabHost.onWindowVisible();
1719 if (!mWorkspaceLoading) {
1720 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001721 // We want to let Launcher draw itself at least once before we force it to build
1722 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001723 // apps is nice and speedy.
1724 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001725 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001726 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001727 if (mStarted) return;
1728 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001729 // We delay the layer building a bit in order to give
1730 // other message processing a time to run. In particular
1731 // this avoids a delay in hiding the IME if it was
1732 // currently shown, because doing that may involve
1733 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001734 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001735 final ViewTreeObserver.OnDrawListener listener = this;
1736 mWorkspace.post(new Runnable() {
1737 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001738 if (mWorkspace != null &&
1739 mWorkspace.getViewTreeObserver() != null) {
1740 mWorkspace.getViewTreeObserver().
1741 removeOnDrawListener(listener);
1742 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001743 }
1744 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001745 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001746 }
1747 });
1748 }
1749 clearTypedText();
1750 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001751 }
1752
1753 private void sendAdvanceMessage(long delay) {
1754 mHandler.removeMessages(ADVANCE_MSG);
1755 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1756 mHandler.sendMessageDelayed(msg, delay);
1757 mAutoAdvanceSentTime = System.currentTimeMillis();
1758 }
1759
1760 private void updateRunning() {
1761 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1762 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1763 mAutoAdvanceRunning = autoAdvanceRunning;
1764 if (autoAdvanceRunning) {
1765 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1766 sendAdvanceMessage(delay);
1767 } else {
1768 if (!mWidgetsToAdvance.isEmpty()) {
1769 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1770 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1771 }
1772 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001773 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001774 }
1775 }
1776 }
1777
1778 private final Handler mHandler = new Handler() {
1779 @Override
1780 public void handleMessage(Message msg) {
1781 if (msg.what == ADVANCE_MSG) {
1782 int i = 0;
1783 for (View key: mWidgetsToAdvance.keySet()) {
1784 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1785 final int delay = mAdvanceStagger * i;
1786 if (v instanceof Advanceable) {
1787 postDelayed(new Runnable() {
1788 public void run() {
1789 ((Advanceable) v).advance();
1790 }
1791 }, delay);
1792 }
1793 i++;
1794 }
1795 sendAdvanceMessage(mAdvanceInterval);
1796 }
1797 }
1798 };
1799
1800 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001801 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001802 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1803 if (v instanceof Advanceable) {
1804 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001805 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001806 updateRunning();
1807 }
1808 }
1809
1810 void removeWidgetToAutoAdvance(View hostView) {
1811 if (mWidgetsToAdvance.containsKey(hostView)) {
1812 mWidgetsToAdvance.remove(hostView);
1813 updateRunning();
1814 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001815 }
1816
Joe Onorato9c1289c2009-08-17 11:03:03 -04001817 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001818 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001819 launcherInfo.hostView = null;
1820 }
1821
Winson Chung93eef082012-03-23 15:59:27 -07001822 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1823 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1824 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001825 }
1826
Winson Chunga6945242014-01-08 14:04:34 -08001827 public DragLayer getDragLayer() {
1828 return mDragLayer;
1829 }
1830
1831 public Workspace getWorkspace() {
1832 return mWorkspace;
1833 }
1834
1835 public Hotseat getHotseat() {
1836 return mHotseat;
1837 }
1838
Jorim Jaggid017f882014-01-14 17:08:48 -08001839 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001840 return mOverviewPanel;
1841 }
1842
1843 public SearchDropTargetBar getSearchBar() {
1844 return mSearchDropTargetBar;
1845 }
1846
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001847 public LauncherAppWidgetHost getAppWidgetHost() {
1848 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 }
Romain Guycbb89e42009-06-08 15:52:54 -07001850
Winson Chunga9abd0e2010-10-27 17:18:37 -07001851 public LauncherModel getModel() {
1852 return mModel;
1853 }
1854
Winson Chunga6945242014-01-08 14:04:34 -08001855 public LauncherClings getLauncherClings() {
1856 return mLauncherClings;
1857 }
1858
1859 protected SharedPreferences getSharedPrefs() {
1860 return mSharedPrefs;
1861 }
1862
Bjorn Bringertc459e522013-06-07 19:36:01 +01001863 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001864 getWindow().closeAllPanels();
1865
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001866 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001867 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001868 }
1869
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870 @Override
1871 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001872 long startTime = 0;
1873 if (DEBUG_RESUME_TIME) {
1874 startTime = System.currentTimeMillis();
1875 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001876 super.onNewIntent(intent);
1877
1878 // Close the menu
1879 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001880 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001881 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001882
Adam Cohened307df2013-10-02 09:37:31 -07001883 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1884 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1885 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001886
Adam Cohen6fecd412013-10-02 17:41:50 -07001887 if (mWorkspace == null) {
1888 // Can be cases where mWorkspace is null, this prevents a NPE
1889 return;
1890 }
1891 Folder openFolder = mWorkspace.getOpenFolder();
1892 // In all these cases, only animate if we're already on home
1893 mWorkspace.exitWidgetResizeMode();
1894 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001895 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001896 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001897 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001898
Adam Cohen6fecd412013-10-02 17:41:50 -07001899 closeFolder();
1900 exitSpringLoadedDragMode();
1901
1902 // If we are already on home, then just animate back to the workspace,
1903 // otherwise, just wait until onResume to set the state back to Workspace
1904 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001905 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001906 } else {
1907 mOnResumeState = State.WORKSPACE;
1908 }
1909
1910 final View v = getWindow().peekDecorView();
1911 if (v != null && v.getWindowToken() != null) {
1912 InputMethodManager imm = (InputMethodManager)getSystemService(
1913 INPUT_METHOD_SERVICE);
1914 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1915 }
1916
1917 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001918 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001919 mAppsCustomizeTabHost.reset();
1920 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001921
1922 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 }
Adam Cohened307df2013-10-02 09:37:31 -07001924
Michael Jurka447bf842013-05-15 14:52:15 +02001925 if (DEBUG_RESUME_TIME) {
1926 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1927 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 }
1929
Adam Coppa120b8e2013-11-12 16:26:04 +00001930 /**
1931 * Override point for subclasses to prevent movement to the default screen when the home
1932 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1933 */
1934 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1935 return true;
1936 }
1937
1938 /**
1939 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1940 */
1941 protected void onHomeIntent() {
1942 // Do nothing
1943 }
1944
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001946 public void onRestoreInstanceState(Bundle state) {
1947 super.onRestoreInstanceState(state);
1948 for (int page: mSynchronouslyBoundPages) {
1949 mWorkspace.restoreInstanceStateForChild(page);
1950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 }
1952
1953 @Override
1954 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001955 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001956 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1957 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001958 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001959 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960
Michael Jurka883f55b2010-10-21 15:47:14 -07001961 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001962 // We close any open folder since it will not be re-opened, and we need to make sure
1963 // this state is reflected.
1964 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001965
Adam Cohendcd297f2013-06-18 13:13:40 -07001966 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001967 mWaitingForResult) {
1968 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001969 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001970 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1971 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001972 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1973 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1974 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001975 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 }
1977
1978 if (mFolderInfo != null && mWaitingForResult) {
1979 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1980 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1981 }
Michael Jurka946ad472010-07-09 18:05:18 -07001982
Winson Chung785d2eb2011-04-14 16:08:02 -07001983 // Save the current AppsCustomize tab
1984 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001985 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1986 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001987 if (currentTabTag != null) {
1988 outState.putString("apps_customize_currentTab", currentTabTag);
1989 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001990 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1991 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001992 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001993 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 }
1995
1996 @Override
1997 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001998 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001999
Winson Chunge7a03942011-08-05 15:05:12 -07002000 // Remove all pending runnables
2001 mHandler.removeMessages(ADVANCE_MSG);
2002 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002003 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002004
Winson Chungcd2b0142011-06-08 16:02:26 -07002005 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002006 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002007 mModel.stopLoader();
2008 app.setLauncher(null);
2009
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002011 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002013 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002015 mAppWidgetHost = null;
2016
2017 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018
2019 TextKeyListener.getInstance().release();
2020
Winson Chung81b52252012-08-27 15:34:29 -07002021 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2022 // to prevent leaking Launcher activities on orientation change.
2023 if (mModel != null) {
2024 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2025 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002026
2027 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002028 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002029
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002030 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002031 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002032 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002033 mWorkspace = null;
2034 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002035
Sunny Goyale755d462014-07-22 13:48:29 -07002036 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002037 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 }
2039
Adam Cohena9cf38f2011-05-02 15:36:58 -07002040 public DragController getDragController() {
2041 return mDragController;
2042 }
2043
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 @Override
2045 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002046 if (requestCode >= 0) {
2047 setWaitingForResult(true);
2048 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 super.startActivityForResult(intent, requestCode);
2050 }
2051
Winson Chung70d72102011-08-12 11:24:35 -07002052 /**
2053 * Indicates that we want global search for this activity by setting the globalSearch
2054 * argument for {@link #startSearch} to true.
2055 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002057 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002059
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002060 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002061
Karl Rosaen138a0412009-04-23 19:00:21 -07002062 if (initialQuery == null) {
2063 // Use any text typed in the launcher as the initial query
2064 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002065 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002066 if (appSearchData == null) {
2067 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002068 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069 }
Winson Chungadf0c182012-08-23 14:59:07 -07002070 Rect sourceBounds = new Rect();
2071 if (mSearchDropTargetBar != null) {
2072 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2073 }
Romain Guycbb89e42009-06-08 15:52:54 -07002074
Bjorn Bringertc459e522013-06-07 19:36:01 +01002075 startSearch(initialQuery, selectInitialQuery,
2076 appSearchData, sourceBounds);
2077 }
2078
2079 public void startSearch(String initialQuery,
2080 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002081 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002082 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002083 }
2084
2085 /**
2086 * Starts the global search activity. This code is a copied from SearchManager
2087 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002088 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002089 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002090 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002091 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2092 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2093 if (globalSearchActivity == null) {
2094 Log.w(TAG, "No global search activity found.");
2095 return;
2096 }
2097 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2098 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2099 intent.setComponent(globalSearchActivity);
2100 // Make sure that we have a Bundle to put source in
2101 if (appSearchData == null) {
2102 appSearchData = new Bundle();
2103 } else {
2104 appSearchData = new Bundle(appSearchData);
2105 }
2106 // Set source to package name of app that starts global search, if not set already.
2107 if (!appSearchData.containsKey("source")) {
2108 appSearchData.putString("source", getPackageName());
2109 }
2110 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2111 if (!TextUtils.isEmpty(initialQuery)) {
2112 intent.putExtra(SearchManager.QUERY, initialQuery);
2113 }
2114 if (selectInitialQuery) {
2115 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2116 }
2117 intent.setSourceBounds(sourceBounds);
2118 try {
2119 startActivity(intent);
2120 } catch (ActivityNotFoundException ex) {
2121 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2122 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 }
2124
Yura4f93ec62014-02-04 14:15:21 +00002125 public boolean isOnCustomContent() {
2126 return mWorkspace.isOnOrMovingToCustomContent();
2127 }
2128
Winson Chung70d72102011-08-12 11:24:35 -07002129 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002130 public boolean onPrepareOptionsMenu(Menu menu) {
2131 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002132 if (!isOnCustomContent()) {
2133 // Close any open folders
2134 closeFolder();
2135 // Stop resizing any widgets
2136 mWorkspace.exitWidgetResizeMode();
2137 if (!mWorkspace.isInOverviewMode()) {
2138 // Show the overview mode
2139 showOverviewMode(true);
2140 } else {
2141 showWorkspace(true);
2142 }
Winson Chunge0298742014-01-17 12:03:00 -08002143 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002144 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002145 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002147 @Override
2148 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002149 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002150 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002151 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002152 }
2153
Joe Onorato9c1289c2009-08-17 11:03:03 -04002154 public boolean isWorkspaceLocked() {
2155 return mWorkspaceLoading || mWaitingForResult;
2156 }
2157
Adam Cohen517a7f52014-03-01 12:12:59 -08002158 public boolean isWorkspaceLoading() {
2159 return mWorkspaceLoading;
2160 }
2161
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002162 private void setWorkspaceLoading(boolean value) {
2163 boolean isLocked = isWorkspaceLocked();
2164 mWorkspaceLoading = value;
2165 if (isLocked != isWorkspaceLocked()) {
2166 onWorkspaceLockedChanged();
2167 }
2168 }
2169
2170 private void setWaitingForResult(boolean value) {
2171 boolean isLocked = isWorkspaceLocked();
2172 mWaitingForResult = value;
2173 if (isLocked != isWorkspaceLocked()) {
2174 onWorkspaceLockedChanged();
2175 }
2176 }
2177
2178 protected void onWorkspaceLockedChanged() { }
2179
Michael Jurka0280c3b2010-09-17 15:00:07 -07002180 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002181 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002182 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002183 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2184 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002185 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002186 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002187 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002188
Adam Cohenad4e15c2013-10-17 16:21:35 -07002189 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2190 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2191 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2192 }
2193
2194 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2195 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2196 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002197 if (appWidgetInfo.configure != null) {
2198 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002199 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002200
Bjorn Bringert7984c942009-12-09 15:38:25 +00002201 // Launch over to configure widget, if needed
2202 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002203 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002204 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002205 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002206 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002207 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002208 Runnable onComplete = new Runnable() {
2209 @Override
2210 public void run() {
2211 // Exit spring loaded mode if necessary after adding the widget
2212 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2213 null);
2214 }
2215 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002216 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002217 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002218 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002219 }
2220 }
Romain Guycbb89e42009-06-08 15:52:54 -07002221
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002222 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002223 // Close any folders that may be open.
2224 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002225 mWorkspace.moveToCustomContentScreen(animate);
2226 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002227 /**
2228 * Process a shortcut drop.
2229 *
2230 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002231 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002232 * @param cell The cell it should be added to, optional
2233 * @param position The location on the screen where it was dropped, optional
2234 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002235 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002236 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002237 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002238 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002239 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002240 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002241
2242 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002243 mPendingAddInfo.cellX = cell[0];
2244 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002245 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002246
2247 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2248 createShortcutIntent.setComponent(componentName);
2249 processShortcut(createShortcutIntent);
2250 }
2251
Adam Cohenfbba09b2011-07-18 21:43:05 -07002252 /**
2253 * Process a widget drop.
2254 *
2255 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002256 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 * @param cell The cell it should be added to, optional
2258 * @param position The location on the screen where it was dropped, optional
2259 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002260 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002261 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002262 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002263 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002264 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002265 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002266 mPendingAddInfo.minSpanX = info.minSpanX;
2267 mPendingAddInfo.minSpanY = info.minSpanY;
2268
Adam Cohenfbba09b2011-07-18 21:43:05 -07002269 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002270 mPendingAddInfo.cellX = cell[0];
2271 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002272 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002273 if (span != null) {
2274 mPendingAddInfo.spanX = span[0];
2275 mPendingAddInfo.spanY = span[1];
2276 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002277
Adam Cohened66b2b2012-01-23 17:28:51 -08002278 AppWidgetHostView hostView = info.boundWidget;
2279 int appWidgetId;
2280 if (hostView != null) {
2281 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002282 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002283 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002284 // In this case, we either need to start an activity to get permission to bind
2285 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002286 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002287 Bundle options = info.bindOptions;
2288
2289 boolean success = false;
2290 if (options != null) {
2291 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2292 info.componentName, options);
2293 } else {
2294 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2295 info.componentName);
2296 }
2297 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002298 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002299 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002300 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002301 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2302 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2303 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002304 // TODO: we need to make sure that this accounts for the options bundle.
2305 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002306 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2307 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002308 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002309 }
2310
Joe Onoratodeb98af2010-02-19 14:59:39 -08002311 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002312 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002313 }
2314
Winson Chung24ab2f12010-09-16 14:10:47 -07002315 void processWallpaper(Intent intent) {
2316 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2317 }
2318
Adam Cohendcd297f2013-06-18 13:13:40 -07002319 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002320 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002321 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002322 folderInfo.title = getText(R.string.folder_name);
2323
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002324 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002325 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002326 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002327 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002328
2329 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002330 FolderIcon newFolder =
2331 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002332 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002333 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002334 // Force measure the new folder icon
2335 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2336 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002337 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002338 }
Romain Guycbb89e42009-06-08 15:52:54 -07002339
Joe Onorato9c1289c2009-08-17 11:03:03 -04002340 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002341 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002342 }
2343
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002344 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002345 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002346 }
2347
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002348 /**
2349 * Registers various content observers. The current implementation registers
2350 * only a favorites observer to keep track of the favorites applications.
2351 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002352 private void registerContentObservers() {
2353 ContentResolver resolver = getContentResolver();
2354 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2355 true, mWidgetObserver);
2356 }
2357
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 @Override
2359 public boolean dispatchKeyEvent(KeyEvent event) {
2360 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2361 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002363 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002364 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002365 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002366 dumpState();
2367 return true;
2368 }
2369 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002370 }
2371 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2372 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002373 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 return true;
2375 }
2376 }
2377
2378 return super.dispatchKeyEvent(event);
2379 }
2380
Joe Onorato88ec0992009-11-19 13:16:06 -08002381 @Override
2382 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002383 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002384 if (mAppsCustomizeContent.getContentType() ==
2385 AppsCustomizePagedView.ContentType.Applications) {
2386 showWorkspace(true);
2387 } else {
2388 showOverviewMode(true);
2389 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002390 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002391 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002392 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002393 Folder openFolder = mWorkspace.getOpenFolder();
2394 if (openFolder.isEditingName()) {
2395 openFolder.dismissEditingName();
2396 } else {
2397 closeFolder();
2398 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002399 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002400 mWorkspace.exitWidgetResizeMode();
2401
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002402 // Back button is a no-op here, but give at least some feedback for the button press
2403 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002404 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002405 }
2406
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002407 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002408 * Re-listen when widgets are reset.
2409 */
2410 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002411 if (mAppWidgetHost != null) {
2412 mAppWidgetHost.startListening();
2413 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002414 }
2415
2416 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002417 * Launches the intent referred by the clicked shortcut.
2418 *
2419 * @param v The view representing the clicked shortcut.
2420 */
2421 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002422 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2423 // view has detached (it's possible for this to happen if the view is removed mid touch).
2424 if (v.getWindowToken() == null) {
2425 return;
2426 }
2427
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002428 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002429 return;
2430 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002431
Adam Cohen1697b792013-09-17 19:08:21 -07002432 if (v instanceof Workspace) {
2433 if (mWorkspace.isInOverviewMode()) {
2434 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002435 }
2436 return;
2437 }
2438
2439 if (v instanceof CellLayout) {
2440 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002441 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002442 }
2443 }
2444
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002445 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002446 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002447 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002448 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002449 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002450 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002451 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002452 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002453 onClickAllAppsButton(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002454 } else if (tag instanceof LauncherAppWidgetInfo) {
2455 if (v instanceof PendingAppWidgetHostView) {
2456 onClickPendingWidget((PendingAppWidgetHostView) v);
2457 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002458 }
2459 }
2460
Michael Jurka0e260592010-06-30 17:07:39 -07002461 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002462 return false;
2463 }
2464
Michael Jurkaaf442092010-06-10 17:01:57 -07002465 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002466 * Event handler for the app widget view which has not fully restored.
2467 */
2468 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2469 if (v.isReadyForClickSetup()) {
2470 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2471 int widgetId = info.appWidgetId;
2472 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2473 if (appWidgetInfo != null) {
2474 mPendingAddWidgetInfo = appWidgetInfo;
2475 mPendingAddInfo.copyFrom(info);
2476 mPendingAddWidgetId = widgetId;
2477
2478 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2479 intent.setComponent(appWidgetInfo.configure);
2480 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2481 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2482 }
2483 }
2484 }
2485
2486 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002487 * Event handler for the search button
2488 *
2489 * @param v The view that was clicked.
2490 */
2491 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002492 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2493
Amith Yamasania135ba82011-08-09 17:42:01 -07002494 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002495 }
2496
2497 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002498 * Event handler for the voice button
2499 *
2500 * @param v The view that was clicked.
2501 */
2502 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002503 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002504
Bjorn Bringertc459e522013-06-07 19:36:01 +01002505 startVoice();
2506 }
2507
2508 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002509 try {
2510 final SearchManager searchManager =
2511 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2512 ComponentName activityName = searchManager.getGlobalSearchActivity();
2513 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002514 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002515 if (activityName != null) {
2516 intent.setPackage(activityName.getPackageName());
2517 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002518 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002519 } catch (ActivityNotFoundException e) {
2520 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002521 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002522 startActivitySafely(null, intent, "onClickVoiceButton");
2523 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002524 }
2525
2526 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002527 * Event handler for the "grid" button that appears on the home screen, which
2528 * enters all apps mode.
2529 *
2530 * @param v The view that was clicked.
2531 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002532 protected void onClickAllAppsButton(View v) {
2533 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2534 if (isAllAppsVisible()) {
2535 showWorkspace(true);
2536 } else {
2537 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2538 }
2539 }
2540
2541 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002542 * Event handler for a paged view icon click.
2543 * @param v The view that was clicked.
2544 * @param appInfo The {link AppInfo} of the view.
2545 */
2546 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2547 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2548 startActivitySafely(v, appInfo.intent, appInfo);
2549 getStats().recordLaunch(appInfo.intent);
2550 }
2551
2552 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002553 * Event handler for an app shortcut click.
2554 *
2555 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2556 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002557 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002558 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2559 Object tag = v.getTag();
2560 if (!(tag instanceof ShortcutInfo)) {
2561 throw new IllegalArgumentException("Input must be a Shortcut");
2562 }
2563
2564 // Open shortcut
2565 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2566 final Intent intent = shortcut.intent;
2567
2568 // Check for special shortcuts
2569 if (intent.getComponent() != null) {
2570 final String shortcutClass = intent.getComponent().getClassName();
2571
2572 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2573 MemoryDumpActivity.startDump(this);
2574 return;
2575 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2576 toggleShowWeightWatcher();
2577 return;
2578 }
2579 }
2580
Chris Wren40c5ed32014-06-24 18:24:23 -04002581 // Check for abandoned promise
2582 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002583 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2584 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002585 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002586 builder.setPositiveButton(R.string.abandoned_search,
2587 new DialogInterface.OnClickListener() {
2588 public void onClick(DialogInterface dialog, int id) {
2589 startAppShortcutActivity(v);
2590 }
2591 }
2592 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002593 builder.setNeutralButton(R.string.abandoned_clean_this,
2594 new DialogInterface.OnClickListener() {
2595 public void onClick(DialogInterface dialog, int id) {
2596 final BubbleTextView bubble = (BubbleTextView) v;
2597 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2598 mWorkspace.removeAbandonedPromise(bubble, user);
2599 }
2600 });
2601 builder.create().show();
2602 return;
2603 }
2604
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002605 // Start activities
Chris Wren40c5ed32014-06-24 18:24:23 -04002606 startAppShortcutActivity(v);
2607 }
2608
2609 private void startAppShortcutActivity(View v) {
2610 Object tag = v.getTag();
2611 if (!(tag instanceof ShortcutInfo)) {
2612 throw new IllegalArgumentException("Input must be a Shortcut");
2613 }
2614 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2615 final Intent intent = shortcut.intent;
2616
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617 int[] pos = new int[2];
2618 v.getLocationOnScreen(pos);
2619 intent.setSourceBounds(new Rect(pos[0], pos[1],
2620 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2621
2622 boolean success = startActivitySafely(v, intent, tag);
2623
2624 mStats.recordLaunch(intent, shortcut);
2625
2626 if (success && v instanceof BubbleTextView) {
2627 mWaitingForResume = (BubbleTextView) v;
2628 mWaitingForResume.setStayPressed(true);
2629 }
2630 }
2631
2632 /**
2633 * Event handler for a folder icon click.
2634 *
2635 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2636 */
2637 protected void onClickFolderIcon(View v) {
2638 if (LOGD) Log.d(TAG, "onClickFolder");
2639 if (!(v instanceof FolderIcon)){
2640 throw new IllegalArgumentException("Input must be a FolderIcon");
2641 }
2642
2643 FolderIcon folderIcon = (FolderIcon) v;
2644 final FolderInfo info = folderIcon.getFolderInfo();
2645 Folder openFolder = mWorkspace.getFolderForTag(info);
2646
2647 // If the folder info reports that the associated folder is open, then verify that
2648 // it is actually opened. There have been a few instances where this gets out of sync.
2649 if (info.opened && openFolder == null) {
2650 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2651 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2652 info.opened = false;
2653 }
2654
2655 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2656 // Close any open folder
2657 closeFolder();
2658 // Open the requested folder
2659 openFolder(folderIcon);
2660 } else {
2661 // Find the open folder...
2662 int folderScreen;
2663 if (openFolder != null) {
2664 folderScreen = mWorkspace.getPageForView(openFolder);
2665 // .. and close it
2666 closeFolder(openFolder);
2667 if (folderScreen != mWorkspace.getCurrentPage()) {
2668 // Close any folder open on the current screen
2669 closeFolder();
2670 // Pull the folder onto this screen
2671 openFolder(folderIcon);
2672 }
2673 }
2674 }
Michael Jurka5130e402011-10-13 04:55:35 -07002675 }
2676
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002677 /**
2678 * Event handler for the (Add) Widgets button that appears after a long press
2679 * on the home screen.
2680 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002681 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002682 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002683 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2684 }
2685
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002686 /**
2687 * Event handler for the wallpaper picker button that appears after a long press
2688 * on the home screen.
2689 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002690 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002691 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2692 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2693 pickWallpaper.setComponent(getWallpaperPickerComponent());
2694 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2695 }
2696
2697 /**
2698 * Event handler for a click on the settings button that appears after a long press
2699 * on the home screen.
2700 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002701 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002702 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2703 }
2704
Michael Jurka5130e402011-10-13 04:55:35 -07002705 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002706 // Provide the same haptic feedback that the system offers for virtual keys.
2707 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002708 }
2709
Adam Cohen61f560d2013-09-30 15:58:20 -07002710 public void performHapticFeedbackOnTouchDown(View v) {
2711 // Provide the same haptic feedback that the system offers for virtual keys.
2712 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2713 }
2714
2715 public View.OnTouchListener getHapticFeedbackTouchListener() {
2716 if (mHapticFeedbackTouchListener == null) {
2717 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2718 @Override
2719 public boolean onTouch(View v, MotionEvent event) {
2720 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2721 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2722 }
2723 return false;
2724 }
2725 };
2726 }
2727 return mHapticFeedbackTouchListener;
2728 }
2729
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002730 public void onDragStarted(View view) {}
2731
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002732 /**
2733 * Called when the user stops interacting with the launcher.
2734 * This implies that the user is now on the homescreen and is not doing housekeeping.
2735 */
2736 protected void onInteractionEnd() {}
2737
2738 /**
2739 * Called when the user starts interacting with the launcher.
2740 * The possible interactions are:
2741 * - open all apps
2742 * - reorder an app shortcut, or a widget
2743 * - open the overview mode.
2744 * This is a good time to stop doing things that only make sense
2745 * when the user is on the homescreen and not doing housekeeping.
2746 */
2747 protected void onInteractionBegin() {}
2748
Kenny Guyf07af7b2014-07-31 11:39:16 +01002749 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002750 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002751 try {
2752 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2753 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2754 launcherApps.showAppDetailsForProfile(componentName, user);
2755 } catch (SecurityException e) {
2756 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2757 Log.e(TAG, "Launcher does not have permission to launch settings");
2758 } catch (ActivityNotFoundException e) {
2759 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2760 Log.e(TAG, "Unable to launch settings");
2761 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002762 }
2763
Michael Jurka1e2f4652013-07-08 18:03:46 -07002764 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002765 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2766 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002767 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002768 // System applications cannot be installed. For now, show a toast explaining that.
2769 // We may give them the option of disabling apps this way.
2770 int messageId = R.string.uninstall_system_app_text;
2771 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002772 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002773 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002774 String packageName = componentName.getPackageName();
2775 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002776 Intent intent = new Intent(
2777 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002778 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2779 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002780 if (user != null) {
2781 user.addToIntent(intent, Intent.EXTRA_USER);
2782 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002783 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002784 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002785 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002786 }
2787
Michael Jurka86a720e2012-05-09 11:23:23 -07002788 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002789 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002790 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002791 // Only launch using the new animation if the shortcut has not opted out (this is a
2792 // private contract between launcher and may be ignored in the future).
2793 boolean useLaunchAnimation = (v != null) &&
2794 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002795 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2796 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002797
Kenny Guy1317e2d2014-05-08 18:52:50 +01002798 UserHandleCompat user = null;
2799 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2800 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2801 user = userManager.getUserForSerialNumber(serialNumber);
2802 }
2803
2804 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002805 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002806 ActivityOptions opts = Utilities.isLmp() ?
2807 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2808 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002809 optsBundle = opts.toBundle();
2810 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002811
2812 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2813 // Could be launching some bookkeeping activity
2814 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002815 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002816 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002817 launcherApps.startActivityForProfile(intent.getComponent(), user,
2818 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002819 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002820 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002821 } catch (SecurityException e) {
2822 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002823 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002824 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002825 "or use the exported attribute for this activity. "
2826 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002827 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002828 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002829 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002830
Michael Jurka86a720e2012-05-09 11:23:23 -07002831 boolean startActivitySafely(View v, Intent intent, Object tag) {
2832 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002833 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2834 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2835 return false;
2836 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002837 try {
2838 success = startActivity(v, intent, tag);
2839 } catch (ActivityNotFoundException e) {
2840 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2841 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2842 }
2843 return success;
2844 }
2845
Adam Cohen268c4752012-06-06 17:47:33 -07002846 /**
2847 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2848 * in the DragLayer in the exact absolute location of the original FolderIcon.
2849 */
2850 private void copyFolderIconToImage(FolderIcon fi) {
2851 final int width = fi.getMeasuredWidth();
2852 final int height = fi.getMeasuredHeight();
2853
2854 // Lazy load ImageView, Bitmap and Canvas
2855 if (mFolderIconImageView == null) {
2856 mFolderIconImageView = new ImageView(this);
2857 }
2858 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2859 mFolderIconBitmap.getHeight() != height) {
2860 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2861 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2862 }
2863
2864 DragLayer.LayoutParams lp;
2865 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2866 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2867 } else {
2868 lp = new DragLayer.LayoutParams(width, height);
2869 }
2870
Adam Cohen307fe232012-08-16 17:55:58 -07002871 // The layout from which the folder is being opened may be scaled, adjust the starting
2872 // view size by this scale factor.
2873 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002874 lp.customPosition = true;
2875 lp.x = mRectForFolderAnimation.left;
2876 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002877 lp.width = (int) (scale * width);
2878 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002879
2880 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2881 fi.draw(mFolderIconCanvas);
2882 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002883 if (fi.getFolder() != null) {
2884 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2885 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002886 }
Adam Cohen268c4752012-06-06 17:47:33 -07002887 // Just in case this image view is still in the drag layer from a previous animation,
2888 // we remove it and re-add it.
2889 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2890 mDragLayer.removeView(mFolderIconImageView);
2891 }
2892 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002893 if (fi.getFolder() != null) {
2894 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002895 }
Adam Cohen268c4752012-06-06 17:47:33 -07002896 }
2897
Adam Cohen2801caf2011-05-13 20:57:39 -07002898 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002899 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002900 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2901 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2902 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2903
Adam Cohenc51934b2011-07-26 21:07:43 -07002904 FolderInfo info = (FolderInfo) fi.getTag();
2905 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2906 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002907 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2908 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002909 }
2910
Adam Cohen268c4752012-06-06 17:47:33 -07002911 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2912 copyFolderIconToImage(fi);
2913 fi.setVisibility(View.INVISIBLE);
2914
Michael Jurka2ecf9952012-06-18 12:52:28 -07002915 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002916 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002917 if (Utilities.isLmp()) {
2918 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2919 }
2920 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002921 oa.start();
2922 }
2923
Adam Cohen268c4752012-06-06 17:47:33 -07002924 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002925 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002926 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2927 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2928 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2929
Adam Cohen268c4752012-06-06 17:47:33 -07002930 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002931
Adam Cohen268c4752012-06-06 17:47:33 -07002932 // We remove and re-draw the FolderIcon in-case it has changed
2933 mDragLayer.removeView(mFolderIconImageView);
2934 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002935 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002936 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002937 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002938 oa.addListener(new AnimatorListenerAdapter() {
2939 @Override
2940 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002941 if (cl != null) {
2942 cl.clearFolderLeaveBehind();
2943 // Remove the ImageView copy of the FolderIcon and make the original visible.
2944 mDragLayer.removeView(mFolderIconImageView);
2945 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002946 }
2947 }
2948 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002949 oa.start();
2950 }
2951
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002952 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002953 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002954 * is animated relative to the specified View. If the View is null, no animation
2955 * is played.
2956 *
2957 * @param folderInfo The FolderInfo describing the folder to open.
2958 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002959 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002960 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002961 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002962
Adam Cohena9cf38f2011-05-02 15:36:58 -07002963 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002964
Adam Cohen4554ee12011-08-03 16:13:21 -07002965 // Just verify that the folder hasn't already been added to the DragLayer.
2966 // There was a one-off crash where the folder had a parent already.
2967 if (folder.getParent() == null) {
2968 mDragLayer.addView(folder);
2969 mDragController.addDropTarget((DropTarget) folder);
2970 } else {
2971 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2972 folder.getParent() + ").");
2973 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002974 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002975 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002976
2977 // Notify the accessibility manager that this folder "window" has appeared and occluded
2978 // the workspace items
2979 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2980 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002981 }
2982
2983 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002984 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002985 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002986 if (folder.isEditingName()) {
2987 folder.dismissEditingName();
2988 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002989 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002990
2991 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002992 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002993 }
2994 }
2995
2996 void closeFolder(Folder folder) {
2997 folder.getInfo().opened = false;
2998
2999 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3000 if (parent != null) {
3001 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3002 shrinkAndFadeInFolderIcon(fi);
3003 }
3004 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003005
3006 // Notify the accessibility manager that this folder "window" has disappeard and no
3007 // longer occludeds the workspace items
3008 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003009 }
3010
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003011 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003012 if (!isDraggingEnabled()) return false;
3013 if (isWorkspaceLocked()) return false;
3014 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003015
Adam Cohen1697b792013-09-17 19:08:21 -07003016 if (v instanceof Workspace) {
3017 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003018 if (mWorkspace.enterOverviewMode()) {
3019 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3020 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3021 return true;
3022 } else {
3023 return false;
3024 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003025 } else {
3026 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003027 }
Adam Cohen1697b792013-09-17 19:08:21 -07003028 }
3029
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003030 CellLayout.CellInfo longClickCellInfo = null;
3031 View itemUnderLongClick = null;
3032 if (v.getTag() instanceof ItemInfo) {
3033 ItemInfo info = (ItemInfo) v.getTag();
3034 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3035 itemUnderLongClick = longClickCellInfo.cell;
3036 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003037 }
3038
Winson Chung3d503fb2011-07-13 17:25:49 -07003039 // The hotseat touch handling does not go through Workspace, and we always allow long press
3040 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003041 final boolean inHotseat = isHotseatLayout(v);
3042 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003043 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003044 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003045 // User long pressed on empty space
3046 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3047 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003048 if (mWorkspace.isInOverviewMode()) {
3049 mWorkspace.startReordering(v);
3050 } else {
3051 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003052 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003053 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003054 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3055 mHotseat.getOrderInHotseat(
3056 longClickCellInfo.cellX,
3057 longClickCellInfo.cellY));
3058 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003059 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003060 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003061 }
3062 }
3063 }
3064 return true;
3065 }
3066
Winson Chung3d503fb2011-07-13 17:25:49 -07003067 boolean isHotseatLayout(View layout) {
3068 return mHotseat != null && layout != null &&
3069 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3070 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003071
Winson Chung3d503fb2011-07-13 17:25:49 -07003072 /**
3073 * Returns the CellLayout of the specified container at the specified screen.
3074 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003075 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003076 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3077 if (mHotseat != null) {
3078 return mHotseat.getLayout();
3079 } else {
3080 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003081 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003082 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003083 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003084 }
3085 }
3086
Daniel Sandler843e8602010-06-07 14:59:01 -04003087 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003088 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003089 }
3090
Craig Mautner360310b2012-10-26 15:13:08 -07003091 private void setWorkspaceBackground(boolean workspace) {
3092 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003093 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003094 }
3095
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003096 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003097 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3098 int curflags = getWindow().getAttributes().flags
3099 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3100 if (wpflags != curflags) {
3101 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3102 }
Craig Mautner360310b2012-10-26 15:13:08 -07003103 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003104 }
3105
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003106 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3107 if (v instanceof LauncherTransitionable) {
3108 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3109 }
3110 }
3111
Michael Jurkabed61d22012-02-14 22:51:29 -08003112 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3113 if (v instanceof LauncherTransitionable) {
3114 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3115 }
Winson Chung70442722012-02-10 15:43:22 -08003116
3117 // Update the workspace transition step as well
3118 dispatchOnLauncherTransitionStep(v, 0f);
3119 }
3120
3121 private void dispatchOnLauncherTransitionStep(View v, float t) {
3122 if (v instanceof LauncherTransitionable) {
3123 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3124 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003125 }
3126
3127 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3128 if (v instanceof LauncherTransitionable) {
3129 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3130 }
Winson Chung70442722012-02-10 15:43:22 -08003131
3132 // Update the workspace transition step as well
3133 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003134 }
3135
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003136 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003137 * Things to test when changing the following seven functions.
3138 * - Home from workspace
3139 * - from center screen
3140 * - from other screens
3141 * - Home from all apps
3142 * - from center screen
3143 * - from other screens
3144 * - Back from all apps
3145 * - from center screen
3146 * - from other screens
3147 * - Launch app from workspace and quit
3148 * - with back
3149 * - with home
3150 * - Launch app from all apps and quit
3151 * - with back
3152 * - with home
3153 * - Go to a screen that's not the default, then all
3154 * apps, and launch and app, and go back
3155 * - with back
3156 * -with home
3157 * - On workspace, long press power and go back
3158 * - with back
3159 * - with home
3160 * - On all apps, long press power and go back
3161 * - with back
3162 * - with home
3163 * - On workspace, power off
3164 * - On all apps, power off
3165 * - Launch an app and turn off the screen while in that app
3166 * - Go back with home key
3167 * - Go back with back key TODO: make this not go to workspace
3168 * - From all apps
3169 * - From workspace
3170 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3171 * - From all apps
3172 * - From the center workspace
3173 * - From another workspace
3174 */
3175
3176 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003177 * Zoom the camera out from the workspace to reveal 'toView'.
3178 * Assumes that the view to show is anchored at either the very top or very bottom
3179 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003180 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003181 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003182 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3183 showAppsCustomizeHelper(animated, springLoaded, contentType);
3184 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003185
Winson Chungc58497e2013-09-03 17:48:37 -07003186 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3187 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003188 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003189 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003190 mStateAnimation.cancel();
3191 mStateAnimation = null;
3192 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003193
3194 boolean material = Utilities.isLmp();
3195
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003196 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003197
Winson Chungf0ea4d32011-06-06 14:27:16 -07003198 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3199 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003200 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003201 final int itemsAlphaStagger =
3202 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003203
Winson Chungf0ea4d32011-06-06 14:27:16 -07003204 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003205 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003206 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003207
Adam Cohen6c5891a2014-07-09 23:53:15 -07003208 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3209 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003210 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003211 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003212 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003213 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3214 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003215 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3216 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003217
3218 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003219 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003220
Adam Cohen9bfdb762014-07-21 17:44:06 -07003221 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3222 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003223
Adam Cohen9bfdb762014-07-21 17:44:06 -07003224 final View page = content.getPageAt(content.getCurrentPage());
3225 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003226
Adam Cohen63f1ec02014-08-12 09:23:13 -07003227 final float initialPanelAlpha = 1f;
3228
3229 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3230 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003231 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3232 } else {
3233 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3234 }
3235
Adam Cohen9bfdb762014-07-21 17:44:06 -07003236 // Hide the real page background, and swap in the fake one
3237 revealView.setVisibility(View.VISIBLE);
3238 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003239
Adam Cohen9bfdb762014-07-21 17:44:06 -07003240 int width = revealView.getMeasuredWidth();
3241 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003242
Adam Cohen9bfdb762014-07-21 17:44:06 -07003243 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003244 revealView.setTranslationY(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003245
Adam Cohen63f1ec02014-08-12 09:23:13 -07003246 // Get the y delta between the center of the page and the center of the all apps button
3247 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3248 getAllAppsButton(), null);
3249 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3250
3251 float initAlpha = isWidgetTray ? 0.3f : 1f;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003252 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003253 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003254 PropertyValuesHolder panelDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003255 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003256
Adam Cohen9bfdb762014-07-21 17:44:06 -07003257 ObjectAnimator panelAlphaAndDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003258 LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003259 panelAlphaAndDrift.setDuration(revealDuration);
3260 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003261
Adam Cohen9bfdb762014-07-21 17:44:06 -07003262 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003263
Adam Cohen4e243a22014-08-10 18:30:55 -07003264 if (page != null) {
3265 page.setVisibility(View.VISIBLE);
3266 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003267
Adam Cohen63f1ec02014-08-12 09:23:13 -07003268 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0);
Adam Cohen4e243a22014-08-10 18:30:55 -07003269 pageDrift.setDuration(revealDuration);
3270 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003271 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003272 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003273
Adam Cohen63f1ec02014-08-12 09:23:13 -07003274 page.setAlpha(0f);
3275 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003276 itemsAlpha.setDuration(revealDuration);
3277 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3278 itemsAlpha.setStartDelay(itemsAlphaStagger);
3279 mStateAnimation.play(itemsAlpha);
3280 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003281
Adam Cohen4e243a22014-08-10 18:30:55 -07003282 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3283 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003284 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003285 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003286 indicatorsAlpha.setDuration(revealDuration);
3287 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003288
Adam Cohen9bfdb762014-07-21 17:44:06 -07003289 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003290 final View allApps = getAllAppsButton();
3291 int allAppsButtonSize = LauncherAppState.getInstance().
3292 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3293 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003294 Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003295 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003296 reveal.setDuration(revealDuration);
3297 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003298
3299 reveal.addListener(new AnimatorListenerAdapter() {
3300 public void onAnimationStart(Animator animation) {
3301 if (!isWidgetTray) {
3302 allApps.setVisibility(View.INVISIBLE);
3303 }
3304 }
3305 public void onAnimationEnd(Animator animation) {
3306 if (!isWidgetTray) {
3307 allApps.setVisibility(View.VISIBLE);
3308 }
3309 }
3310 });
3311
Adam Cohen6c5891a2014-07-09 23:53:15 -07003312 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003313 }
Michael Jurka1899a362011-11-03 13:50:45 -07003314
Adam Cohen9bfdb762014-07-21 17:44:06 -07003315 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3316 @Override
3317 public void onAnimationEnd(Animator animation) {
3318 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3319 dispatchOnLauncherTransitionEnd(toView, animated, false);
3320
3321 revealView.setVisibility(View.INVISIBLE);
3322 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003323 if (page != null) {
3324 page.setLayerType(View.LAYER_TYPE_NONE, null);
3325 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003326 content.setPageBackgroundsVisible(true);
3327
3328 // Hide the search bar
3329 if (mSearchDropTargetBar != null) {
3330 mSearchDropTargetBar.hideSearchBar(false);
3331 }
3332 }
3333
3334 @Override
3335 public void onAnimationStart(Animator animation) {
3336 // Prepare the position
3337 toView.bringToFront();
3338 toView.setVisibility(View.VISIBLE);
3339 }
3340 });
3341
Michael Jurka1899a362011-11-03 13:50:45 -07003342 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003343 if (workspaceAnim != null) {
3344 mStateAnimation.play(workspaceAnim);
3345 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003346 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3347 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003348
3349 // If any of the objects being animated haven't been measured/laid out
3350 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003351 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003352 (mWorkspace.getMeasuredWidth() == 0) ||
3353 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003354 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003355 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003356
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003357 final AnimatorSet stateAnimation = mStateAnimation;
3358 final Runnable startAnimRunnable = new Runnable() {
3359 public void run() {
3360 // Check that mStateAnimation hasn't changed while
3361 // we waited for a layout/draw pass
3362 if (mStateAnimation != stateAnimation)
3363 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003364 dispatchOnLauncherTransitionStart(fromView, animated, false);
3365 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003366 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003367 }
3368 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003369 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003370 toView.bringToFront();
3371 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003372 final ViewTreeObserver observer = toView.getViewTreeObserver();
3373 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3374 public void onGlobalLayout() {
3375 startAnimRunnable.run();
3376 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3377 }
3378 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003379 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003380 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003381 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003382 } else {
3383 toView.setTranslationX(0.0f);
3384 toView.setTranslationY(0.0f);
3385 toView.setScaleX(1.0f);
3386 toView.setScaleY(1.0f);
3387 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003388 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003389
Daniel Sandlere4f98912013-06-25 15:13:26 -04003390 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003391 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003392 if (mSearchDropTargetBar != null) {
3393 mSearchDropTargetBar.hideSearchBar(false);
3394 }
Michael Jurkaabded662011-03-04 12:06:57 -08003395 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003396 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003397 dispatchOnLauncherTransitionStart(fromView, animated, false);
3398 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003399 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003400 dispatchOnLauncherTransitionStart(toView, animated, false);
3401 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003402 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003403 }
3404
3405 /**
3406 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003407 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003408 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003409 */
Adam Cohened307df2013-10-02 09:37:31 -07003410 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003411 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003412
Michael Jurkab3e22d92011-10-31 15:58:33 -07003413 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003414 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003415 mStateAnimation.cancel();
3416 mStateAnimation = null;
3417 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003418
3419 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003420 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003421
Winson Chungf0ea4d32011-06-06 14:27:16 -07003422 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003423 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003424 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003425 final int itemsAlphaStagger =
3426 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003427
Winson Chungf0ea4d32011-06-06 14:27:16 -07003428 final float scaleFactor = (float)
3429 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3430 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003431 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003432 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003433 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003434 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen63f1ec02014-08-12 09:23:13 -07003435 toState, animated);
Adam Cohened307df2013-10-02 09:37:31 -07003436 } else if (toState == Workspace.State.SPRING_LOADED ||
3437 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003438 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003439 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003440 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003441
Winson Chung4afe9b32011-07-27 17:46:20 -07003442 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003443 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003444 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003445
Adam Cohen9bfdb762014-07-21 17:44:06 -07003446 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3447 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003448
Adam Cohen9bfdb762014-07-21 17:44:06 -07003449 final View page = content.getPageAt(content.getNextPage());
3450 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003451
Adam Cohen4e243a22014-08-10 18:30:55 -07003452 AppsCustomizePagedView.ContentType contentType = content.getContentType();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003453 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3454
3455 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003456 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3457 } else {
3458 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3459 }
3460
Adam Cohen9bfdb762014-07-21 17:44:06 -07003461 int width = revealView.getMeasuredWidth();
3462 int height = revealView.getMeasuredHeight();
3463 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003464
Adam Cohen9bfdb762014-07-21 17:44:06 -07003465 // Hide the real page background, and swap in the fake one
3466 revealView.setVisibility(View.VISIBLE);
3467 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003468
Adam Cohen63f1ec02014-08-12 09:23:13 -07003469 final View allAppsButton = getAllAppsButton();
3470 revealView.setTranslationY(0);
3471 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3472 allAppsButton, null);
3473 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen6c5891a2014-07-09 23:53:15 -07003474
Adam Cohen9bfdb762014-07-21 17:44:06 -07003475 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003476
Adam Cohen63f1ec02014-08-12 09:23:13 -07003477 // The vertical motion of the apps panel should be delayed by one frame
3478 // from the conceal animation in order to give the right feel. We correpsondingly
3479 // shorten the duration so that the slide and conceal end at the same time.
3480 ObjectAnimator panelDrift = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
3481 panelDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3482 panelDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3483 panelDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3484 mStateAnimation.play(panelDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003485
Adam Cohen63f1ec02014-08-12 09:23:13 -07003486 if (isWidgetTray) {
3487 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f);
3488 panelAlpha.setDuration(revealDuration);
3489 panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3490 mStateAnimation.play(panelAlpha);
3491 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003492
Adam Cohen4e243a22014-08-10 18:30:55 -07003493 if (page != null) {
3494 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003495
Adam Cohen63f1ec02014-08-12 09:23:13 -07003496 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3497 0, yDrift);
3498 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003499 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003500 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003501 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003502
Adam Cohen4e243a22014-08-10 18:30:55 -07003503 page.setAlpha(1f);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003504 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3505 itemsAlpha.setDuration(100);
Adam Cohen4e243a22014-08-10 18:30:55 -07003506 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3507 mStateAnimation.play(itemsAlpha);
3508 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003509
Adam Cohen9bfdb762014-07-21 17:44:06 -07003510 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003511 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003512 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003513 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003514 indicatorsAlpha.setDuration(revealDuration);
3515 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3516 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003517
Adam Cohen9bfdb762014-07-21 17:44:06 -07003518 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003519
Adam Cohen9bfdb762014-07-21 17:44:06 -07003520 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003521 if (!isWidgetTray) {
3522 allAppsButton.setVisibility(View.INVISIBLE);
3523 }
3524 int allAppsButtonSize = LauncherAppState.getInstance().
3525 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3526 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003527 Animator reveal =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003528 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3529 height / 2, revealRadius, finalRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003530 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3531 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003532 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003533
3534 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003535 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003536 revealView.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003537 if (!isWidgetTray) {
3538 allAppsButton.setVisibility(View.VISIBLE);
3539 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003540 }
3541 });
3542
Adam Cohen6c5891a2014-07-09 23:53:15 -07003543 mStateAnimation.play(reveal);
3544 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003545
3546 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3547 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3548 mAppsCustomizeContent.stopScrolling();
3549
Adam Cohen6c5891a2014-07-09 23:53:15 -07003550 if (workspaceAnim != null) {
3551 mStateAnimation.play(workspaceAnim);
3552 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003553
3554 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003555 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003556 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003557 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003558 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3559 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003560 if (onCompleteRunnable != null) {
3561 onCompleteRunnable.run();
3562 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003563
3564 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003565 if (page != null) {
3566 page.setLayerType(View.LAYER_TYPE_NONE, null);
3567 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003568 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003569 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003570 }
3571 });
3572
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003573 dispatchOnLauncherTransitionStart(fromView, animated, true);
3574 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003575 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003576 } else {
3577 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003578 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003579 dispatchOnLauncherTransitionStart(fromView, animated, true);
3580 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003581 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003582 dispatchOnLauncherTransitionStart(toView, animated, true);
3583 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003584 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003585 }
3586
Michael Jurkae326f182011-11-21 14:05:46 -08003587 @Override
3588 public void onTrimMemory(int level) {
3589 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003590 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003591 mAppsCustomizeTabHost.onTrimMemory();
3592 }
3593 }
3594
Adam Cohened307df2013-10-02 09:37:31 -07003595 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003596 showWorkspace(animated, null);
3597 }
3598
Adam Cohened307df2013-10-02 09:37:31 -07003599 protected void showWorkspace() {
3600 showWorkspace(true);
3601 }
3602
Adam Cohened66b2b2012-01-23 17:28:51 -08003603 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003604 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003605 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003606 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003607 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003608
Winson Chungc7d2b602012-05-16 17:02:20 -07003609 // Show the search bar (only animate if we were showing the drop target bar in spring
3610 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003611 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003612 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003613 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003614
Michael Jurkab3e22d92011-10-31 15:58:33 -07003615 // Set focus to the AppsCustomize button
3616 if (mAllAppsButton != null) {
3617 mAllAppsButton.requestFocus();
3618 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003619 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003620
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003621 // Change the state *after* we've called all the transition code
3622 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003623
Winson Chung5fb63472011-02-02 17:03:37 -08003624 // Resume the auto-advance of widgets
3625 mUserPresent = true;
3626 updateRunning();
3627
alanv1d4fde62012-10-17 13:15:47 -07003628 // Send an accessibility event to announce the context change
3629 getWindow().getDecorView()
3630 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003631
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003632 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003633 }
3634
Adam Cohened307df2013-10-02 09:37:31 -07003635 void showOverviewMode(boolean animated) {
3636 mWorkspace.setVisibility(View.VISIBLE);
3637 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3638 mState = State.WORKSPACE;
3639 onWorkspaceShown(animated);
3640 }
3641
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003642 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003643 }
3644
Winson Chung82963d52013-10-09 11:20:57 -07003645 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3646 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003647 if (mState != State.WORKSPACE) return;
3648
Winson Chung82963d52013-10-09 11:20:57 -07003649 if (resetPageToZero) {
3650 mAppsCustomizeTabHost.reset();
3651 }
Winson Chungc58497e2013-09-03 17:48:37 -07003652 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003653 mAppsCustomizeTabHost.post(new Runnable() {
3654 @Override
3655 public void run() {
3656 // We post this in-case the all apps view isn't yet constructed.
3657 mAppsCustomizeTabHost.requestFocus();
3658 }
3659 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003660
Michael Jurkab3e22d92011-10-31 15:58:33 -07003661 // Change the state *after* we've called all the transition code
3662 mState = State.APPS_CUSTOMIZE;
3663
3664 // Pause the auto-advance of widgets until we are out of AllApps
3665 mUserPresent = false;
3666 updateRunning();
3667 closeFolder();
3668
3669 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003670 getWindow().getDecorView()
3671 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003672 }
3673
Adam Cohen7777d962011-08-18 18:58:38 -07003674 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003675 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003676 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003677 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003678 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003679 }
Adam Cohen7777d962011-08-18 18:58:38 -07003680
Adam Cohenad4e15c2013-10-17 16:21:35 -07003681 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003682 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003683 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3684
Winson Chunge7a03942011-08-05 15:05:12 -07003685 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003686 @Override
3687 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003688 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003689 // Before we show workspace, hide all apps again because
3690 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3691 // clean up our state transition functions
3692 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003693 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003694 } else {
3695 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003696 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003697 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003698 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003699 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003700
Michael Jurkad3ef3062010-11-23 16:23:58 -08003701 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003702 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003703 final boolean animated = true;
3704 final boolean springLoaded = true;
3705 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003706 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003707 }
3708 // Otherwise, we are not in spring loaded mode, so don't do anything.
3709 }
3710
Michael Jurkab3e22d92011-10-31 15:58:33 -07003711 void lockAllApps() {
3712 // TODO
3713 }
3714
3715 void unlockAllApps() {
3716 // TODO
3717 }
3718
Winson Chungf0ea4d32011-06-06 14:27:16 -07003719 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003720 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003721 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003722 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003723 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003724 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003725 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003726 int duration = 0;
3727 if (mSearchDropTargetBar != null) {
3728 duration = mSearchDropTargetBar.getTransitionInDuration();
3729 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003730 mHotseat.animate().alpha(1f).setDuration(duration);
3731 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003732 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003733 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003734 }
3735 }
3736 }
3737
3738 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003739 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003740 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003741 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003742 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003743 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003744 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003745 int duration = 0;
3746 if (mSearchDropTargetBar != null) {
3747 duration = mSearchDropTargetBar.getTransitionOutDuration();
3748 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003749 mHotseat.animate().alpha(0f).setDuration(duration);
3750 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003751 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003752 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003753 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003754 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003755 }
3756
Patrick Dubroy5f445422011-02-18 14:35:21 -08003757 /**
3758 * Add an item from all apps or customize onto the given workspace screen.
3759 * If layout is null, add to the current screen.
3760 */
3761 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003762 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003763 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003764 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003765 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003766
Winson Chungdff8ebb2011-09-08 17:25:31 -07003767 /** Maps the current orientation to an index for referencing orientation correct global icons */
3768 private int getCurrentOrientationIndexForGlobalIcons() {
3769 // default - 0, landscape - 1
3770 switch (getResources().getConfiguration().orientation) {
3771 case Configuration.ORIENTATION_LANDSCAPE:
3772 return 1;
3773 default:
3774 return 0;
3775 }
3776 }
3777
Michael Jurkaae65ee32012-04-30 11:45:54 -07003778 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003779 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003780 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003781 // Look for the toolbar icon specified in the activity meta-data
3782 Bundle metaData = packageManager.getActivityInfo(
3783 activityName, PackageManager.GET_META_DATA).metaData;
3784 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003785 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003786 if (iconResId != 0) {
3787 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003788 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003789 }
3790 }
3791 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003792 // This can happen if the activity defines an invalid drawable
3793 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3794 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003795 } catch (Resources.NotFoundException nfe) {
3796 // This can happen if the activity defines an invalid drawable
3797 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3798 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003799 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003800 return null;
3801 }
3802
3803 // if successful in getting icon, return it; otherwise, set button to use default drawable
3804 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003805 int buttonId, ComponentName activityName, int fallbackDrawableId,
3806 String toolbarResourceName) {
3807 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003808 Resources r = getResources();
3809 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3810 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003811
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003812 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003813 // If we were unable to find the icon via the meta-data, use a generic one
3814 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003815 toolbarIcon = r.getDrawable(fallbackDrawableId);
3816 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003817 if (button != null) {
3818 button.setCompoundDrawables(toolbarIcon, null, null, null);
3819 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003820 return null;
3821 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003822 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003823 if (button != null) {
3824 button.setCompoundDrawables(toolbarIcon, null, null, null);
3825 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003826 return toolbarIcon.getConstantState();
3827 }
3828 }
3829
3830 // if successful in getting icon, return it; otherwise, set button to use default drawable
3831 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003832 int buttonId, ComponentName activityName, int fallbackDrawableId,
3833 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003834 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003835 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003836
Michael Jurka19e0fc52011-07-22 18:00:21 -07003837 if (button != null) {
3838 // If we were unable to find the icon via the meta-data, use a
3839 // generic one
3840 if (toolbarIcon == null) {
3841 button.setImageResource(fallbackDrawableId);
3842 } else {
3843 button.setImageDrawable(toolbarIcon);
3844 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003845 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003846
3847 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3848
Michael Jurka0423dcf2010-10-05 14:56:18 -07003849 }
3850
Winson Chung1b884092012-06-08 17:13:02 -07003851 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003852 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003853 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003854 }
3855
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003856 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003857 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003858 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003859 }
3860
Winson Chungbb185bd2011-11-21 12:31:42 -08003861 private void invalidatePressedFocusedStates(View container, View button) {
3862 if (container instanceof HolographicLinearLayout) {
3863 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3864 layout.invalidatePressedFocusedStates();
3865 } else if (button instanceof HolographicImageView) {
3866 HolographicImageView view = (HolographicImageView) button;
3867 view.invalidatePressedFocusedStates();
3868 }
3869 }
3870
Cristina Stancu476493b2013-08-07 17:20:14 +01003871 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003872 if (mQsb == null) {
3873 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3874 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003875 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003876 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003877 }
3878
3879 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003880 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003881 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003882 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003883 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003884
Winson Chung1cad91e2011-05-25 17:41:01 -07003885 final SearchManager searchManager =
3886 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3887 ComponentName activityName = searchManager.getGlobalSearchActivity();
3888 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003889 int coi = getCurrentOrientationIndexForGlobalIcons();
3890 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003891 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3892 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3893 if (sGlobalSearchIcon[coi] == null) {
3894 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3895 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3896 TOOLBAR_ICON_METADATA_NAME);
3897 }
3898
Winson Chungc51db6a2011-10-05 11:44:49 -07003899 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3900 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003901 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003902 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003903 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003904 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003905 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3906 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003907 if (searchButton != null) searchButton.setVisibility(View.GONE);
3908 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003909 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003910 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003911 }
3912 }
3913
Cristina Stancu476493b2013-08-07 17:20:14 +01003914 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003915 final View searchButtonContainer = findViewById(R.id.search_button_container);
3916 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003917 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003918 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003919 }
3920
Cristina Stancu476493b2013-08-07 17:20:14 +01003921 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003922 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003923 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003924
Winson Chungc51db6a2011-10-05 11:44:49 -07003925 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003926 final SearchManager searchManager =
3927 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3928 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3929
3930 ComponentName activityName = null;
3931 if (globalSearchActivity != null) {
3932 // Check if the global search activity handles voice search
3933 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3934 intent.setPackage(globalSearchActivity.getPackageName());
3935 activityName = intent.resolveActivity(getPackageManager());
3936 }
3937
3938 if (activityName == null) {
3939 // Fallback: check if an activity other than the global search activity
3940 // resolves this
3941 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3942 activityName = intent.resolveActivity(getPackageManager());
3943 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003944 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003945 int coi = getCurrentOrientationIndexForGlobalIcons();
3946 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003947 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3948 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3949 if (sVoiceSearchIcon[coi] == null) {
3950 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3951 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3952 TOOLBAR_ICON_METADATA_NAME);
3953 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003954 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003955 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003956 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003957 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003958 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003959 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003960 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003961 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003962 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003963 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003964 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003965 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003966
Cristina Stancu476493b2013-08-07 17:20:14 +01003967 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003968 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3969 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003970 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003971 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003972 }
3973
Winson Chung5841efa2013-09-30 18:06:44 -07003974 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003975 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3976 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003977 boolean visible = !forceDisableVoiceButtonProxy &&
3978 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003979 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003980 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003981 }
3982 }
Winson Chung5841efa2013-09-30 18:06:44 -07003983
3984 /**
3985 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3986 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3987 */
3988 public void disableVoiceButtonProxy(boolean disabled) {
3989 updateVoiceButtonProxyVisible(disabled);
3990 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003991
Michael Jurkad7c28052012-04-27 15:43:36 -07003992 @Override
3993 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003994 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003995 final List<CharSequence> text = event.getText();
3996 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003997 // Populate event with a fake title based on the current state.
3998 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003999 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004000 } else {
4001 text.add(getString(R.string.all_apps_home_button_label));
4002 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004003 return result;
4004 }
4005
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004006 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004007 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004008 */
4009 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4010 @Override
4011 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004012 closeSystemDialogs();
4013 }
4014 }
4015
4016 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004017 * Receives notifications whenever the appwidgets are reset.
4018 */
4019 private class AppWidgetResetObserver extends ContentObserver {
4020 public AppWidgetResetObserver() {
4021 super(new Handler());
4022 }
4023
4024 @Override
4025 public void onChange(boolean selfChange) {
4026 onAppWidgetReset();
4027 }
4028 }
4029
4030 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004031 * If the activity is currently paused, signal that we need to run the passed Runnable
4032 * in onResume.
4033 *
4034 * This needs to be called from incoming places where resources might have been loaded
4035 * while we are paused. That is becaues the Configuration might be wrong
4036 * when we're not running, and if it comes back to what it was when we
4037 * were paused, we are not restarted.
4038 *
4039 * Implementation of the method from LauncherModel.Callbacks.
4040 *
4041 * @return true if we are currently paused. The caller might be able to
4042 * skip some work in that case since we will come back again.
4043 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004044 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004045 if (mPaused) {
4046 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004047 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004048 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004049 }
4050 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004051 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004052 return true;
4053 } else {
4054 return false;
4055 }
4056 }
4057
Michael Jurkac402cd92013-05-20 15:49:32 +02004058 private boolean waitUntilResume(Runnable run) {
4059 return waitUntilResume(run, false);
4060 }
4061
Michael Jurka1e2f4652013-07-08 18:03:46 -07004062 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004063 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004064 }
4065
Michael Jurka7607c2f2013-04-03 14:33:19 -07004066 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004067 * If the activity is currently paused, signal that we need to re-run the loader
4068 * in onResume.
4069 *
4070 * This needs to be called from incoming places where resources might have been loaded
4071 * while we are paused. That is becaues the Configuration might be wrong
4072 * when we're not running, and if it comes back to what it was when we
4073 * were paused, we are not restarted.
4074 *
4075 * Implementation of the method from LauncherModel.Callbacks.
4076 *
4077 * @return true if we are currently paused. The caller might be able to
4078 * skip some work in that case since we will come back again.
4079 */
4080 public boolean setLoadOnResume() {
4081 if (mPaused) {
4082 Log.i(TAG, "setLoadOnResume");
4083 mOnResumeNeedsLoad = true;
4084 return true;
4085 } else {
4086 return false;
4087 }
4088 }
4089
4090 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004091 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004092 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004093 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004094 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004095 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004096 } else {
4097 return SCREEN_COUNT / 2;
4098 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004099 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004100
Joe Onorato9c1289c2009-08-17 11:03:03 -04004101 /**
4102 * Refreshes the shortcuts shown on the workspace.
4103 *
4104 * Implementation of the method from LauncherModel.Callbacks.
4105 */
4106 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004107 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004108
Michael Jurka7607c2f2013-04-03 14:33:19 -07004109 // If we're starting binding all over again, clear any bind calls we'd postponed in
4110 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4111 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004112 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004113
Winson Chungd64d1762013-08-20 14:37:16 -07004114 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004115 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004116 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004117
Michael Jurka05bf6442011-11-30 20:28:53 -08004118 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004119 if (mHotseat != null) {
4120 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004121 }
4122 }
4123
Adam Cohendcd297f2013-06-18 13:13:40 -07004124 @Override
4125 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004126 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004127
Adam Cohen5084cba2013-09-03 12:01:16 -07004128 // If there are no screens, we need to have an empty screen
4129 if (orderedScreenIds.size() == 0) {
4130 mWorkspace.addExtraEmptyScreen();
4131 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004132
4133 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004134 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004135 if (hasCustomContentToLeft()) {
4136 mWorkspace.createCustomContentContainer();
4137 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004138 }
Winson Chung64359a52013-07-08 17:17:08 -07004139 }
4140
4141 @Override
4142 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004143 // Log to disk
4144 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4145 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4146 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004147 int count = orderedScreenIds.size();
4148 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004149 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004150 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004151 }
4152
Adam Cohen39a06042013-07-19 14:30:12 -07004153 private boolean shouldShowWeightWatcher() {
4154 String spKey = LauncherAppState.getSharedPreferencesKey();
4155 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004156 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004157
4158 return show;
4159 }
4160
4161 private void toggleShowWeightWatcher() {
4162 String spKey = LauncherAppState.getSharedPreferencesKey();
4163 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4164 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4165
4166 show = !show;
4167
4168 SharedPreferences.Editor editor = sp.edit();
4169 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4170 editor.commit();
4171
4172 if (mWeightWatcher != null) {
4173 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4174 }
4175 }
4176
Winson Chungd64d1762013-08-20 14:37:16 -07004177 public void bindAppsAdded(final ArrayList<Long> newScreens,
4178 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004179 final ArrayList<ItemInfo> addAnimated,
4180 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004181 Runnable r = new Runnable() {
4182 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004183 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004184 }
4185 };
4186 if (waitUntilResume(r)) {
4187 return;
4188 }
4189
Winson Chungd64d1762013-08-20 14:37:16 -07004190 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004191 if (newScreens != null) {
4192 bindAddScreens(newScreens);
4193 }
Winson Chungd64d1762013-08-20 14:37:16 -07004194
4195 // We add the items without animation on non-visible pages, and with
4196 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004197 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004198 bindItems(addNotAnimated, 0,
4199 addNotAnimated.size(), false);
4200 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004201 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004202 bindItems(addAnimated, 0,
4203 addAnimated.size(), true);
4204 }
Winson Chungc58497e2013-09-03 17:48:37 -07004205
Winson Chung87412982013-10-03 18:34:14 -07004206 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004207 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004208
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004209 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004210 addedApps != null && mAppsCustomizeContent != null) {
4211 mAppsCustomizeContent.addApps(addedApps);
4212 }
Winson Chungd64d1762013-08-20 14:37:16 -07004213 }
4214
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004215 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004216 * Bind the items start-end from the list.
4217 *
4218 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004219 */
Winson Chung64359a52013-07-08 17:17:08 -07004220 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4221 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004222 Runnable r = new Runnable() {
4223 public void run() {
4224 bindItems(shortcuts, start, end, forceAnimateIcons);
4225 }
4226 };
4227 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004228 return;
4229 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004230
Winson Chungf0c6ae02012-03-21 16:10:31 -07004231 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004232 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4233 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004234 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004235 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004236 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004237 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004238 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004239
4240 // Short circuit if we are loading dock items for a configuration which has no dock
4241 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4242 mHotseat == null) {
4243 continue;
4244 }
4245
Joe Onorato9c1289c2009-08-17 11:03:03 -04004246 switch (item.itemType) {
4247 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4248 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004249 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004250 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004251
Winson Chung64359a52013-07-08 17:17:08 -07004252 /*
4253 * TODO: FIX collision case
4254 */
Winson Chungce376632013-07-11 16:12:41 -07004255 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4256 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4257 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004258 View v = cl.getChildAt(item.cellX, item.cellY);
4259 Object tag = v.getTag();
4260 String desc = "Collision while binding workspace item: " + item
4261 + ". Collides with " + tag;
4262 if (LauncherAppState.isDogfoodBuild()) {
4263 throw (new RuntimeException(desc));
4264 } else {
4265 Log.d(TAG, desc);
4266 }
Winson Chungce376632013-07-11 16:12:41 -07004267 }
Winson Chung64359a52013-07-08 17:17:08 -07004268 }
4269
Adam Cohendcd297f2013-06-18 13:13:40 -07004270 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4271 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004272 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004273 // Animate all the applications up now
4274 shortcut.setAlpha(0f);
4275 shortcut.setScaleX(0f);
4276 shortcut.setScaleY(0f);
4277 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004278 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004279 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004280 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004281 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004282 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004283 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004284 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004285 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4286 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004287 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004288 default:
4289 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004290 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004291 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004292
Winson Chung997a9232013-07-24 15:33:46 -07004293 if (animateIcons) {
4294 // Animate to the correct page
4295 if (newShortcutsScreenId > -1) {
4296 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004297 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004298 final Runnable startBounceAnimRunnable = new Runnable() {
4299 public void run() {
4300 anim.playTogether(bounceAnims);
4301 anim.start();
4302 }
4303 };
Winson Chung997a9232013-07-24 15:33:46 -07004304 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004305 // We post the animation slightly delayed to prevent slowdowns
4306 // when we are loading right after we return to launcher.
4307 mWorkspace.postDelayed(new Runnable() {
4308 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004309 if (mWorkspace != null) {
4310 mWorkspace.snapToPage(newScreenIndex);
4311 mWorkspace.postDelayed(startBounceAnimRunnable,
4312 NEW_APPS_ANIMATION_DELAY);
4313 }
Winson Chung94d67682013-09-25 16:29:40 -07004314 }
4315 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004316 } else {
4317 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004318 }
4319 }
Winson Chung64359a52013-07-08 17:17:08 -07004320 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004321 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004322 }
4323
Joe Onorato9c1289c2009-08-17 11:03:03 -04004324 /**
4325 * Implementation of the method from LauncherModel.Callbacks.
4326 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004327 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004328 Runnable r = new Runnable() {
4329 public void run() {
4330 bindFolders(folders);
4331 }
4332 };
4333 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004334 return;
4335 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004336 sFolders.clear();
4337 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004338 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004339
4340 /**
4341 * Add the views for a widget to the workspace.
4342 *
4343 * Implementation of the method from LauncherModel.Callbacks.
4344 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004345 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004346 Runnable r = new Runnable() {
4347 public void run() {
4348 bindAppWidget(item);
4349 }
4350 };
4351 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004352 return;
4353 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004354
Daniel Sandler843e8602010-06-07 14:59:01 -04004355 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4356 if (DEBUG_WIDGETS) {
4357 Log.d(TAG, "bindAppWidget: " + item);
4358 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004359 final Workspace workspace = mWorkspace;
4360
Sunny Goyalff572272014-07-23 13:58:07 -07004361 AppWidgetProviderInfo appWidgetInfo;
4362 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4363 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4364
4365 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4366 if (appWidgetInfo == null) {
4367 if (DEBUG_WIDGETS) {
4368 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4369 + " belongs to component " + item.providerName
4370 + ", as the povider is null");
4371 }
4372 LauncherModel.deleteItemFromDatabase(this, item);
4373 return;
4374 }
4375 // Note: This assumes that the id remap broadcast is received before this step.
4376 // If that is not the case, the id remap will be ignored and user may see the
4377 // click to setup view.
4378 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4379 pendingInfo.spanX = item.spanX;
4380 pendingInfo.spanY = item.spanY;
4381 pendingInfo.minSpanX = item.minSpanX;
4382 pendingInfo.minSpanY = item.minSpanY;
4383 Bundle options =
4384 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4385
4386 boolean success = false;
4387 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4388 if (options != null) {
4389 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4390 appWidgetInfo.provider, options);
4391 } else {
4392 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4393 appWidgetInfo.provider);
4394 }
4395
4396 // TODO consider showing a permission dialog when the widget is clicked.
4397 if (!success) {
4398 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4399 if (DEBUG_WIDGETS) {
4400 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4401 + " belongs to component " + item.providerName
4402 + ", as the launcher is unable to bing a new widget id");
4403 }
4404 LauncherModel.deleteItemFromDatabase(this, item);
4405 return;
4406 }
4407
4408 item.appWidgetId = newWidgetId;
4409
4410 // If the widget has a configure activity, it is still needs to set it up, otherwise
4411 // the widget is ready to go.
4412 item.restoreStatus = (appWidgetInfo.configure == null)
4413 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4414 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4415
4416 LauncherModel.updateItemInDatabase(this, item);
4417 }
4418
Sunny Goyal651077b2014-06-30 14:15:31 -07004419 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4420 final int appWidgetId = item.appWidgetId;
4421 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4422 if (DEBUG_WIDGETS) {
4423 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4424 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004425
Sunny Goyal651077b2014-06-30 14:15:31 -07004426 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4427 } else {
4428 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004429 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4430 view.updateIcon(mIconCache);
4431 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004432 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004433 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004434 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004435
Joe Onorato9c1289c2009-08-17 11:03:03 -04004436 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004437 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004438
Adam Cohendcd297f2013-06-18 13:13:40 -07004439 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004440 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004441 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4442
Joe Onorato9c1289c2009-08-17 11:03:03 -04004443 workspace.requestLayout();
4444
Daniel Sandler843e8602010-06-07 14:59:01 -04004445 if (DEBUG_WIDGETS) {
4446 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4447 + (SystemClock.uptimeMillis()-start) + "ms");
4448 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004449 }
4450
Sunny Goyalff572272014-07-23 13:58:07 -07004451 /**
4452 * Restores a pending widget.
4453 *
4454 * @param appWidgetId The app widget id
4455 * @param cellInfo The position on screen where to create the widget.
4456 */
4457 private void completeRestoreAppWidget(final int appWidgetId) {
4458 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4459 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4460 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4461 return;
4462 }
4463
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004464 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004465 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4466
4467 mWorkspace.reinflateWidgetsIfNecessary();
4468 LauncherModel.updateItemInDatabase(this, info);
4469 }
4470
Adam Cohen1462de32012-07-24 22:34:36 -07004471 public void onPageBoundSynchronously(int page) {
4472 mSynchronouslyBoundPages.add(page);
4473 }
4474
Joe Onorato9c1289c2009-08-17 11:03:03 -04004475 /**
4476 * Callback saying that there aren't any more items to bind.
4477 *
4478 * Implementation of the method from LauncherModel.Callbacks.
4479 */
Adam Cohene25af792013-06-06 23:08:25 -07004480 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004481 Runnable r = new Runnable() {
4482 public void run() {
4483 finishBindingItems(upgradePath);
4484 }
4485 };
4486 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004487 return;
4488 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004489 if (mSavedState != null) {
4490 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004491 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004492 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004493 mSavedState = null;
4494 }
4495
Adam Cohen1462de32012-07-24 22:34:36 -07004496 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004497
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004498 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004499 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004500
4501 // If we received the result of any pending adds while the loader was running (e.g. the
4502 // widget configuration forced an orientation change), process them now.
4503 if (sPendingAddItem != null) {
4504 final long screenId = completeAdd(sPendingAddItem);
4505
4506 // TODO: this moves the user to the page where the pending item was added. Ideally,
4507 // the screen would be guaranteed to exist after bind, and the page would be set through
4508 // the workspace restore process.
4509 mWorkspace.post(new Runnable() {
4510 @Override
4511 public void run() {
4512 mWorkspace.snapToScreenId(screenId);
4513 }
4514 });
4515 sPendingAddItem = null;
4516 }
4517
Adam Cohene25af792013-06-06 23:08:25 -07004518 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004519 mWorkspace.getUniqueComponents(true, null);
4520 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004521 }
Sunny Goyale755d462014-07-22 13:48:29 -07004522 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004523 }
4524
Adam Cohen3ed316a2014-07-23 18:21:20 -07004525 private void sendLoadingCompleteBroadcastIfNecessary() {
4526 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4527 String permission =
4528 getResources().getString(R.string.receive_first_load_broadcast_permission);
4529 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4530 sendBroadcast(intent, permission);
4531 SharedPreferences.Editor editor = mSharedPrefs.edit();
4532 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4533 editor.apply();
4534 }
4535 }
4536
Winson Chunga0b7e862013-09-05 16:03:15 -07004537 public boolean isAllAppsButtonRank(int rank) {
4538 if (mHotseat != null) {
4539 return mHotseat.isAllAppsButtonRank(rank);
4540 }
4541 return false;
4542 }
4543
Winson Chunga2413752012-04-03 14:22:34 -07004544 private boolean canRunNewAppsAnimation() {
4545 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4546 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4547 }
4548
Winson Chungc9168342013-06-26 14:54:55 -07004549 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4550 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4551 PropertyValuesHolder.ofFloat("alpha", 1f),
4552 PropertyValuesHolder.ofFloat("scaleX", 1f),
4553 PropertyValuesHolder.ofFloat("scaleY", 1f));
4554 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4555 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4556 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4557 return bounceAnim;
4558 }
4559
Adam Cohen27772732013-11-11 14:00:56 +00004560 public boolean useVerticalBarLayout() {
4561 return LauncherAppState.getInstance().getDynamicGrid().
4562 getDeviceProfile().isVerticalBarLayout();
4563 }
4564
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004565 protected Rect getSearchBarBounds() {
4566 return LauncherAppState.getInstance().getDynamicGrid().
4567 getDeviceProfile().getSearchBarBounds();
4568 }
4569
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004570 @Override
4571 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004572 boolean searchVisible = updateGlobalSearchIcon();
4573 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004574 if (mSearchDropTargetBar != null) {
4575 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4576 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004577 }
4578
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004579 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004580 * Add the icons for all apps.
4581 *
4582 * Implementation of the method from LauncherModel.Callbacks.
4583 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004584 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004585 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004586 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4587 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4588 getHotseat().addAllAppsFolder(mIconCache, apps,
4589 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4590 }
4591 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004592 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004593 if (mAppsCustomizeContent != null) {
4594 mAppsCustomizeContent.onPackagesUpdated(
4595 LauncherModel.getSortedWidgetsAndShortcuts(this));
4596 }
Winson Chungc58497e2013-09-03 17:48:37 -07004597 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004598 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004599 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004600 mAppsCustomizeContent.onPackagesUpdated(
4601 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004602 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004603 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004604 }
4605
4606 /**
4607 * A package was updated.
4608 *
4609 * Implementation of the method from LauncherModel.Callbacks.
4610 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004611 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004612 Runnable r = new Runnable() {
4613 public void run() {
4614 bindAppsUpdated(apps);
4615 }
4616 };
4617 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004618 return;
4619 }
4620
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004621 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004622 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004623 }
Winson Chungc58497e2013-09-03 17:48:37 -07004624
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004625 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004626 mAppsCustomizeContent != null) {
4627 mAppsCustomizeContent.updateApps(apps);
4628 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004629 }
4630
4631 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004632 * Update the state of a package, typically related to install state.
4633 *
4634 * Implementation of the method from LauncherModel.Callbacks.
4635 */
Sunny Goyale755d462014-07-22 13:48:29 -07004636 @Override
4637 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004638 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004639 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004640 }
4641 }
4642
4643 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004644 * A package was uninstalled. We take both the super set of packageNames
4645 * in addition to specific applications to remove, the reason being that
4646 * this can be called when a package is updated as well. In that scenario,
4647 * we only remove specific components from the workspace, where as
4648 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004649 *
4650 * Implementation of the method from LauncherModel.Callbacks.
4651 */
Winson Chung83892cc2013-05-01 16:53:33 -07004652 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004653 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004654 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004655 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004656 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004657 }
Winson Chungd64d1762013-08-20 14:37:16 -07004658 };
4659 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004660 return;
4661 }
4662
Winson Chungdf95eb12013-10-16 14:57:07 -07004663 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004664 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004665 }
4666 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004667 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004668 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004669
Winson Chunga1820962011-10-03 16:31:06 -07004670 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004671 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004672
Winson Chungdf95eb12013-10-16 14:57:07 -07004673 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004674 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004675 mAppsCustomizeContent != null) {
4676 mAppsCustomizeContent.removeApps(appInfos);
4677 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004678 }
Joe Onoratobe386092009-11-17 17:32:16 -08004679
4680 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004681 * A number of packages were updated.
4682 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004683 private ArrayList<Object> mWidgetsAndShortcuts;
4684 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004685 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004686 bindPackagesUpdated(mWidgetsAndShortcuts);
4687 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004688 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004689 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004690 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4691 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4692 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004693 return;
4694 }
4695
Winson Chung64359a52013-07-08 17:17:08 -07004696 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004697 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004698 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004699 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004700 }
4701
Winson Chung400438b2011-01-16 17:53:48 -08004702 private int mapConfigurationOriActivityInfoOri(int configOri) {
4703 final Display d = getWindowManager().getDefaultDisplay();
4704 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4705 switch (d.getRotation()) {
4706 case Surface.ROTATION_0:
4707 case Surface.ROTATION_180:
4708 // We are currently in the same basic orientation as the natural orientation
4709 naturalOri = configOri;
4710 break;
4711 case Surface.ROTATION_90:
4712 case Surface.ROTATION_270:
4713 // We are currently in the other basic orientation to the natural orientation
4714 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4715 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4716 break;
4717 }
4718
4719 int[] oriMap = {
4720 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4721 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4722 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4723 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4724 };
4725 // Since the map starts at portrait, we need to offset if this device's natural orientation
4726 // is landscape.
4727 int indexOffset = 0;
4728 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4729 indexOffset = 1;
4730 }
4731 return oriMap[(d.getRotation() + indexOffset) % 4];
4732 }
Adam Cohen446e9402011-09-15 18:21:21 -07004733
Winson Chung4b919f82012-05-01 10:44:08 -07004734 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004735 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004736 getResources().getBoolean(R.bool.allow_rotation);
4737 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004738 }
Winson Chung4b919f82012-05-01 10:44:08 -07004739 public void lockScreenOrientation() {
4740 if (isRotationEnabled()) {
4741 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4742 .getConfiguration().orientation));
4743 }
4744 }
4745 public void unlockScreenOrientation(boolean immediate) {
4746 if (isRotationEnabled()) {
4747 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004748 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004749 } else {
4750 mHandler.postDelayed(new Runnable() {
4751 public void run() {
4752 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4753 }
4754 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004755 }
Winson Chung4b919f82012-05-01 10:44:08 -07004756 }
Winson Chung400438b2011-01-16 17:53:48 -08004757 }
4758
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004759 /**
4760 * Called when the SearchBar hint should be changed.
4761 *
4762 * @param hint the hint to be displayed in the search bar.
4763 */
4764 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004765 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004766 }
4767
Winson Chunge43a1e72014-01-15 10:33:02 -08004768 protected boolean isLauncherPreinstalled() {
4769 PackageManager pm = getPackageManager();
4770 try {
4771 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4772 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4773 return true;
4774 } else {
4775 return false;
4776 }
4777 } catch (NameNotFoundException e) {
4778 e.printStackTrace();
4779 return false;
4780 }
4781 }
4782
Adam Cohenea90f832014-05-21 15:03:34 -07004783 /**
4784 * This method indicates whether or not we should suggest default wallpaper dimensions
4785 * when our wallpaper cropper was not yet used to set a wallpaper.
4786 */
4787 protected boolean overrideWallpaperDimensions() {
4788 return true;
4789 }
4790
Adam Cohen5eed5d82014-05-19 13:12:13 -07004791 protected boolean shouldClingFocusHotseatApp() {
4792 return false;
4793 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004794 protected String getFirstRunClingSearchBarHint() {
4795 return "";
4796 }
4797 protected String getFirstRunCustomContentHint() {
4798 return "";
4799 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004800 protected int getFirstRunFocusedHotseatAppDrawableId() {
4801 return -1;
4802 }
4803 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4804 return null;
4805 }
4806 protected int getFirstRunFocusedHotseatAppRank() {
4807 return -1;
4808 }
4809 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4810 return "";
4811 }
4812 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4813 return "";
4814 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004815
Winson Chungaf40f202013-09-18 18:26:31 -07004816 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004817 mLauncherClings.dismissFirstRunCling(v);
4818 }
4819 public void dismissMigrationClingCopyApps(View v) {
4820 mLauncherClings.dismissMigrationClingCopyApps(v);
4821 }
4822 public void dismissMigrationClingUseDefault(View v) {
4823 mLauncherClings.dismissMigrationClingUseDefault(v);
4824 }
4825 public void dismissMigrationWorkspaceCling(View v) {
4826 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004827 }
Winson Chung82f55532011-08-09 14:14:23 -07004828 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004829 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004830 }
4831 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004832 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004833 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004834 public void markFolderClingDismissedIfNecessary() {
4835 mLauncherClings.markFolderClingDismissedIfNecessary();
4836 }
Adam Cohen432609a2014-03-13 17:03:22 -07004837
4838 /**
4839 * To be overridden by subclasses to indicate that there is an activity to launch
4840 * before showing the standard launcher experience.
4841 */
4842 protected boolean hasFirstRunActivity() {
4843 return false;
4844 }
4845
4846 /**
4847 * To be overridden by subclasses to launch any first run activity
4848 */
4849 protected Intent getFirstRunActivity() {
4850 return null;
4851 }
4852
Winson Chunga6945242014-01-08 14:04:34 -08004853 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004854 return !ActivityManager.isRunningInTestHarness() &&
4855 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004856 }
4857
Adam Cohen4a9423d2014-03-28 14:22:31 -07004858 protected boolean hasRunFirstRunActivity() {
4859 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4860 }
4861
Adam Cohen432609a2014-03-13 17:03:22 -07004862 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004863 if (shouldRunFirstRunActivity() &&
4864 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004865 Intent firstRunIntent = getFirstRunActivity();
4866 if (firstRunIntent != null) {
4867 startActivity(firstRunIntent);
4868 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004869 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004870 }
4871 }
Adam Cohen432609a2014-03-13 17:03:22 -07004872 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004873 }
4874
4875 private void markFirstRunActivityShown() {
4876 SharedPreferences.Editor editor = mSharedPrefs.edit();
4877 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4878 editor.apply();
4879 }
4880
Adam Cohen432609a2014-03-13 17:03:22 -07004881 /**
4882 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4883 * screen that must be displayed and dismissed.
4884 */
4885 protected boolean hasDismissableIntroScreen() {
4886 return false;
4887 }
4888
4889 /**
4890 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4891 */
4892 protected View getIntroScreen() {
4893 return null;
4894 }
4895
4896 /**
4897 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4898 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4899 */
4900 private boolean shouldShowIntroScreen() {
4901 return hasDismissableIntroScreen() &&
4902 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4903 }
4904
4905 protected void showIntroScreen() {
4906 View introScreen = getIntroScreen();
4907 changeWallpaperVisiblity(false);
4908 if (introScreen != null) {
4909 mDragLayer.showOverlayView(introScreen);
4910 }
4911 }
4912
4913 public void dismissIntroScreen() {
4914 markIntroScreenDismissed();
4915 if (showFirstRunActivity()) {
4916 // We delay hiding the intro view until the first run activity is showing. This
4917 // avoids a blip.
4918 mWorkspace.postDelayed(new Runnable() {
4919 @Override
4920 public void run() {
4921 mDragLayer.dismissOverlayView();
4922 }
4923 }, ACTIVITY_START_DELAY);
4924 } else {
4925 mDragLayer.dismissOverlayView();
4926 }
4927 changeWallpaperVisiblity(true);
4928 }
4929
4930 private void markIntroScreenDismissed() {
4931 SharedPreferences.Editor editor = mSharedPrefs.edit();
4932 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4933 editor.apply();
4934 }
4935
Winson Chunga6945242014-01-08 14:04:34 -08004936 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004937 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4938 if (mHotseat != null) mHotseat.setAlpha(1f);
4939 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4940 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004941 }
4942
4943 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004944 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4945 if (mHotseat != null) mHotseat.setAlpha(0f);
4946 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4947 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004948 }
4949
Mathew Inwood72fbec12013-11-19 15:45:07 +00004950 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004951 // Called from search suggestion, not supported in other profiles.
4952 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4953 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4954 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4955 myUser);
4956 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004957 return null;
4958 }
Kenny Guyed131872014-04-30 03:02:21 +01004959 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004960 }
4961
4962 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4963 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004964 // Called from search suggestion, not supported in other profiles.
4965 return createShortcutDragInfo(shortcutIntent, caption, icon,
4966 UserHandleCompat.myUserHandle());
4967 }
4968
4969 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4970 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004971 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004972 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004973 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004974 }
4975
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004976 protected void moveWorkspaceToDefaultScreen() {
4977 mWorkspace.moveToDefaultScreen(false);
4978 }
4979
Mathew Inwood72fbec12013-11-19 15:45:07 +00004980 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4981 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004982 mWorkspace.onExternalDragStartedWithItem(dragView);
4983 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004984 }
4985
Anjali Koppalf5d29132014-02-28 13:33:27 -08004986 @Override
4987 public void onPageSwitch(View newPage, int newPageIndex) {
4988 }
4989
Winson Chung80baf5a2010-08-09 16:03:15 -07004990 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004991 * Prints out out state for debugging.
4992 */
4993 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004994 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004995 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004996 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4997 Log.d(TAG, "mRestoring=" + mRestoring);
4998 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4999 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005000 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005001 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005002
Winson Chung785d2eb2011-04-14 16:08:02 -07005003 if (mAppsCustomizeContent != null) {
5004 mAppsCustomizeContent.dumpState();
5005 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005006 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005007 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005008
5009 @Override
5010 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5011 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005012 synchronized (sDumpLogs) {
5013 writer.println(" ");
5014 writer.println("Debug logs: ");
5015 for (int i = 0; i < sDumpLogs.size(); i++) {
5016 writer.println(" " + sDumpLogs.get(i));
5017 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005018 }
5019 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005020
5021 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005022 if (DEBUG_DUMP_LOG) {
5023 synchronized (sDumpLogs) {
5024 Log.d(TAG, "");
5025 Log.d(TAG, "*********************");
5026 Log.d(TAG, "Launcher debug logs: ");
5027 for (int i = 0; i < sDumpLogs.size(); i++) {
5028 Log.d(TAG, " " + sDumpLogs.get(i));
5029 }
5030 Log.d(TAG, "*********************");
5031 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005032 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005033 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005034 }
5035
5036 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005037 addDumpLog(tag, log, null, debugLog);
5038 }
5039
5040 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005041 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005042 if (e != null) {
5043 Log.d(tag, log, e);
5044 } else {
5045 Log.d(tag, log);
5046 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005047 }
Winson Chungede41292013-09-19 16:27:36 -07005048 if (DEBUG_DUMP_LOG) {
5049 sDateStamp.setTime(System.currentTimeMillis());
5050 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005051 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5052 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005053 }
Winson Chungede41292013-09-19 16:27:36 -07005054 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005055 }
5056
Winson Chungede41292013-09-19 16:27:36 -07005057 public void dumpLogsToLocalData() {
5058 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005059 new AsyncTask<Void, Void, Void>() {
5060 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005061 boolean success = false;
5062 sDateStamp.setTime(sRunStart);
5063 String FILENAME = sDateStamp.getMonth() + "-"
5064 + sDateStamp.getDay() + "_"
5065 + sDateStamp.getHours() + "-"
5066 + sDateStamp.getMinutes() + "_"
5067 + sDateStamp.getSeconds() + ".txt";
5068
5069 FileOutputStream fos = null;
5070 File outFile = null;
5071 try {
5072 outFile = new File(getFilesDir(), FILENAME);
5073 outFile.createNewFile();
5074 fos = new FileOutputStream(outFile);
5075 } catch (Exception e) {
5076 e.printStackTrace();
5077 }
5078 if (fos != null) {
5079 PrintWriter writer = new PrintWriter(fos);
5080
5081 writer.println(" ");
5082 writer.println("Debug logs: ");
5083 synchronized (sDumpLogs) {
5084 for (int i = 0; i < sDumpLogs.size(); i++) {
5085 writer.println(" " + sDumpLogs.get(i));
5086 }
5087 }
5088 writer.close();
5089 }
5090 try {
5091 if (fos != null) {
5092 fos.close();
5093 success = true;
5094 }
5095 } catch (IOException e) {
5096 e.printStackTrace();
5097 }
Michael Jurka43467462013-11-14 12:03:58 +01005098 return null;
Winson Chungede41292013-09-19 16:27:36 -07005099 }
Michael Jurka43467462013-11-14 12:03:58 +01005100 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005101 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005102 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005103}
Michael Jurka2763be32011-02-24 11:19:57 -08005104
Michael Jurkaabded662011-03-04 12:06:57 -08005105interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005106 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005107 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005108 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005109 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005110 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005111}
Dan Sandlerd5024042014-01-09 15:01:33 -05005112
5113interface DebugIntents {
5114 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5115 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005116}