blob: 111fba8ced57ad3f68c657043f06432df7ade390 [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;
Winson Chung70442722012-02-10 15:43:22 -080026import android.animation.ValueAnimator.AnimatorUpdateListener;
Adam Cohen0b395352014-06-09 22:54:36 +000027import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070028import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070029import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070030import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040031import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040042import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080052import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070053import android.graphics.Bitmap;
54import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070055import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070056import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070057import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020063import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080064import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070065import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070066import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040067import android.os.SystemClock;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080068import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070073import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.Display;
76import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
79import android.view.LayoutInflater;
80import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070081import android.view.MotionEvent;
82import android.view.Surface;
83import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070084import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Sunny Goyale755d462014-07-22 13:48:29 -070086import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.ViewGroup;
88import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080089import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Sunny Goyal651077b2014-06-30 14:15:31 -070090import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080092import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070093import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080094import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070096import android.widget.Advanceable;
97import android.widget.FrameLayout;
98import android.widget.ImageView;
99import android.widget.TextView;
100import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700101
Sunny Goyal651077b2014-06-30 14:15:31 -0700102import com.android.launcher3.DropTarget.DragObject;
103import com.android.launcher3.PagedView.PageSwitchListener;
Kenny Guyed131872014-04-30 03:02:21 +0100104import com.android.launcher3.compat.LauncherActivityInfoCompat;
105import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700106import com.android.launcher3.compat.PackageInstallerCompat;
107import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100108import com.android.launcher3.compat.UserHandleCompat;
109import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700110
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.io.DataInputStream;
112import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700114import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700118import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000119import java.lang.reflect.Field;
120import java.lang.reflect.InvocationTargetException;
121import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700122import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700124import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700127import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000128import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700129
Winson Chunga6945242014-01-08 14:04:34 -0800130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131/**
132 * Default launcher application.
133 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100134public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700135 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700136 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800137 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700138 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Daniel Sandlerf061f822013-06-27 13:59:36 -0400140 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400141 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700142 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400143 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700144 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700145
Dan Sandlerd5024042014-01-09 15:01:33 -0500146 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
147
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700149 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700151 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700152 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Michael Jurka8b805b12012-04-18 14:23:14 -0700154 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700155 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700156
Mathew Inwood876a8462013-06-14 14:12:41 +0100157 /**
158 * IntentStarter uses request codes starting with this. This must be greater than all activity
159 * request codes used internally.
160 */
161 protected static final int REQUEST_LAST = 100;
162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
164
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800165 static final int SCREEN_COUNT = 5;
166 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167
Romain Guy98d01652009-06-30 16:21:04 -0700168 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800169 // To turn on these properties, type
170 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
171 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
172 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800173 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
Winson Chung2672ff92012-05-04 16:22:30 -0700175 // The Intent extra that defines whether to ignore the launch animation
176 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400177 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700178
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 // Type: int
180 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700181 // Type: int
182 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700184 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
185 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
187 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700188 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700190 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 // Type: boolean
192 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
193 // Type: long
194 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700195 // Type: int
196 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
197 // Type: int
198 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
199 // Type: parcelable
200 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000201 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800202 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000203 // Type: int[]
204 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205
Adam Cohen432609a2014-03-13 17:03:22 -0700206 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800207 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
208
Adam Cohen3ed316a2014-07-23 18:21:20 -0700209 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
210 static final String ACTION_FIRST_LOAD_COMPLETE =
211 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
212
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100213 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700214 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100215 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700216 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100217 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700218
Adam Cohen39a06042013-07-19 14:30:12 -0700219 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700220 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700221
Winson Chunga6945242014-01-08 14:04:34 -0800222 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
223
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700224 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700225 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700226 private State mState = State.WORKSPACE;
227 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700228
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700229 private boolean mIsSafeModeEnabled;
230
Joe Onorato9c1289c2009-08-17 11:03:03 -0400231 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700232 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
233 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700234 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800237 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000239 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
240 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
241
Winson Chunga2413752012-04-03 14:22:34 -0700242 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700243 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
244 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700245 private static int NEW_APPS_ANIMATION_DELAY = 500;
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];
332 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800333
Winson Chungd64a6662013-09-30 11:06:59 -0700334 private Intent mAppMarketIntent = null;
335 private static final boolean DISABLE_MARKET_BUTTON = true;
336
Craig Mautner360310b2012-10-26 15:13:08 -0700337 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700338
Adam Cohen1462de32012-07-24 22:34:36 -0700339 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700340 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700341
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700342 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700343 static Date sDateStamp = new Date();
344 static DateFormat sDateFormat =
345 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
346 static long sRunStart = System.currentTimeMillis();
347 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700348
Winson Chung46353de2012-02-16 14:05:10 -0800349 // We only want to get the SharedPreferences once since it does an FS stat each time we get
350 // it from the context.
351 private SharedPreferences mSharedPrefs;
352
Adam Cohene25af792013-06-06 23:08:25 -0700353 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
354
Winson Chungf0c6ae02012-03-21 16:10:31 -0700355 // Holds the page that we need to animate to, and the icon views that we need to animate up
356 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700357 private ImageView mFolderIconImageView;
358 private Bitmap mFolderIconBitmap;
359 private Canvas mFolderIconCanvas;
360 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700361
Michael Jurkaddd62e92011-02-16 17:49:14 -0800362 private BubbleTextView mWaitingForResume;
363
Michael Jurkac1f5d262011-09-30 19:32:27 -0700364 private Runnable mBuildLayersRunnable = new Runnable() {
365 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700366 if (mWorkspace != null) {
367 mWorkspace.buildPageHardwareLayers();
368 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700369 }
370 };
371
Adam Cohendb364c32014-05-20 14:23:40 -0700372 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800373
Michael Jurka7267fa52013-09-26 15:29:57 -0700374 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800375
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800376 private static class PendingAddArguments {
377 int requestCode;
378 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700379 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700380 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800381 int cellX;
382 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700383 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800384 }
385
Daniel Sandlerff02d492013-08-05 02:12:05 -0400386 private Stats mStats;
387
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800388 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800389 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700390 }
391
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392 @Override
393 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700394 if (DEBUG_STRICT_MODE) {
395 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
396 .detectDiskReads()
397 .detectDiskWrites()
398 .detectNetwork() // or .detectAll() for all detectable problems
399 .penaltyLog()
400 .build());
401 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
402 .detectLeakedSqlLiteObjects()
403 .detectLeakedClosableObjects()
404 .penaltyLog()
405 .penaltyDeath()
406 .build());
407 }
408
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800409 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400410
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400411 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400412 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700413 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700414 // Determine the dynamic grid properties
415 Point smallestSize = new Point();
416 Point largestSize = new Point();
417 Point realSize = new Point();
418 Display display = getWindowManager().getDefaultDisplay();
419 display.getCurrentSizeRange(smallestSize, largestSize);
420 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700421 DisplayMetrics dm = new DisplayMetrics();
422 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700423
Winson Chung5f8afe62013-08-12 16:19:28 -0700424 // Lazy-initialize the dynamic grid
425 DeviceProfile grid = app.initDynamicGrid(this,
426 Math.min(smallestSize.x, smallestSize.y),
427 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700428 realSize.x, realSize.y,
429 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700430
431 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400432 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700433 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700434 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800435 mModel = app.setLauncher(this);
436 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700437 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400438 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800439 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700441
Daniel Sandlerff02d492013-08-05 02:12:05 -0400442 mStats = new Stats(this);
443
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700444 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700445
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700446 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
447 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700448
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700449 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
450 // this also ensures that any synchronous binding below doesn't re-trigger another
451 // LauncherModel load.
452 mPaused = false;
453
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200455 android.os.Debug.startMethodTracing(
456 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 }
458
Adam Cohen53805212013-10-01 10:39:23 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800461 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700462
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100464 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800466 registerContentObservers();
467
Joe Onorato7c312c12009-08-13 21:36:53 -0700468 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700469
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800470 mSavedState = savedInstanceState;
471 restoreState(mSavedState);
472
473 if (PROFILE_STARTUP) {
474 android.os.Debug.stopMethodTracing();
475 }
476
477 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700478 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700479 // If the user leaves launcher, then we should just load items asynchronously when
480 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500481 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700482 } else {
483 // We only load the page synchronously if the user rotates (or triggers a
484 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800485 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700486 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800487 }
488
489 // For handling default keys
490 mDefaultKeySsb = new SpannableStringBuilder();
491 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800492
493 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
494 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800495
Adam Cohenf9426d52012-06-04 17:26:21 -0700496 updateGlobalIcons();
497
498 // On large interfaces, we want the screen to auto-rotate based on the current orientation
499 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700500
Adam Cohen432609a2014-03-13 17:03:22 -0700501 if (shouldShowIntroScreen()) {
502 showIntroScreen();
503 } else {
504 showFirstRunActivity();
505 }
506
Winson Chunge43a1e72014-01-15 10:33:02 -0800507 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
508 // on the device, then we always show the first run cling experience (or if there is no
509 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800510 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
511 if (mModel.canMigrateFromOldLauncherDb(this)) {
512 mLauncherClings.showMigrationCling();
513 } else {
514 mLauncherClings.showFirstRunCling();
515 }
Winson Chunga6945242014-01-08 14:04:34 -0800516 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800517 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800518 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700519 }
520
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700521 @Override
522 public void onLauncherProviderChange() { }
523
Winson Chung98ca0f72013-07-29 12:58:51 -0700524 /** To be overriden by subclasses to hint to Launcher that we have custom content */
525 protected boolean hasCustomContentToLeft() {
526 return false;
527 }
528
Dave Hawkeya8881582013-09-17 15:55:33 -0600529 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500530 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600531 * {@link #addToCustomContentPage}. This will only be invoked if
532 * {@link #hasCustomContentToLeft()} is {@code true}.
533 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500534 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600535 }
536
537 /**
538 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
539 * ensure the custom content page is added or removed if necessary.
540 */
541 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600542 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600543 // Not bound yet, wait for bindScreens to be called.
544 return;
545 }
546
547 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
548 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500549 mWorkspace.createCustomContentContainer();
550 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600551 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
552 mWorkspace.removeCustomContentPage();
553 }
554 }
555
Adam Cohenf9426d52012-06-04 17:26:21 -0700556 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700557 boolean searchVisible = false;
558 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800559 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700560 int coi = getCurrentOrientationIndexForGlobalIcons();
561 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
562 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700563 if (!DISABLE_MARKET_BUTTON) {
564 updateAppMarketIcon();
565 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700566 searchVisible = updateGlobalSearchIcon();
567 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700568 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700569 if (sGlobalSearchIcon[coi] != null) {
570 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700571 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700572 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700573 if (sVoiceSearchIcon[coi] != null) {
574 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700575 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700576 }
Winson Chungd64a6662013-09-30 11:06:59 -0700577 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700578 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800579 }
Winson Chungadf0c182012-08-23 14:59:07 -0700580 if (mSearchDropTargetBar != null) {
581 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
582 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583 }
Romain Guycbb89e42009-06-08 15:52:54 -0700584
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800585 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700586 if (sLocaleConfiguration == null) {
587 new AsyncTask<Void, Void, LocaleConfiguration>() {
588 @Override
589 protected LocaleConfiguration doInBackground(Void... unused) {
590 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
591 readConfiguration(Launcher.this, localeConfiguration);
592 return localeConfiguration;
593 }
594
595 @Override
596 protected void onPostExecute(LocaleConfiguration result) {
597 sLocaleConfiguration = result;
598 checkForLocaleChange(); // recursive, but now with a locale configuration
599 }
600 }.execute();
601 return;
602 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700603
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800604 final Configuration configuration = getResources().getConfiguration();
605
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800607 final String locale = configuration.locale.toString();
608
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700609 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800610 final int mcc = configuration.mcc;
611
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700612 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800613 final int mnc = configuration.mnc;
614
Romain Guy84f296c2009-11-04 15:00:44 -0800615 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800616
Romain Guy84f296c2009-11-04 15:00:44 -0800617 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700618 sLocaleConfiguration.locale = locale;
619 sLocaleConfiguration.mcc = mcc;
620 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700621
Joe Onorato0589f0f2010-02-08 13:44:00 -0800622 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700623
624 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100625 new AsyncTask<Void, Void, Void>() {
626 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700627 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100628 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700629 }
Michael Jurka43467462013-11-14 12:03:58 +0100630 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700631 }
632 }
633
634 private static class LocaleConfiguration {
635 public String locale;
636 public int mcc = -1;
637 public int mnc = -1;
638 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700639
Romain Guy98d01652009-06-30 16:21:04 -0700640 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
641 DataInputStream in = null;
642 try {
643 in = new DataInputStream(context.openFileInput(PREFERENCES));
644 configuration.locale = in.readUTF();
645 configuration.mcc = in.readInt();
646 configuration.mnc = in.readInt();
647 } catch (FileNotFoundException e) {
648 // Ignore
649 } catch (IOException e) {
650 // Ignore
651 } finally {
652 if (in != null) {
653 try {
654 in.close();
655 } catch (IOException e) {
656 // Ignore
657 }
658 }
659 }
660 }
661
662 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
663 DataOutputStream out = null;
664 try {
665 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
666 out.writeUTF(configuration.locale);
667 out.writeInt(configuration.mcc);
668 out.writeInt(configuration.mnc);
669 out.flush();
670 } catch (FileNotFoundException e) {
671 // Ignore
672 } catch (IOException e) {
673 //noinspection ResultOfMethodCallIgnored
674 context.getFileStreamPath(PREFERENCES).delete();
675 } finally {
676 if (out != null) {
677 try {
678 out.close();
679 } catch (IOException e) {
680 // Ignore
681 }
682 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 }
684 }
685
Anton Hanssona2f665f2013-09-26 12:18:32 +0100686 public Stats getStats() {
687 return mStats;
688 }
689
Bjorn Bringertc459e522013-06-07 19:36:01 +0100690 public LayoutInflater getInflater() {
691 return mInflater;
692 }
693
Winson Chung36a62fe2012-05-06 18:04:42 -0700694 boolean isDraggingEnabled() {
695 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
696 // that is subsequently removed from the workspace in startBinding().
697 return !mModel.isLoadingWorkspace();
698 }
699
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700 static int getScreen() {
701 synchronized (sLock) {
702 return sScreen;
703 }
704 }
705
706 static void setScreen(int screen) {
707 synchronized (sLock) {
708 sScreen = screen;
709 }
710 }
711
Winson Chung557d6ed2011-07-08 15:34:52 -0700712 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000713 * Copied from View -- the View version of the method isn't called
714 * anywhere else in our process and only exists for API level 17+,
715 * so it's ok to keep our own version with no API requirement.
716 */
717 public static int generateViewId() {
718 for (;;) {
719 final int result = sNextGeneratedId.get();
720 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
721 int newValue = result + 1;
722 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
723 if (sNextGeneratedId.compareAndSet(result, newValue)) {
724 return result;
725 }
726 }
727 }
728
729 public int getViewIdForItem(ItemInfo info) {
730 // This cast is safe given the > 2B range for int.
731 int itemId = (int) info.id;
732 if (mItemIdToViewId.containsKey(itemId)) {
733 return mItemIdToViewId.get(itemId);
734 }
735 int viewId = generateViewId();
736 mItemIdToViewId.put(itemId, viewId);
737 return viewId;
738 }
739
740 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700741 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
742 * a configuration step, this allows the proper animations to run after other transitions.
743 */
Adam Cohendb364c32014-05-20 14:23:40 -0700744 private long completeAdd(PendingAddArguments args) {
745
746 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700749 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700750 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700751 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700753 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700754 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700755 case REQUEST_RECONFIGURE_APPWIDGET:
756 completeRestoreAppWidget(args.appWidgetId);
757 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800758 }
Michael Jurka27614d22012-04-02 06:40:22 -0700759 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
760 // if you turned the screen off and then back while in All Apps, Launcher would not
761 // return to the workspace. Clearing mAddInfo.container here fixes this issue
762 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700763 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800764 }
765
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800766 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700767 protected void onActivityResult(
768 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700769 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700770 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700771 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800772 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700773
Adam Cohenad4e15c2013-10-17 16:21:35 -0700774 Runnable exitSpringLoaded = new Runnable() {
775 @Override
776 public void run() {
777 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
778 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
779 }
780 };
781
Michael Jurka8b805b12012-04-18 14:23:14 -0700782 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700783 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700784 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
785 if (resultCode == RESULT_CANCELED) {
786 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700787 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700788 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700789 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700790 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
791 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700792 }
793 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200794 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
795 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
796 mWorkspace.exitOverviewMode(false);
797 }
798 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700799 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200800
Adam Cohened66b2b2012-01-23 17:28:51 -0800801 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
802 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700803
Adam Cohendb364c32014-05-20 14:23:40 -0700804 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800805 // We have special handling for widgets
806 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800807 final int appWidgetId;
808 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
809 : -1;
810 if (widgetId < 0) {
811 appWidgetId = pendingAddWidgetId;
812 } else {
813 appWidgetId = widgetId;
814 }
815
Adam Cohenad4e15c2013-10-17 16:21:35 -0700816 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800817 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700818 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
819 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700820 result = RESULT_CANCELED;
821 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700822 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700823 @Override
824 public void run() {
825 exitSpringLoadedDragModeDelayed(false, 0, null);
826 }
827 };
Adam Cohendb364c32014-05-20 14:23:40 -0700828 if (workspaceLocked) {
829 // No need to remove the empty screen if we're mid-binding, as the
830 // the bind will not add the empty screen.
831 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
832 } else {
833 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
834 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
835 }
Winson Chung5aaab772012-04-27 15:24:02 -0700836 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700837 if (!workspaceLocked) {
838 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
839 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
840
841 dropLayout.setDropPending(true);
842 final Runnable onComplete = new Runnable() {
843 @Override
844 public void run() {
845 completeTwoStageWidgetDrop(resultCode, appWidgetId);
846 dropLayout.setDropPending(false);
847 }
848 };
849 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
850 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
851 } else {
852 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
853 mPendingAddInfo);
854 sPendingAddItem = args;
855 }
Winson Chung5aaab772012-04-27 15:24:02 -0700856 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800857 return;
858 }
859
Sunny Goyalff572272014-07-23 13:58:07 -0700860 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
861 if (resultCode == RESULT_OK) {
862 // Update the widget view.
863 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
864 pendingAddWidgetId, mPendingAddInfo);
865 if (workspaceLocked) {
866 sPendingAddItem = args;
867 } else {
868 completeAdd(args);
869 }
870 }
871 // Leave the widget in the pending state if the user canceled the configure.
872 return;
873 }
874
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800875 // The pattern used here is that a user PICKs a specific application,
876 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700877
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800878 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
879 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700880 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700881 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
882 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800883 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700884 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800885 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700886 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700887 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
888 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800889 }
Adam Cohen00074722013-10-11 17:46:09 -0700890 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700891 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700892 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800893 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800894 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800895 }
896
Adam Cohendb364c32014-05-20 14:23:40 -0700897 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
898 appWidgetId, ItemInfo info) {
899 PendingAddArguments args = new PendingAddArguments();
900 args.requestCode = requestCode;
901 args.intent = data;
902 args.container = info.container;
903 args.screenId = info.screenId;
904 args.cellX = info.cellX;
905 args.cellY = info.cellY;
906 args.appWidgetId = appWidgetId;
907 return args;
908 }
909
910 /**
911 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
912 *
913 * @param screenId the screen id to check
914 * @return the new screen, or screenId if it exists
915 */
916 private long ensurePendingDropLayoutExists(long screenId) {
917 CellLayout dropLayout =
918 (CellLayout) mWorkspace.getScreenWithId(screenId);
919 if (dropLayout == null) {
920 // it's possible that the add screen was removed because it was
921 // empty and a re-bind occurred
922 mWorkspace.addExtraEmptyScreen();
923 return mWorkspace.commitExtraEmptyScreen();
924 } else {
925 return screenId;
926 }
927 }
928
Adam Cohened66b2b2012-01-23 17:28:51 -0800929 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700930 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700931 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800932 Runnable onCompleteRunnable = null;
933 int animationType = 0;
934
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700935 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800936 if (resultCode == RESULT_OK) {
937 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
938 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700939 mPendingAddWidgetInfo);
940 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800941 onCompleteRunnable = new Runnable() {
942 @Override
943 public void run() {
944 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700945 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700946 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
947 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800948 }
949 };
950 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800951 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800952 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800953 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700954 if (mDragLayer.getAnimatedView() != null) {
955 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
956 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
957 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700958 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700959 // The animated view may be null in the case of a rotation during widget configuration
960 onCompleteRunnable.run();
961 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800962 }
963
964 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700965 protected void onStop() {
966 super.onStop();
967 FirstFrameAnimatorHelper.setIsVisible(false);
968 }
969
970 @Override
971 protected void onStart() {
972 super.onStart();
973 FirstFrameAnimatorHelper.setIsVisible(true);
974 }
975
976 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200978 long startTime = 0;
979 if (DEBUG_RESUME_TIME) {
980 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400981 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200982 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800983 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700984
Winson Chung4a2afa32012-07-19 14:53:05 -0700985 // Restore the previous launcher state
986 if (mOnResumeState == State.WORKSPACE) {
987 showWorkspace(false);
988 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800989 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700990 }
991 mOnResumeState = State.NONE;
992
Craig Mautner360310b2012-10-26 15:13:08 -0700993 // Background was set to gradient in onPause(), restore to black if in all apps.
994 setWorkspaceBackground(mState == State.WORKSPACE);
995
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800996 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700997 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700998 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500999 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001000 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001001 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001002 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001003 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001004 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1005 // execute them here
1006 long startTimeCallbacks = 0;
1007 if (DEBUG_RESUME_TIME) {
1008 startTimeCallbacks = System.currentTimeMillis();
1009 }
1010
1011 if (mAppsCustomizeContent != null) {
1012 mAppsCustomizeContent.setBulkBind(true);
1013 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001014 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1015 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001016 }
1017 if (mAppsCustomizeContent != null) {
1018 mAppsCustomizeContent.setBulkBind(false);
1019 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001020 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001021 if (DEBUG_RESUME_TIME) {
1022 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1023 (System.currentTimeMillis() - startTimeCallbacks));
1024 }
Michael Jurka447bf842013-05-15 14:52:15 +02001025 }
Michael Jurka54554252013-08-01 12:52:23 +02001026 if (mOnResumeCallbacks.size() > 0) {
1027 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1028 mOnResumeCallbacks.get(i).run();
1029 }
1030 mOnResumeCallbacks.clear();
1031 }
Winson Chunge4e50662012-01-23 14:45:13 -08001032
1033 // Reset the pressed state of icons that were locked in the press state while activities
1034 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001035 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001036 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001037 mWaitingForResume.setStayPressed(false);
1038 }
Winson Chunge4e50662012-01-23 14:45:13 -08001039 if (mAppsCustomizeContent != null) {
1040 // Resets the previous all apps icon press state
1041 mAppsCustomizeContent.resetDrawableState();
1042 }
Winson Chung82963d52013-10-09 11:20:57 -07001043
Adam Cohen06dff352012-06-01 17:17:08 -07001044 // It is possible that widgets can receive updates while launcher is not in the foreground.
1045 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1046 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1047 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001048 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001049
Winson Chung780fe592013-09-26 14:48:44 -07001050 // Process any items that were added while Launcher was away.
1051 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1052
Winson Chung5841efa2013-09-30 18:06:44 -07001053 // Update the voice search button proxy
1054 updateVoiceButtonProxyVisible(false);
1055
Adam Cohenf9426d52012-06-04 17:26:21 -07001056 // Again, as with the above scenario, it's possible that one or more of the global icons
1057 // were updated in the wrong orientation.
1058 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001059 if (DEBUG_RESUME_TIME) {
1060 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1061 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001062
1063 if (mWorkspace.getCustomContentCallbacks() != null) {
1064 // If we are resuming and the custom content is the current page, we call onShow().
1065 // It is also poassible that onShow will instead be called slightly after first layout
1066 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1067 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001068 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001069 }
1070 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001071 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001072 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001073
1074 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001075 }
1076
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001078 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001079 // Ensure that items added to Launcher are queued until Launcher returns
1080 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001081 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001082
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001083 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001084 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001085 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001086 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001087
1088 // We call onHide() aggressively. The custom content callbacks should be able to
1089 // debounce excess onHide calls.
1090 if (mWorkspace.getCustomContentCallbacks() != null) {
1091 mWorkspace.getCustomContentCallbacks().onHide();
1092 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001093 }
Romain Guycbb89e42009-06-08 15:52:54 -07001094
Adam Cohenbffe7452013-07-22 18:21:45 -07001095 QSBScroller mQsbScroller = new QSBScroller() {
1096 int scrollY = 0;
1097
1098 @Override
1099 public void setScrollY(int scroll) {
1100 scrollY = scroll;
1101
1102 if (mWorkspace.isOnOrMovingToCustomContent()) {
1103 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001104 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001105 }
1106 }
1107 };
1108
1109 public void resetQSBScroll() {
1110 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001111 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001112 }
1113
1114 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001115 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1116 // by a onResume or by scrolling otherwise.
1117 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001118
1119 // Custom content is completely hidden
1120 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001121
1122 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1123 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001124
1125 // Indicates whether the user is allowed to scroll away from the custom content.
1126 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001127 }
1128
Jorim Jaggid017f882014-01-14 17:08:48 -08001129 protected boolean hasSettings() {
1130 return false;
1131 }
1132
Adam Cohenbffe7452013-07-22 18:21:45 -07001133 public interface QSBScroller {
1134 public void setScrollY(int scrollY);
1135 }
1136
Winson Chung98ca0f72013-07-29 12:58:51 -07001137 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001138 CustomContentCallbacks callbacks, String description) {
1139 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001140 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001141 }
1142
Adam Cohenedb40762013-07-18 16:45:45 -07001143 // The custom content needs to offset its content to account for the QSB
1144 public int getTopOffsetForCustomContent() {
1145 return mWorkspace.getPaddingTop();
1146 }
1147
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001148 @Override
1149 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001150 // Flag the loader to stop early before switching
1151 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001152 if (mAppsCustomizeContent != null) {
1153 mAppsCustomizeContent.surrender();
1154 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001155 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001156 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001157
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001158 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001159 @Override
1160 public void onWindowFocusChanged(boolean hasFocus) {
1161 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001162 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001163 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001164
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 private boolean acceptFilter() {
1166 final InputMethodManager inputManager = (InputMethodManager)
1167 getSystemService(Context.INPUT_METHOD_SERVICE);
1168 return !inputManager.isFullscreenMode();
1169 }
1170
1171 @Override
1172 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001173 final int uniChar = event.getUnicodeChar();
1174 final boolean handled = super.onKeyDown(keyCode, event);
1175 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1176 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1178 keyCode, event);
1179 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001180 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001181 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001182 // showSearchDialog()
1183 // If there are multiple keystrokes before the search dialog takes focus,
1184 // onSearchRequested() will be called for every keystroke,
1185 // but it is idempotent, so it's fine.
1186 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001187 }
1188 }
1189
Joe Onorato8a9625e2010-01-28 15:55:35 -08001190 // Eat the long press event so the keyboard doesn't come up.
1191 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1192 return true;
1193 }
1194
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 return handled;
1196 }
1197
Karl Rosaen138a0412009-04-23 19:00:21 -07001198 private String getTypedText() {
1199 return mDefaultKeySsb.toString();
1200 }
1201
1202 private void clearTypedText() {
1203 mDefaultKeySsb.clear();
1204 mDefaultKeySsb.clearSpans();
1205 Selection.setSelection(mDefaultKeySsb, 0);
1206 }
1207
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001209 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1210 * State
1211 */
1212 private static State intToState(int stateOrdinal) {
1213 State state = State.WORKSPACE;
1214 final State[] stateValues = State.values();
1215 for (int i = 0; i < stateValues.length; i++) {
1216 if (stateValues[i].ordinal() == stateOrdinal) {
1217 state = stateValues[i];
1218 break;
1219 }
1220 }
1221 return state;
1222 }
1223
1224 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225 * Restores the previous state, if it exists.
1226 *
1227 * @param savedState The previous state.
1228 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001229 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 private void restoreState(Bundle savedState) {
1231 if (savedState == null) {
1232 return;
1233 }
1234
Michael Jurka883f55b2010-10-21 15:47:14 -07001235 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001236 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001237 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001238 }
1239
Adam Cohen21cd0022013-10-09 18:57:02 -07001240 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1241 PagedView.INVALID_RESTORE_PAGE);
1242 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001243 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001244 }
1245
Winson Chung3d503fb2011-07-13 17:25:49 -07001246 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001247 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001248
Winson Chung3d503fb2011-07-13 17:25:49 -07001249 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1250 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001251 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001252 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1253 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001254 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1255 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1256 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001257 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001258 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 mRestoring = true;
1260 }
1261
1262 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1263 if (renameFolder) {
1264 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001265 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001266 mRestoring = true;
1267 }
Winson Chunga12a2502010-12-20 14:41:35 -08001268
Winson Chung785d2eb2011-04-14 16:08:02 -07001269 // Restore the AppsCustomize tab
1270 if (mAppsCustomizeTabHost != null) {
1271 String curTab = savedState.getString("apps_customize_currentTab");
1272 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001273 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001274 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001275 mAppsCustomizeContent.loadAssociatedPages(
1276 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001277 }
1278
Winson Chung5afbf7b2011-07-25 11:53:08 -07001279 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1280 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001281 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001282 mItemIdToViewId = (HashMap<Integer, Integer>)
1283 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284 }
1285
1286 /**
1287 * Finds all the views we need and configure them properly.
1288 */
1289 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001290 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001291
Craig Mautner360310b2012-10-26 15:13:08 -07001292 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001293 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1294 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001295 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001296 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001297
John Spurlock77e1f472013-09-11 10:09:51 -04001298 mLauncherView.setSystemUiVisibility(
1299 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001300 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301
Winson Chung4c98d922011-05-31 16:50:48 -07001302 // Setup the drag layer
1303 mDragLayer.setup(this, dragController);
1304
Winson Chung3d503fb2011-07-13 17:25:49 -07001305 // Setup the hotseat
1306 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1307 if (mHotseat != null) {
1308 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001309 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001310 }
1311
Jorim Jaggid017f882014-01-14 17:08:48 -08001312 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001313 View widgetButton = findViewById(R.id.widget_button);
1314 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001315 @Override
1316 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001317 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001318 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001319 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001320 }
1321 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001322 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1323
1324 View wallpaperButton = findViewById(R.id.wallpaper_button);
1325 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001326 @Override
1327 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001328 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001329 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001330 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001331 }
1332 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001333 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1334
1335 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001336 if (hasSettings()) {
1337 settingsButton.setOnClickListener(new OnClickListener() {
1338 @Override
1339 public void onClick(View arg0) {
1340 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001341 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001342 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001343 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001344 });
1345 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1346 } else {
1347 settingsButton.setVisibility(View.GONE);
1348 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1349 lp.gravity = Gravity.END | Gravity.TOP;
1350 widgetButton.requestLayout();
1351 }
1352
Adam Cohendbdff6b2013-09-18 19:09:15 -07001353 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001354
Winson Chung4c98d922011-05-31 16:50:48 -07001355 // Setup the workspace
1356 mWorkspace.setHapticFeedbackEnabled(false);
1357 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001358 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001359 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001360
Winson Chungf0ea4d32011-06-06 14:27:16 -07001361 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001362 mSearchDropTargetBar = (SearchDropTargetBar)
1363 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001364
Winson Chungf0ea4d32011-06-06 14:27:16 -07001365 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001366 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001367 mAppsCustomizeContent = (AppsCustomizePagedView)
1368 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1369 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001370
Winson Chung3d503fb2011-07-13 17:25:49 -07001371 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001372 dragController.setDragScoller(mWorkspace);
1373 dragController.setScrollView(mDragLayer);
1374 dragController.setMoveTarget(mWorkspace);
1375 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001376 if (mSearchDropTargetBar != null) {
1377 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001378 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001379
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001380 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001381 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001382 mWeightWatcher = new WeightWatcher(this);
1383 mWeightWatcher.setAlpha(0.5f);
1384 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001385 new FrameLayout.LayoutParams(
1386 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001387 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001388 Gravity.BOTTOM)
1389 );
Adam Cohen39a06042013-07-19 14:30:12 -07001390
1391 boolean show = shouldShowWeightWatcher();
1392 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001393 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394 }
1395
1396 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001397 * Sets the all apps button. This method is called from {@link Hotseat}.
1398 */
1399 public void setAllAppsButton(View allAppsButton) {
1400 mAllAppsButton = allAppsButton;
1401 }
1402
1403 public View getAllAppsButton() {
1404 return mAllAppsButton;
1405 }
1406
1407 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 * Creates a view representing a shortcut.
1409 *
1410 * @param info The data structure describing the shortcut.
1411 *
1412 * @return A View inflated from R.layout.application.
1413 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001414 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001415 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001416 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 }
1418
1419 /**
1420 * Creates a view representing a shortcut inflated from the specified resource.
1421 *
1422 * @param layoutResId The id of the XML layout used to create the shortcut.
1423 * @param parent The group the shortcut belongs to.
1424 * @param info The data structure describing the shortcut.
1425 *
1426 * @return A View inflated from layoutResId.
1427 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001428 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001429 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001430 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 return favorite;
1433 }
1434
1435 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 * Add a shortcut to the workspace.
1437 *
1438 * @param data The intent describing the shortcut.
1439 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001441 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001442 int cellY) {
1443 int[] cellXY = mTmpAddItemCellCoordinates;
1444 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001445 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001446
Michael Jurkad3ef3062010-11-23 16:23:58 -08001447 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001448
Adam Cohen558baaf2011-08-15 15:22:57 -07001449 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001450 if (info == null) {
1451 return;
1452 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001453 final View view = createShortcut(info);
1454
Adam Cohenfbba09b2011-07-18 21:43:05 -07001455 // First we check if we already know the exact location where we want to add this item.
1456 if (cellX >= 0 && cellY >= 0) {
1457 cellXY[0] = cellX;
1458 cellXY[1] = cellY;
1459 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001460
1461 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001462 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001463 true, null,null)) {
1464 return;
1465 }
1466 DragObject dragObject = new DragObject();
1467 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001468 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1469 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001470 return;
1471 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001472 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001473 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001474 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001475 foundCellSpan = (result != null);
1476 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001477 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001478 }
1479
1480 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001481 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001482 return;
1483 }
1484
Adam Cohendcd297f2013-06-18 13:13:40 -07001485 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486
1487 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001488 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001489 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001490 }
1491 }
1492
Adam Cohen2f093b62012-04-30 18:59:53 -07001493 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1494 int minHeight) {
1495 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001496 // We want to account for the extra amount of padding that we are adding to the widget
1497 // to ensure that it gets the full amount of space that it has requested
1498 int requiredWidth = minWidth + padding.left + padding.right;
1499 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001500 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001501 }
1502
Adam Cohen2f093b62012-04-30 18:59:53 -07001503 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1504 return getSpanForWidget(context, info.provider, 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, AppWidgetProviderInfo info) {
1508 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001509 }
1510
Adam Cohen2f093b62012-04-30 18:59:53 -07001511 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1512 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001513 }
1514
Adam Cohen2f093b62012-04-30 18:59:53 -07001515 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1516 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001517 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001518 }
1519
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001521 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001523 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001524 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001526 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001527 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1528 if (appWidgetInfo == null) {
1529 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1530 }
Romain Guycbb89e42009-06-08 15:52:54 -07001531
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001532 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001533 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001534
Adam Cohen2f093b62012-04-30 18:59:53 -07001535 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1536 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001537
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001539 // We have saved the position to which the widget was dragged-- this really only matters
1540 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001541 int[] cellXY = mTmpAddItemCellCoordinates;
1542 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001543 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001544 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001545 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1546 cellXY[0] = mPendingAddInfo.cellX;
1547 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001548 spanXY[0] = mPendingAddInfo.spanX;
1549 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001550 foundCellSpan = true;
1551 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001552 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001553 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001554 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1555 spanXY[1], cellXY, finalSpan);
1556 spanXY[0] = finalSpan[0];
1557 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001558 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001559 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001560 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001561 }
1562
Michael Jurka0280c3b2010-09-17 15:00:07 -07001563 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001564 if (appWidgetId != -1) {
1565 // Deleting an app widget ID is a void call but writes to disk before returning
1566 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001567 new AsyncTask<Void, Void, Void>() {
1568 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001569 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001570 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001571 }
Michael Jurka43467462013-11-14 12:03:58 +01001572 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001573 }
Winson Chung93eef082012-03-23 15:59:27 -07001574 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001575 return;
1576 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001578 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001579 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1580 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001581 launcherInfo.spanX = spanXY[0];
1582 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001583 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1584 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001585
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001587 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588
1589 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001590 if (hostView == null) {
1591 // Perform actual inflation because we're live
1592 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1593 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1594 } else {
1595 // The AppWidgetHostView has already been inflated and instantiated
1596 launcherInfo.hostView = hostView;
1597 }
Romain Guycbb89e42009-06-08 15:52:54 -07001598
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001600 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001601 launcherInfo.notifyWidgetSizeChanged(this);
1602
Adam Cohendcd297f2013-06-18 13:13:40 -07001603 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001604 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001605
1606 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001608 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001609 }
Romain Guycbb89e42009-06-08 15:52:54 -07001610
Adam Cohended9f8d2010-11-03 13:25:16 -07001611 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1612 @Override
1613 public void onReceive(Context context, Intent intent) {
1614 final String action = intent.getAction();
1615 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1616 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001617 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001618 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001619
Winson Chungc100e8e2011-08-09 16:02:43 -07001620 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001621 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001622 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001623 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001624 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001625 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1626 mUserPresent = true;
1627 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001628 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1629 mModel.resetLoadedState(false, true);
1630 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1631 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1632 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1633 mModel.resetLoadedState(false, true);
1634 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1635 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1636 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001637 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1638 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1639 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001640 }
1641 }
1642 };
1643
1644 @Override
1645 public void onAttachedToWindow() {
1646 super.onAttachedToWindow();
1647
1648 // Listen for broadcasts related to user-presence
1649 final IntentFilter filter = new IntentFilter();
1650 filter.addAction(Intent.ACTION_SCREEN_OFF);
1651 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001652 // For handling managed profiles
1653 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1654 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001655 if (ENABLE_DEBUG_INTENTS) {
1656 filter.addAction(DebugIntents.DELETE_DATABASE);
1657 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1658 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001659 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001660 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001661 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001662 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001663 mVisible = true;
1664 }
1665
Adam Cohen0b395352014-06-09 22:54:36 +00001666 /**
1667 * Sets up transparent navigation and status bars in LMP.
1668 * This method is a no-op for other platform versions.
1669 */
1670 @TargetApi(19)
1671 private void setupTransparentSystemBarsForLmp() {
1672 // TODO(sansid): use the APIs directly when compiling against L sdk.
1673 // Currently we use reflection to access the flags and the API to set the transparency
1674 // on the System bars.
1675 if (Utilities.isLmp()) {
1676 try {
1677 getWindow().getAttributes().systemUiVisibility |=
1678 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1679 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1680 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1681 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1682 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1683 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1684 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1685 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1686
1687 Method setStatusBarColorMethod =
1688 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1689 Method setNavigationBarColorMethod =
1690 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1691 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1692 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1693 } catch (NoSuchFieldException e) {
1694 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1695 } catch (NoSuchMethodException ex) {
1696 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1697 } catch (IllegalAccessException e) {
1698 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1699 } catch (IllegalArgumentException e) {
1700 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1701 } catch (InvocationTargetException e) {
1702 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1703 } finally {}
1704 }
1705 }
1706
Adam Cohended9f8d2010-11-03 13:25:16 -07001707 @Override
1708 public void onDetachedFromWindow() {
1709 super.onDetachedFromWindow();
1710 mVisible = false;
1711
Adam Cohend113e0c2010-11-11 10:48:05 -08001712 if (mAttached) {
1713 unregisterReceiver(mReceiver);
1714 mAttached = false;
1715 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001716 updateRunning();
1717 }
1718
1719 public void onWindowVisibilityChanged(int visibility) {
1720 mVisible = visibility == View.VISIBLE;
1721 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001722 // The following code used to be in onResume, but it turns out onResume is called when
1723 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1724 // is a more appropriate event to handle
1725 if (mVisible) {
1726 mAppsCustomizeTabHost.onWindowVisible();
1727 if (!mWorkspaceLoading) {
1728 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001729 // We want to let Launcher draw itself at least once before we force it to build
1730 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001731 // apps is nice and speedy.
1732 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001733 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001734 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001735 if (mStarted) return;
1736 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001737 // We delay the layer building a bit in order to give
1738 // other message processing a time to run. In particular
1739 // this avoids a delay in hiding the IME if it was
1740 // currently shown, because doing that may involve
1741 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001742 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001743 final ViewTreeObserver.OnDrawListener listener = this;
1744 mWorkspace.post(new Runnable() {
1745 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001746 if (mWorkspace != null &&
1747 mWorkspace.getViewTreeObserver() != null) {
1748 mWorkspace.getViewTreeObserver().
1749 removeOnDrawListener(listener);
1750 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001751 }
1752 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001753 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001754 }
1755 });
1756 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001757 // When Launcher comes back to foreground, a different Activity might be responsible for
1758 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001759 if (!DISABLE_MARKET_BUTTON) {
1760 updateAppMarketIcon();
1761 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001762 clearTypedText();
1763 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001764 }
1765
1766 private void sendAdvanceMessage(long delay) {
1767 mHandler.removeMessages(ADVANCE_MSG);
1768 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1769 mHandler.sendMessageDelayed(msg, delay);
1770 mAutoAdvanceSentTime = System.currentTimeMillis();
1771 }
1772
1773 private void updateRunning() {
1774 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1775 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1776 mAutoAdvanceRunning = autoAdvanceRunning;
1777 if (autoAdvanceRunning) {
1778 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1779 sendAdvanceMessage(delay);
1780 } else {
1781 if (!mWidgetsToAdvance.isEmpty()) {
1782 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1783 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1784 }
1785 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001786 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001787 }
1788 }
1789 }
1790
1791 private final Handler mHandler = new Handler() {
1792 @Override
1793 public void handleMessage(Message msg) {
1794 if (msg.what == ADVANCE_MSG) {
1795 int i = 0;
1796 for (View key: mWidgetsToAdvance.keySet()) {
1797 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1798 final int delay = mAdvanceStagger * i;
1799 if (v instanceof Advanceable) {
1800 postDelayed(new Runnable() {
1801 public void run() {
1802 ((Advanceable) v).advance();
1803 }
1804 }, delay);
1805 }
1806 i++;
1807 }
1808 sendAdvanceMessage(mAdvanceInterval);
1809 }
1810 }
1811 };
1812
1813 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001814 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001815 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1816 if (v instanceof Advanceable) {
1817 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001818 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001819 updateRunning();
1820 }
1821 }
1822
1823 void removeWidgetToAutoAdvance(View hostView) {
1824 if (mWidgetsToAdvance.containsKey(hostView)) {
1825 mWidgetsToAdvance.remove(hostView);
1826 updateRunning();
1827 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001828 }
1829
Joe Onorato9c1289c2009-08-17 11:03:03 -04001830 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001831 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001832 launcherInfo.hostView = null;
1833 }
1834
Winson Chung93eef082012-03-23 15:59:27 -07001835 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1836 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1837 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001838 }
1839
Winson Chunga6945242014-01-08 14:04:34 -08001840 public DragLayer getDragLayer() {
1841 return mDragLayer;
1842 }
1843
1844 public Workspace getWorkspace() {
1845 return mWorkspace;
1846 }
1847
1848 public Hotseat getHotseat() {
1849 return mHotseat;
1850 }
1851
Jorim Jaggid017f882014-01-14 17:08:48 -08001852 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001853 return mOverviewPanel;
1854 }
1855
1856 public SearchDropTargetBar getSearchBar() {
1857 return mSearchDropTargetBar;
1858 }
1859
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001860 public LauncherAppWidgetHost getAppWidgetHost() {
1861 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001862 }
Romain Guycbb89e42009-06-08 15:52:54 -07001863
Winson Chunga9abd0e2010-10-27 17:18:37 -07001864 public LauncherModel getModel() {
1865 return mModel;
1866 }
1867
Winson Chunga6945242014-01-08 14:04:34 -08001868 public LauncherClings getLauncherClings() {
1869 return mLauncherClings;
1870 }
1871
1872 protected SharedPreferences getSharedPrefs() {
1873 return mSharedPrefs;
1874 }
1875
Bjorn Bringertc459e522013-06-07 19:36:01 +01001876 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001877 getWindow().closeAllPanels();
1878
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001879 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001880 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001881 }
1882
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 @Override
1884 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001885 long startTime = 0;
1886 if (DEBUG_RESUME_TIME) {
1887 startTime = System.currentTimeMillis();
1888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 super.onNewIntent(intent);
1890
1891 // Close the menu
1892 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001893 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001894 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001895
Adam Cohened307df2013-10-02 09:37:31 -07001896 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1897 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1898 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001899
Adam Cohen6fecd412013-10-02 17:41:50 -07001900 if (mWorkspace == null) {
1901 // Can be cases where mWorkspace is null, this prevents a NPE
1902 return;
1903 }
1904 Folder openFolder = mWorkspace.getOpenFolder();
1905 // In all these cases, only animate if we're already on home
1906 mWorkspace.exitWidgetResizeMode();
1907 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001908 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001909 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001910 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001911
Adam Cohen6fecd412013-10-02 17:41:50 -07001912 closeFolder();
1913 exitSpringLoadedDragMode();
1914
1915 // If we are already on home, then just animate back to the workspace,
1916 // otherwise, just wait until onResume to set the state back to Workspace
1917 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001918 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001919 } else {
1920 mOnResumeState = State.WORKSPACE;
1921 }
1922
1923 final View v = getWindow().peekDecorView();
1924 if (v != null && v.getWindowToken() != null) {
1925 InputMethodManager imm = (InputMethodManager)getSystemService(
1926 INPUT_METHOD_SERVICE);
1927 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1928 }
1929
1930 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001931 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001932 mAppsCustomizeTabHost.reset();
1933 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001934
1935 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 }
Adam Cohened307df2013-10-02 09:37:31 -07001937
Michael Jurka447bf842013-05-15 14:52:15 +02001938 if (DEBUG_RESUME_TIME) {
1939 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1940 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 }
1942
Adam Coppa120b8e2013-11-12 16:26:04 +00001943 /**
1944 * Override point for subclasses to prevent movement to the default screen when the home
1945 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1946 */
1947 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1948 return true;
1949 }
1950
1951 /**
1952 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1953 */
1954 protected void onHomeIntent() {
1955 // Do nothing
1956 }
1957
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001958 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001959 public void onRestoreInstanceState(Bundle state) {
1960 super.onRestoreInstanceState(state);
1961 for (int page: mSynchronouslyBoundPages) {
1962 mWorkspace.restoreInstanceStateForChild(page);
1963 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 }
1965
1966 @Override
1967 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001968 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001969 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1970 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001971 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001972 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973
Michael Jurka883f55b2010-10-21 15:47:14 -07001974 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001975 // We close any open folder since it will not be re-opened, and we need to make sure
1976 // this state is reflected.
1977 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001978
Adam Cohendcd297f2013-06-18 13:13:40 -07001979 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001980 mWaitingForResult) {
1981 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001982 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001983 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1984 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001985 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1986 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1987 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001988 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 }
1990
1991 if (mFolderInfo != null && mWaitingForResult) {
1992 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1993 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1994 }
Michael Jurka946ad472010-07-09 18:05:18 -07001995
Winson Chung785d2eb2011-04-14 16:08:02 -07001996 // Save the current AppsCustomize tab
1997 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001998 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1999 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07002000 if (currentTabTag != null) {
2001 outState.putString("apps_customize_currentTab", currentTabTag);
2002 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002003 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2004 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002005 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002006 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 }
2008
2009 @Override
2010 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002012
Winson Chunge7a03942011-08-05 15:05:12 -07002013 // Remove all pending runnables
2014 mHandler.removeMessages(ADVANCE_MSG);
2015 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002016 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002017
Winson Chungcd2b0142011-06-08 16:02:26 -07002018 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002019 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002020 mModel.stopLoader();
2021 app.setLauncher(null);
2022
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002024 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002026 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002028 mAppWidgetHost = null;
2029
2030 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031
2032 TextKeyListener.getInstance().release();
2033
Winson Chung81b52252012-08-27 15:34:29 -07002034 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2035 // to prevent leaking Launcher activities on orientation change.
2036 if (mModel != null) {
2037 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2038 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002039
2040 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002041 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002042
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002043 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002044 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002045 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002046 mWorkspace = null;
2047 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002048
Sunny Goyale755d462014-07-22 13:48:29 -07002049 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002050 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 }
2052
Adam Cohena9cf38f2011-05-02 15:36:58 -07002053 public DragController getDragController() {
2054 return mDragController;
2055 }
2056
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002057 @Override
2058 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002059 if (requestCode >= 0) {
2060 setWaitingForResult(true);
2061 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 super.startActivityForResult(intent, requestCode);
2063 }
2064
Winson Chung70d72102011-08-12 11:24:35 -07002065 /**
2066 * Indicates that we want global search for this activity by setting the globalSearch
2067 * argument for {@link #startSearch} to true.
2068 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002069 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002070 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002072
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002073 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002074
Karl Rosaen138a0412009-04-23 19:00:21 -07002075 if (initialQuery == null) {
2076 // Use any text typed in the launcher as the initial query
2077 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002078 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 if (appSearchData == null) {
2080 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002081 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 }
Winson Chungadf0c182012-08-23 14:59:07 -07002083 Rect sourceBounds = new Rect();
2084 if (mSearchDropTargetBar != null) {
2085 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2086 }
Romain Guycbb89e42009-06-08 15:52:54 -07002087
Bjorn Bringertc459e522013-06-07 19:36:01 +01002088 startSearch(initialQuery, selectInitialQuery,
2089 appSearchData, sourceBounds);
2090 }
2091
2092 public void startSearch(String initialQuery,
2093 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002094 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002095 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002096 }
2097
2098 /**
2099 * Starts the global search activity. This code is a copied from SearchManager
2100 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002101 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002102 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002103 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002104 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2105 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2106 if (globalSearchActivity == null) {
2107 Log.w(TAG, "No global search activity found.");
2108 return;
2109 }
2110 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2111 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2112 intent.setComponent(globalSearchActivity);
2113 // Make sure that we have a Bundle to put source in
2114 if (appSearchData == null) {
2115 appSearchData = new Bundle();
2116 } else {
2117 appSearchData = new Bundle(appSearchData);
2118 }
2119 // Set source to package name of app that starts global search, if not set already.
2120 if (!appSearchData.containsKey("source")) {
2121 appSearchData.putString("source", getPackageName());
2122 }
2123 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2124 if (!TextUtils.isEmpty(initialQuery)) {
2125 intent.putExtra(SearchManager.QUERY, initialQuery);
2126 }
2127 if (selectInitialQuery) {
2128 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2129 }
2130 intent.setSourceBounds(sourceBounds);
2131 try {
2132 startActivity(intent);
2133 } catch (ActivityNotFoundException ex) {
2134 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2135 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136 }
2137
Yura4f93ec62014-02-04 14:15:21 +00002138 public boolean isOnCustomContent() {
2139 return mWorkspace.isOnOrMovingToCustomContent();
2140 }
2141
Winson Chung70d72102011-08-12 11:24:35 -07002142 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002143 public boolean onPrepareOptionsMenu(Menu menu) {
2144 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002145 if (!isOnCustomContent()) {
2146 // Close any open folders
2147 closeFolder();
2148 // Stop resizing any widgets
2149 mWorkspace.exitWidgetResizeMode();
2150 if (!mWorkspace.isInOverviewMode()) {
2151 // Show the overview mode
2152 showOverviewMode(true);
2153 } else {
2154 showWorkspace(true);
2155 }
Winson Chunge0298742014-01-17 12:03:00 -08002156 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002157 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002158 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002160 @Override
2161 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002162 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002163 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002164 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002165 }
2166
Joe Onorato9c1289c2009-08-17 11:03:03 -04002167 public boolean isWorkspaceLocked() {
2168 return mWorkspaceLoading || mWaitingForResult;
2169 }
2170
Adam Cohen517a7f52014-03-01 12:12:59 -08002171 public boolean isWorkspaceLoading() {
2172 return mWorkspaceLoading;
2173 }
2174
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002175 private void setWorkspaceLoading(boolean value) {
2176 boolean isLocked = isWorkspaceLocked();
2177 mWorkspaceLoading = value;
2178 if (isLocked != isWorkspaceLocked()) {
2179 onWorkspaceLockedChanged();
2180 }
2181 }
2182
2183 private void setWaitingForResult(boolean value) {
2184 boolean isLocked = isWorkspaceLocked();
2185 mWaitingForResult = value;
2186 if (isLocked != isWorkspaceLocked()) {
2187 onWorkspaceLockedChanged();
2188 }
2189 }
2190
2191 protected void onWorkspaceLockedChanged() { }
2192
Michael Jurka0280c3b2010-09-17 15:00:07 -07002193 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002194 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002195 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002196 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2197 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002198 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002199 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002200 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002201
Adam Cohenad4e15c2013-10-17 16:21:35 -07002202 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2203 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2204 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2205 }
2206
2207 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2208 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2209 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002210 if (appWidgetInfo.configure != null) {
2211 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002212 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002213
Bjorn Bringert7984c942009-12-09 15:38:25 +00002214 // Launch over to configure widget, if needed
2215 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002216 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002217 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002218 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002219 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002220 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002221 Runnable onComplete = new Runnable() {
2222 @Override
2223 public void run() {
2224 // Exit spring loaded mode if necessary after adding the widget
2225 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2226 null);
2227 }
2228 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002229 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002230 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002231 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002232 }
2233 }
Romain Guycbb89e42009-06-08 15:52:54 -07002234
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002235 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002236 // Close any folders that may be open.
2237 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002238 mWorkspace.moveToCustomContentScreen(animate);
2239 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002240 /**
2241 * Process a shortcut drop.
2242 *
2243 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002244 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002245 * @param cell The cell it should be added to, optional
2246 * @param position The location on the screen where it was dropped, optional
2247 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002248 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002249 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002250 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002251 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002252 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002253 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002254
2255 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002256 mPendingAddInfo.cellX = cell[0];
2257 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002258 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002259
2260 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2261 createShortcutIntent.setComponent(componentName);
2262 processShortcut(createShortcutIntent);
2263 }
2264
Adam Cohenfbba09b2011-07-18 21:43:05 -07002265 /**
2266 * Process a widget drop.
2267 *
2268 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002269 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002270 * @param cell The cell it should be added to, optional
2271 * @param position The location on the screen where it was dropped, optional
2272 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002273 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002274 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002275 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002276 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002277 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002278 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002279 mPendingAddInfo.minSpanX = info.minSpanX;
2280 mPendingAddInfo.minSpanY = info.minSpanY;
2281
Adam Cohenfbba09b2011-07-18 21:43:05 -07002282 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002283 mPendingAddInfo.cellX = cell[0];
2284 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002285 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002286 if (span != null) {
2287 mPendingAddInfo.spanX = span[0];
2288 mPendingAddInfo.spanY = span[1];
2289 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002290
Adam Cohened66b2b2012-01-23 17:28:51 -08002291 AppWidgetHostView hostView = info.boundWidget;
2292 int appWidgetId;
2293 if (hostView != null) {
2294 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002295 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002296 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002297 // In this case, we either need to start an activity to get permission to bind
2298 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002299 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002300 Bundle options = info.bindOptions;
2301
2302 boolean success = false;
2303 if (options != null) {
2304 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2305 info.componentName, options);
2306 } else {
2307 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2308 info.componentName);
2309 }
2310 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002311 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002312 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002313 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002314 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2315 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2316 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002317 // TODO: we need to make sure that this accounts for the options bundle.
2318 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002319 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2320 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002321 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002322 }
2323
Joe Onoratodeb98af2010-02-19 14:59:39 -08002324 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002325 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326 }
2327
Winson Chung24ab2f12010-09-16 14:10:47 -07002328 void processWallpaper(Intent intent) {
2329 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2330 }
2331
Adam Cohendcd297f2013-06-18 13:13:40 -07002332 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002333 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002334 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002335 folderInfo.title = getText(R.string.folder_name);
2336
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002337 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002338 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002339 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002340 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002341
2342 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002343 FolderIcon newFolder =
2344 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002345 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002346 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002347 // Force measure the new folder icon
2348 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2349 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002350 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002351 }
Romain Guycbb89e42009-06-08 15:52:54 -07002352
Joe Onorato9c1289c2009-08-17 11:03:03 -04002353 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002354 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002355 }
2356
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002357 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002358 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002359 }
2360
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002361 /**
2362 * Registers various content observers. The current implementation registers
2363 * only a favorites observer to keep track of the favorites applications.
2364 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002365 private void registerContentObservers() {
2366 ContentResolver resolver = getContentResolver();
2367 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2368 true, mWidgetObserver);
2369 }
2370
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 @Override
2372 public boolean dispatchKeyEvent(KeyEvent event) {
2373 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2374 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002376 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002377 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002378 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002379 dumpState();
2380 return true;
2381 }
2382 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002383 }
2384 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2385 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002386 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 return true;
2388 }
2389 }
2390
2391 return super.dispatchKeyEvent(event);
2392 }
2393
Joe Onorato88ec0992009-11-19 13:16:06 -08002394 @Override
2395 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002396 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002397 if (mAppsCustomizeContent.getContentType() ==
2398 AppsCustomizePagedView.ContentType.Applications) {
2399 showWorkspace(true);
2400 } else {
2401 showOverviewMode(true);
2402 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002403 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002404 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002405 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002406 Folder openFolder = mWorkspace.getOpenFolder();
2407 if (openFolder.isEditingName()) {
2408 openFolder.dismissEditingName();
2409 } else {
2410 closeFolder();
2411 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002412 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002413 mWorkspace.exitWidgetResizeMode();
2414
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002415 // Back button is a no-op here, but give at least some feedback for the button press
2416 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002417 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002418 }
2419
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002420 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002421 * Re-listen when widgets are reset.
2422 */
2423 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002424 if (mAppWidgetHost != null) {
2425 mAppWidgetHost.startListening();
2426 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002427 }
2428
2429 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430 * Launches the intent referred by the clicked shortcut.
2431 *
2432 * @param v The view representing the clicked shortcut.
2433 */
2434 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002435 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2436 // view has detached (it's possible for this to happen if the view is removed mid touch).
2437 if (v.getWindowToken() == null) {
2438 return;
2439 }
2440
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002441 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002442 return;
2443 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002444
Adam Cohen1697b792013-09-17 19:08:21 -07002445 if (v instanceof Workspace) {
2446 if (mWorkspace.isInOverviewMode()) {
2447 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002448 }
2449 return;
2450 }
2451
2452 if (v instanceof CellLayout) {
2453 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002454 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002455 }
2456 }
2457
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002458 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002459 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002460 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002461 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002462 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002463 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002464 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002465 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002466 onClickAllAppsButton(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002467 } else if (tag instanceof LauncherAppWidgetInfo) {
2468 if (v instanceof PendingAppWidgetHostView) {
2469 onClickPendingWidget((PendingAppWidgetHostView) v);
2470 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002471 }
2472 }
2473
Michael Jurka0e260592010-06-30 17:07:39 -07002474 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002475 return false;
2476 }
2477
Michael Jurkaaf442092010-06-10 17:01:57 -07002478 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002479 * Event handler for the app widget view which has not fully restored.
2480 */
2481 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2482 if (v.isReadyForClickSetup()) {
2483 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2484 int widgetId = info.appWidgetId;
2485 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2486 if (appWidgetInfo != null) {
2487 mPendingAddWidgetInfo = appWidgetInfo;
2488 mPendingAddInfo.copyFrom(info);
2489 mPendingAddWidgetId = widgetId;
2490
2491 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2492 intent.setComponent(appWidgetInfo.configure);
2493 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2494 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2495 }
2496 }
2497 }
2498
2499 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002500 * Event handler for the search button
2501 *
2502 * @param v The view that was clicked.
2503 */
2504 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002505 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2506
Amith Yamasania135ba82011-08-09 17:42:01 -07002507 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002508 }
2509
2510 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002511 * Event handler for the voice button
2512 *
2513 * @param v The view that was clicked.
2514 */
2515 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002516 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002517
Bjorn Bringertc459e522013-06-07 19:36:01 +01002518 startVoice();
2519 }
2520
2521 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002522 try {
2523 final SearchManager searchManager =
2524 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2525 ComponentName activityName = searchManager.getGlobalSearchActivity();
2526 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002527 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002528 if (activityName != null) {
2529 intent.setPackage(activityName.getPackageName());
2530 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002531 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002532 } catch (ActivityNotFoundException e) {
2533 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002534 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002535 startActivitySafely(null, intent, "onClickVoiceButton");
2536 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002537 }
2538
2539 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002540 * Event handler for the "grid" button that appears on the home screen, which
2541 * enters all apps mode.
2542 *
2543 * @param v The view that was clicked.
2544 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002545 protected void onClickAllAppsButton(View v) {
2546 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2547 if (isAllAppsVisible()) {
2548 showWorkspace(true);
2549 } else {
2550 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2551 }
2552 }
2553
2554 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002555 * Event handler for a paged view icon click.
2556 * @param v The view that was clicked.
2557 * @param appInfo The {link AppInfo} of the view.
2558 */
2559 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2560 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2561 startActivitySafely(v, appInfo.intent, appInfo);
2562 getStats().recordLaunch(appInfo.intent);
2563 }
2564
2565 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002566 * Event handler for an app shortcut click.
2567 *
2568 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2569 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002570 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002571 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2572 Object tag = v.getTag();
2573 if (!(tag instanceof ShortcutInfo)) {
2574 throw new IllegalArgumentException("Input must be a Shortcut");
2575 }
2576
2577 // Open shortcut
2578 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2579 final Intent intent = shortcut.intent;
2580
2581 // Check for special shortcuts
2582 if (intent.getComponent() != null) {
2583 final String shortcutClass = intent.getComponent().getClassName();
2584
2585 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2586 MemoryDumpActivity.startDump(this);
2587 return;
2588 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2589 toggleShowWeightWatcher();
2590 return;
2591 }
2592 }
2593
Chris Wren40c5ed32014-06-24 18:24:23 -04002594 // Check for abandoned promise
2595 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002596 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2597 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002598 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002599 builder.setPositiveButton(R.string.abandoned_search,
2600 new DialogInterface.OnClickListener() {
2601 public void onClick(DialogInterface dialog, int id) {
2602 startAppShortcutActivity(v);
2603 }
2604 }
2605 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002606 builder.setNeutralButton(R.string.abandoned_clean_this,
2607 new DialogInterface.OnClickListener() {
2608 public void onClick(DialogInterface dialog, int id) {
2609 final BubbleTextView bubble = (BubbleTextView) v;
2610 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2611 mWorkspace.removeAbandonedPromise(bubble, user);
2612 }
2613 });
2614 builder.create().show();
2615 return;
2616 }
2617
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002618 // Start activities
Chris Wren40c5ed32014-06-24 18:24:23 -04002619 startAppShortcutActivity(v);
2620 }
2621
2622 private void startAppShortcutActivity(View v) {
2623 Object tag = v.getTag();
2624 if (!(tag instanceof ShortcutInfo)) {
2625 throw new IllegalArgumentException("Input must be a Shortcut");
2626 }
2627 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2628 final Intent intent = shortcut.intent;
2629
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002630 int[] pos = new int[2];
2631 v.getLocationOnScreen(pos);
2632 intent.setSourceBounds(new Rect(pos[0], pos[1],
2633 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2634
2635 boolean success = startActivitySafely(v, intent, tag);
2636
2637 mStats.recordLaunch(intent, shortcut);
2638
2639 if (success && v instanceof BubbleTextView) {
2640 mWaitingForResume = (BubbleTextView) v;
2641 mWaitingForResume.setStayPressed(true);
2642 }
2643 }
2644
2645 /**
2646 * Event handler for a folder icon click.
2647 *
2648 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2649 */
2650 protected void onClickFolderIcon(View v) {
2651 if (LOGD) Log.d(TAG, "onClickFolder");
2652 if (!(v instanceof FolderIcon)){
2653 throw new IllegalArgumentException("Input must be a FolderIcon");
2654 }
2655
2656 FolderIcon folderIcon = (FolderIcon) v;
2657 final FolderInfo info = folderIcon.getFolderInfo();
2658 Folder openFolder = mWorkspace.getFolderForTag(info);
2659
2660 // If the folder info reports that the associated folder is open, then verify that
2661 // it is actually opened. There have been a few instances where this gets out of sync.
2662 if (info.opened && openFolder == null) {
2663 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2664 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2665 info.opened = false;
2666 }
2667
2668 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2669 // Close any open folder
2670 closeFolder();
2671 // Open the requested folder
2672 openFolder(folderIcon);
2673 } else {
2674 // Find the open folder...
2675 int folderScreen;
2676 if (openFolder != null) {
2677 folderScreen = mWorkspace.getPageForView(openFolder);
2678 // .. and close it
2679 closeFolder(openFolder);
2680 if (folderScreen != mWorkspace.getCurrentPage()) {
2681 // Close any folder open on the current screen
2682 closeFolder();
2683 // Pull the folder onto this screen
2684 openFolder(folderIcon);
2685 }
2686 }
2687 }
Michael Jurka5130e402011-10-13 04:55:35 -07002688 }
2689
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002690 /**
2691 * Event handler for the (Add) Widgets button that appears after a long press
2692 * on the home screen.
2693 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002694 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002695 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002696 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2697 }
2698
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002699 /**
2700 * Event handler for the wallpaper picker button that appears after a long press
2701 * on the home screen.
2702 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002703 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002704 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2705 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2706 pickWallpaper.setComponent(getWallpaperPickerComponent());
2707 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2708 }
2709
2710 /**
2711 * Event handler for a click on the settings button that appears after a long press
2712 * on the home screen.
2713 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002714 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002715 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2716 }
2717
Michael Jurka5130e402011-10-13 04:55:35 -07002718 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002719 // Provide the same haptic feedback that the system offers for virtual keys.
2720 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002721 }
2722
Adam Cohen61f560d2013-09-30 15:58:20 -07002723 public void performHapticFeedbackOnTouchDown(View v) {
2724 // Provide the same haptic feedback that the system offers for virtual keys.
2725 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2726 }
2727
2728 public View.OnTouchListener getHapticFeedbackTouchListener() {
2729 if (mHapticFeedbackTouchListener == null) {
2730 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2731 @Override
2732 public boolean onTouch(View v, MotionEvent event) {
2733 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2734 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2735 }
2736 return false;
2737 }
2738 };
2739 }
2740 return mHapticFeedbackTouchListener;
2741 }
2742
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002743 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002744 if (!DISABLE_MARKET_BUTTON) {
2745 if (mAppMarketIntent != null) {
2746 startActivitySafely(v, mAppMarketIntent, "app market");
2747 } else {
2748 Log.e(TAG, "Invalid app market intent.");
2749 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002750 }
2751 }
2752
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002753 public void onDragStarted(View view) {}
2754
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002755 /**
2756 * Called when the user stops interacting with the launcher.
2757 * This implies that the user is now on the homescreen and is not doing housekeeping.
2758 */
2759 protected void onInteractionEnd() {}
2760
2761 /**
2762 * Called when the user starts interacting with the launcher.
2763 * The possible interactions are:
2764 * - open all apps
2765 * - reorder an app shortcut, or a widget
2766 * - open the overview mode.
2767 * This is a good time to stop doing things that only make sense
2768 * when the user is on the homescreen and not doing housekeeping.
2769 */
2770 protected void onInteractionBegin() {}
2771
Kenny Guyf07af7b2014-07-31 11:39:16 +01002772 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002773 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002774 try {
2775 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2776 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2777 launcherApps.showAppDetailsForProfile(componentName, user);
2778 } catch (SecurityException e) {
2779 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2780 Log.e(TAG, "Launcher does not have permission to launch settings");
2781 } catch (ActivityNotFoundException e) {
2782 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2783 Log.e(TAG, "Unable to launch settings");
2784 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002785 }
2786
Michael Jurka1e2f4652013-07-08 18:03:46 -07002787 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002788 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2789 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002790 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002791 // System applications cannot be installed. For now, show a toast explaining that.
2792 // We may give them the option of disabling apps this way.
2793 int messageId = R.string.uninstall_system_app_text;
2794 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002795 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002796 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002797 String packageName = componentName.getPackageName();
2798 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002799 Intent intent = new Intent(
2800 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002801 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2802 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002803 if (user != null) {
2804 user.addToIntent(intent, Intent.EXTRA_USER);
2805 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002806 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002807 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002808 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002809 }
2810
Michael Jurka86a720e2012-05-09 11:23:23 -07002811 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002812 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002813 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002814 // Only launch using the new animation if the shortcut has not opted out (this is a
2815 // private contract between launcher and may be ignored in the future).
2816 boolean useLaunchAnimation = (v != null) &&
2817 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002818 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2819 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002820
Kenny Guy1317e2d2014-05-08 18:52:50 +01002821 UserHandleCompat user = null;
2822 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2823 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2824 user = userManager.getUserForSerialNumber(serialNumber);
2825 }
2826
2827 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002828 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002829 ActivityOptions opts = Utilities.isLmp() ?
2830 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2831 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002832 optsBundle = opts.toBundle();
2833 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002834
2835 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2836 // Could be launching some bookkeeping activity
2837 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002838 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002839 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002840 launcherApps.startActivityForProfile(intent.getComponent(), user,
2841 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002842 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002843 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002844 } catch (SecurityException e) {
2845 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002846 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002847 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002848 "or use the exported attribute for this activity. "
2849 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002850 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002851 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002852 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002853
Michael Jurka86a720e2012-05-09 11:23:23 -07002854 boolean startActivitySafely(View v, Intent intent, Object tag) {
2855 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002856 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2857 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2858 return false;
2859 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002860 try {
2861 success = startActivity(v, intent, tag);
2862 } catch (ActivityNotFoundException e) {
2863 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2864 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2865 }
2866 return success;
2867 }
2868
Adam Cohen268c4752012-06-06 17:47:33 -07002869 /**
2870 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2871 * in the DragLayer in the exact absolute location of the original FolderIcon.
2872 */
2873 private void copyFolderIconToImage(FolderIcon fi) {
2874 final int width = fi.getMeasuredWidth();
2875 final int height = fi.getMeasuredHeight();
2876
2877 // Lazy load ImageView, Bitmap and Canvas
2878 if (mFolderIconImageView == null) {
2879 mFolderIconImageView = new ImageView(this);
2880 }
2881 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2882 mFolderIconBitmap.getHeight() != height) {
2883 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2884 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2885 }
2886
2887 DragLayer.LayoutParams lp;
2888 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2889 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2890 } else {
2891 lp = new DragLayer.LayoutParams(width, height);
2892 }
2893
Adam Cohen307fe232012-08-16 17:55:58 -07002894 // The layout from which the folder is being opened may be scaled, adjust the starting
2895 // view size by this scale factor.
2896 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002897 lp.customPosition = true;
2898 lp.x = mRectForFolderAnimation.left;
2899 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002900 lp.width = (int) (scale * width);
2901 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002902
2903 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2904 fi.draw(mFolderIconCanvas);
2905 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002906 if (fi.getFolder() != null) {
2907 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2908 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002909 }
Adam Cohen268c4752012-06-06 17:47:33 -07002910 // Just in case this image view is still in the drag layer from a previous animation,
2911 // we remove it and re-add it.
2912 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2913 mDragLayer.removeView(mFolderIconImageView);
2914 }
2915 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002916 if (fi.getFolder() != null) {
2917 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002918 }
Adam Cohen268c4752012-06-06 17:47:33 -07002919 }
2920
Adam Cohen2801caf2011-05-13 20:57:39 -07002921 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002922 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002923 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2924 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2925 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2926
Adam Cohenc51934b2011-07-26 21:07:43 -07002927 FolderInfo info = (FolderInfo) fi.getTag();
2928 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2929 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002930 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2931 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002932 }
2933
Adam Cohen268c4752012-06-06 17:47:33 -07002934 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2935 copyFolderIconToImage(fi);
2936 fi.setVisibility(View.INVISIBLE);
2937
Michael Jurka2ecf9952012-06-18 12:52:28 -07002938 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002939 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002940 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2941 oa.start();
2942 }
2943
Adam Cohen268c4752012-06-06 17:47:33 -07002944 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002945 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002946 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2947 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2948 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2949
Adam Cohen268c4752012-06-06 17:47:33 -07002950 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002951
Adam Cohen268c4752012-06-06 17:47:33 -07002952 // We remove and re-draw the FolderIcon in-case it has changed
2953 mDragLayer.removeView(mFolderIconImageView);
2954 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002955 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002956 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002957 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002958 oa.addListener(new AnimatorListenerAdapter() {
2959 @Override
2960 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002961 if (cl != null) {
2962 cl.clearFolderLeaveBehind();
2963 // Remove the ImageView copy of the FolderIcon and make the original visible.
2964 mDragLayer.removeView(mFolderIconImageView);
2965 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002966 }
2967 }
2968 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002969 oa.start();
2970 }
2971
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002972 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002973 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002974 * is animated relative to the specified View. If the View is null, no animation
2975 * is played.
2976 *
2977 * @param folderInfo The FolderInfo describing the folder to open.
2978 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002979 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002980 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002981 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002982
Adam Cohena9cf38f2011-05-02 15:36:58 -07002983 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002984
Adam Cohen4554ee12011-08-03 16:13:21 -07002985 // Just verify that the folder hasn't already been added to the DragLayer.
2986 // There was a one-off crash where the folder had a parent already.
2987 if (folder.getParent() == null) {
2988 mDragLayer.addView(folder);
2989 mDragController.addDropTarget((DropTarget) folder);
2990 } else {
2991 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2992 folder.getParent() + ").");
2993 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002994 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002995 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002996
2997 // Notify the accessibility manager that this folder "window" has appeared and occluded
2998 // the workspace items
2999 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3000 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003001 }
3002
3003 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003004 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003005 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003006 if (folder.isEditingName()) {
3007 folder.dismissEditingName();
3008 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003009 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07003010
3011 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08003012 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07003013 }
3014 }
3015
3016 void closeFolder(Folder folder) {
3017 folder.getInfo().opened = false;
3018
3019 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3020 if (parent != null) {
3021 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3022 shrinkAndFadeInFolderIcon(fi);
3023 }
3024 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003025
3026 // Notify the accessibility manager that this folder "window" has disappeard and no
3027 // longer occludeds the workspace items
3028 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003029 }
3030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003031 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003032 if (!isDraggingEnabled()) return false;
3033 if (isWorkspaceLocked()) return false;
3034 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003035
Adam Cohen1697b792013-09-17 19:08:21 -07003036 if (v instanceof Workspace) {
3037 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003038 if (mWorkspace.enterOverviewMode()) {
3039 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3040 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3041 return true;
3042 } else {
3043 return false;
3044 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003045 } else {
3046 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003047 }
Adam Cohen1697b792013-09-17 19:08:21 -07003048 }
3049
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003050 CellLayout.CellInfo longClickCellInfo = null;
3051 View itemUnderLongClick = null;
3052 if (v.getTag() instanceof ItemInfo) {
3053 ItemInfo info = (ItemInfo) v.getTag();
3054 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3055 itemUnderLongClick = longClickCellInfo.cell;
3056 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003057 }
3058
Winson Chung3d503fb2011-07-13 17:25:49 -07003059 // The hotseat touch handling does not go through Workspace, and we always allow long press
3060 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003061 final boolean inHotseat = isHotseatLayout(v);
3062 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003063 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003064 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003065 // User long pressed on empty space
3066 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3067 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003068 if (mWorkspace.isInOverviewMode()) {
3069 mWorkspace.startReordering(v);
3070 } else {
3071 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003072 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003073 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003074 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3075 mHotseat.getOrderInHotseat(
3076 longClickCellInfo.cellX,
3077 longClickCellInfo.cellY));
3078 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003079 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003080 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003081 }
3082 }
3083 }
3084 return true;
3085 }
3086
Winson Chung3d503fb2011-07-13 17:25:49 -07003087 boolean isHotseatLayout(View layout) {
3088 return mHotseat != null && layout != null &&
3089 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3090 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003091
Winson Chung3d503fb2011-07-13 17:25:49 -07003092 /**
3093 * Returns the CellLayout of the specified container at the specified screen.
3094 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003095 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003096 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3097 if (mHotseat != null) {
3098 return mHotseat.getLayout();
3099 } else {
3100 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003101 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003102 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003103 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003104 }
3105 }
3106
Daniel Sandler843e8602010-06-07 14:59:01 -04003107 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003108 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003109 }
3110
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003111 /**
3112 * Helper method for the cameraZoomIn/cameraZoomOut animations
3113 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003114 * @param scaleFactor The scale factor used for the zoom
3115 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07003116 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003117 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07003118 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003119 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05003120
Craig Mautner360310b2012-10-26 15:13:08 -07003121 private void setWorkspaceBackground(boolean workspace) {
3122 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003123 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003124 }
3125
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003126 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003127 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3128 int curflags = getWindow().getAttributes().flags
3129 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3130 if (wpflags != curflags) {
3131 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3132 }
Craig Mautner360310b2012-10-26 15:13:08 -07003133 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003134 }
3135
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003136 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3137 if (v instanceof LauncherTransitionable) {
3138 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3139 }
3140 }
3141
Michael Jurkabed61d22012-02-14 22:51:29 -08003142 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3143 if (v instanceof LauncherTransitionable) {
3144 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3145 }
Winson Chung70442722012-02-10 15:43:22 -08003146
3147 // Update the workspace transition step as well
3148 dispatchOnLauncherTransitionStep(v, 0f);
3149 }
3150
3151 private void dispatchOnLauncherTransitionStep(View v, float t) {
3152 if (v instanceof LauncherTransitionable) {
3153 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3154 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003155 }
3156
3157 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3158 if (v instanceof LauncherTransitionable) {
3159 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3160 }
Winson Chung70442722012-02-10 15:43:22 -08003161
3162 // Update the workspace transition step as well
3163 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003164 }
3165
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003166 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003167 * Things to test when changing the following seven functions.
3168 * - Home from workspace
3169 * - from center screen
3170 * - from other screens
3171 * - Home from all apps
3172 * - from center screen
3173 * - from other screens
3174 * - Back from all apps
3175 * - from center screen
3176 * - from other screens
3177 * - Launch app from workspace and quit
3178 * - with back
3179 * - with home
3180 * - Launch app from all apps and quit
3181 * - with back
3182 * - with home
3183 * - Go to a screen that's not the default, then all
3184 * apps, and launch and app, and go back
3185 * - with back
3186 * -with home
3187 * - On workspace, long press power and go back
3188 * - with back
3189 * - with home
3190 * - On all apps, long press power and go back
3191 * - with back
3192 * - with home
3193 * - On workspace, power off
3194 * - On all apps, power off
3195 * - Launch an app and turn off the screen while in that app
3196 * - Go back with home key
3197 * - Go back with back key TODO: make this not go to workspace
3198 * - From all apps
3199 * - From workspace
3200 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3201 * - From all apps
3202 * - From the center workspace
3203 * - From another workspace
3204 */
3205
3206 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003207 * Zoom the camera out from the workspace to reveal 'toView'.
3208 * Assumes that the view to show is anchored at either the very top or very bottom
3209 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003210 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003211 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003212 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3213 showAppsCustomizeHelper(animated, springLoaded, contentType);
3214 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003215
Winson Chungc58497e2013-09-03 17:48:37 -07003216 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3217 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003218 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003219 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003220 mStateAnimation.cancel();
3221 mStateAnimation = null;
3222 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003223
3224 boolean material = Utilities.isLmp();
3225
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003226 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003227
Winson Chungf0ea4d32011-06-06 14:27:16 -07003228 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3229 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003230 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
3231
Winson Chungf0ea4d32011-06-06 14:27:16 -07003232 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003233 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003234 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003235 final int startDelay =
3236 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003237
Michael Jurkab3e22d92011-10-31 15:58:33 -07003238 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003239
Adam Cohen6c5891a2014-07-09 23:53:15 -07003240 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3241 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003242 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003243 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003244 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003245 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3246 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003247 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3248 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003249
3250 if (animated) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003251 if (!material) {
3252 toView.setScaleX(scale);
3253 toView.setScaleY(scale);
3254 final LauncherViewPropertyAnimator scaleAnim =
3255 new LauncherViewPropertyAnimator(toView);
3256 scaleAnim.
3257 scaleX(1f).scaleY(1f).
3258 setDuration(duration).
3259 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003260
Adam Cohen6c5891a2014-07-09 23:53:15 -07003261 toView.setVisibility(View.VISIBLE);
3262 toView.setAlpha(0f);
3263 final ObjectAnimator alphaAnim = LauncherAnimUtils
3264 .ofFloat(toView, "alpha", 0f, 1f)
3265 .setDuration(fadeDuration);
3266 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
3267 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3268 @Override
3269 public void onAnimationUpdate(ValueAnimator animation) {
3270 if (animation == null) {
3271 throw new RuntimeException("animation is null");
3272 }
3273 float t = (Float) animation.getAnimatedValue();
3274 dispatchOnLauncherTransitionStep(fromView, t);
3275 dispatchOnLauncherTransitionStep(toView, t);
Michael Jurka059798a2012-09-04 09:20:16 -07003276 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003277 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003278
Adam Cohen6c5891a2014-07-09 23:53:15 -07003279 // toView should appear right at the end of the workspace shrink
3280 // animation
3281 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3282 mStateAnimation.play(scaleAnim).after(startDelay);
3283 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003284
Adam Cohen6c5891a2014-07-09 23:53:15 -07003285 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3286 @Override
3287 public void onAnimationStart(Animator animation) {
3288 // Prepare the position
3289 toView.setTranslationX(0.0f);
3290 toView.setTranslationY(0.0f);
3291 toView.setVisibility(View.VISIBLE);
3292 toView.bringToFront();
Winson Chungadf0c182012-08-23 14:59:07 -07003293 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003294 @Override
3295 public void onAnimationEnd(Animator animation) {
3296 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3297 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003298
Adam Cohen6c5891a2014-07-09 23:53:15 -07003299 // Hide the search bar
3300 if (mSearchDropTargetBar != null) {
3301 mSearchDropTargetBar.hideSearchBar(false);
3302 }
3303 }
3304 });
3305 } else {
3306 int width = toView.getMeasuredWidth();
3307 int height = toView.getMeasuredHeight();
3308 float revealRadius = (float) Math.sqrt((width * width) / 4 + height * height);
3309
3310 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3311
3312 AppsCustomizePagedView content = (AppsCustomizePagedView)
3313 toView.findViewById(R.id.apps_customize_pane_content);
3314
3315 View page = content.getPageAt(content.getCurrentPage());
3316 View revealView = content;
3317
3318 float yDrift = height / 2f - 400;
3319
3320 LauncherViewPropertyAnimator panelAlphaAndDrift =
3321 new LauncherViewPropertyAnimator(revealView);
3322 revealView.setTranslationY(yDrift);
3323 revealView.setAlpha(0.3f);
3324 panelAlphaAndDrift.alpha(1)
3325 .translationY(0)
3326 .setDuration(revealDuration)
3327 .setInterpolator(new LogDecelerateInterpolator(100, 0));
3328
3329 mStateAnimation.play(panelAlphaAndDrift);
3330
3331 if (page instanceof CellLayout) {
3332 CellLayout cellLayout = (CellLayout) page;
3333 cellLayout.enableHardwareLayer(true);
3334
3335 View iconsView = cellLayout.getShortcutsAndWidgets();
3336 iconsView.setAlpha(0f);
3337
3338 LauncherViewPropertyAnimator iconsAlpha =
3339 new LauncherViewPropertyAnimator(iconsView);
3340 iconsAlpha.alpha(1f)
3341 .setDuration(revealDuration - 100)
3342 .setInterpolator(new LogDecelerateInterpolator(100, 0));
3343 mStateAnimation.play(iconsAlpha);
3344 }
3345
3346 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3347 pageIndicators.setAlpha(0f);
3348 final LauncherViewPropertyAnimator indicatorsAlpha =
3349 new LauncherViewPropertyAnimator(pageIndicators);
3350 indicatorsAlpha.alpha(1f);
3351 indicatorsAlpha.setDuration(revealDuration);
3352 mStateAnimation.play(indicatorsAlpha);
3353
3354 width = revealView.getMeasuredWidth();
3355
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003356 Animator reveal =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003357 ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3358 height / 2 + 100, 0f, revealRadius);
3359 reveal.setDuration(revealDuration);
3360 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3361
3362 toView.setTranslationX(0);
3363 toView.setTranslationY(0);
3364 toView.setAlpha(1f);
3365 // toView should appear right at the end of the workspace shrink
3366 // animation
3367 mStateAnimation.play(reveal);
3368
3369 reveal.addListener(new AnimatorListenerAdapter() {
3370 @Override
3371 public void onAnimationStart(Animator animation) {
3372 // Prepare the position
3373 toView.bringToFront();
3374 toView.setVisibility(View.VISIBLE);
3375 }
3376 });
3377
3378 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3379 @Override
3380 public void onAnimationEnd(Animator animation) {
3381 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3382 dispatchOnLauncherTransitionEnd(toView, animated, false);
3383
3384 // Hide the search bar
3385 if (mSearchDropTargetBar != null) {
3386 mSearchDropTargetBar.hideSearchBar(false);
3387 }
3388 }
3389 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003390 }
Michael Jurka1899a362011-11-03 13:50:45 -07003391
3392 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003393 if (workspaceAnim != null) {
3394 mStateAnimation.play(workspaceAnim);
3395 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003396 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3397 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003398
3399 // If any of the objects being animated haven't been measured/laid out
3400 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003401 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003402 (mWorkspace.getMeasuredWidth() == 0) ||
3403 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003404 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003405 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003406
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003407 final AnimatorSet stateAnimation = mStateAnimation;
3408 final Runnable startAnimRunnable = new Runnable() {
3409 public void run() {
3410 // Check that mStateAnimation hasn't changed while
3411 // we waited for a layout/draw pass
3412 if (mStateAnimation != stateAnimation)
3413 return;
3414 setPivotsForZoom(toView, scale);
3415 dispatchOnLauncherTransitionStart(fromView, animated, false);
3416 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003417 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003418 }
3419 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003420 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003421 final ViewTreeObserver observer = toView.getViewTreeObserver();
3422 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3423 public void onGlobalLayout() {
3424 startAnimRunnable.run();
3425 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3426 }
3427 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003428 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003429 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003430 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003431 } else {
3432 toView.setTranslationX(0.0f);
3433 toView.setTranslationY(0.0f);
3434 toView.setScaleX(1.0f);
3435 toView.setScaleY(1.0f);
3436 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003437 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003438
Daniel Sandlere4f98912013-06-25 15:13:26 -04003439 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003440 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003441 if (mSearchDropTargetBar != null) {
3442 mSearchDropTargetBar.hideSearchBar(false);
3443 }
Michael Jurkaabded662011-03-04 12:06:57 -08003444 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003445 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003446 dispatchOnLauncherTransitionStart(fromView, animated, false);
3447 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003448 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003449 dispatchOnLauncherTransitionStart(toView, animated, false);
3450 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003451 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003452 }
3453
3454 /**
3455 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003456 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003457 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003458 */
Adam Cohened307df2013-10-02 09:37:31 -07003459 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003460 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003461
Michael Jurkab3e22d92011-10-31 15:58:33 -07003462 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003463 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003464 mStateAnimation.cancel();
3465 mStateAnimation = null;
3466 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003467
3468 boolean material = Utilities.isLmp();
3469
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003470 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003471
Winson Chungf0ea4d32011-06-06 14:27:16 -07003472 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003473 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
3474 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
3475
Winson Chungf0ea4d32011-06-06 14:27:16 -07003476 final float scaleFactor = (float)
3477 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3478 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003479 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003480 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003481 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003482 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3483 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003484 toState, animated, stagger, -1);
3485 } else if (toState == Workspace.State.SPRING_LOADED ||
3486 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003487 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003488 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003489 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003490
Michael Jurkab3e22d92011-10-31 15:58:33 -07003491 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003492 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003493 if (animated) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003494 if (!material) {
3495 final LauncherViewPropertyAnimator scaleAnim =
3496 new LauncherViewPropertyAnimator(fromView);
3497 scaleAnim.
3498 scaleX(scaleFactor).scaleY(scaleFactor).
3499 setDuration(duration).
3500 setInterpolator(new Workspace.ZoomInInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08003501
Adam Cohen6c5891a2014-07-09 23:53:15 -07003502 final ObjectAnimator alphaAnim = LauncherAnimUtils
3503 .ofFloat(fromView, "alpha", 1f, 0f)
3504 .setDuration(fadeOutDuration);
3505 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
3506 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3507 @Override
3508 public void onAnimationUpdate(ValueAnimator animation) {
3509 float t = 1f - (Float) animation.getAnimatedValue();
3510 dispatchOnLauncherTransitionStep(fromView, t);
3511 dispatchOnLauncherTransitionStep(toView, t);
3512 }
3513 });
3514
3515 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3516
3517 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3518 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3519 mAppsCustomizeContent.stopScrolling();
3520
3521 mStateAnimation.playTogether(scaleAnim, alphaAnim);
3522 } else {
3523 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3524
3525 int width = fromView.getMeasuredWidth();
3526 int height = fromView.getMeasuredHeight();
3527 float revealRadius = (float) Math.sqrt((width * width) / 4 + height * height);
3528
3529 AppsCustomizePagedView content = (AppsCustomizePagedView)
3530 fromView.findViewById(R.id.apps_customize_pane_content);
3531
3532 final View page = content.getPageAt(content.getNextPage());
3533 View revealView = page;
3534
3535 float yDrift = height / 2f - 400;
3536
3537 LauncherViewPropertyAnimator panelAlphaAndDrift =
3538 new LauncherViewPropertyAnimator(revealView);
3539 revealView.setTranslationY(0);
3540 revealView.setAlpha(1);
3541 panelAlphaAndDrift.alpha(0)
3542 .translationY(yDrift)
3543 .setDuration(revealDuration)
3544 .setInterpolator(new LogDecelerateInterpolator(100, 0));
3545
3546 mStateAnimation.play(panelAlphaAndDrift);
3547
3548 if (page instanceof CellLayout) {
3549 final CellLayout cellLayout = (CellLayout) page;
3550 cellLayout.enableHardwareLayer(true);
3551
3552 final View iconsView = cellLayout.getShortcutsAndWidgets();
3553
3554 LauncherViewPropertyAnimator iconsAlpha =
3555 new LauncherViewPropertyAnimator(iconsView);
3556 iconsAlpha.alpha(0f)
3557 .setDuration(revealDuration - 100)
3558 .setInterpolator(new LogDecelerateInterpolator(100, 0));
3559
3560 mStateAnimation.play(iconsAlpha);
3561
3562 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3563 @Override
3564 public void onAnimationEnd(Animator animation) {
3565 cellLayout.setTranslationY(0);
3566 cellLayout.setAlpha(1f);
3567 iconsView.setAlpha(1f);
3568 }
3569 });
Winson Chung70442722012-02-10 15:43:22 -08003570 }
Michael Jurka159b4cc2012-01-17 03:00:35 -08003571
Adam Cohen6c5891a2014-07-09 23:53:15 -07003572 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3573 final LauncherViewPropertyAnimator indicatorsAlpha =
3574 new LauncherViewPropertyAnimator(pageIndicators);
3575 indicatorsAlpha.alpha(0f);
3576 indicatorsAlpha.setDuration(revealDuration);
3577 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3578 mStateAnimation.play(indicatorsAlpha);
Michael Jurkabed61d22012-02-14 22:51:29 -08003579
Adam Cohen6c5891a2014-07-09 23:53:15 -07003580 width = revealView.getMeasuredWidth();
3581
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003582 Animator reveal =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003583 ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3584 height / 2 + 100, revealRadius, 0f);
3585 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3586 reveal.setDuration(revealDuration);
3587
3588 reveal.addListener(new AnimatorListenerAdapter() {
3589 @Override
3590 public void onAnimationEnd(Animator animation) {
3591 fromView.setVisibility(View.GONE);
3592 }
3593 });
3594
3595 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3596 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3597 mAppsCustomizeContent.stopScrolling();
3598
3599 mStateAnimation.play(reveal);
3600 }
3601 if (workspaceAnim != null) {
3602 mStateAnimation.play(workspaceAnim);
3603 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003604
3605 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003606 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003607 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003608 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003609 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3610 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003611 if (onCompleteRunnable != null) {
3612 onCompleteRunnable.run();
3613 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003614 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003615 }
3616 });
3617
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003618 dispatchOnLauncherTransitionStart(fromView, animated, true);
3619 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003620 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003621 } else {
3622 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003623 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003624 dispatchOnLauncherTransitionStart(fromView, animated, true);
3625 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003626 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003627 dispatchOnLauncherTransitionStart(toView, animated, true);
3628 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003629 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003630 }
3631
Michael Jurkae326f182011-11-21 14:05:46 -08003632 @Override
3633 public void onTrimMemory(int level) {
3634 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003635 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003636 mAppsCustomizeTabHost.onTrimMemory();
3637 }
3638 }
3639
Adam Cohened307df2013-10-02 09:37:31 -07003640 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003641 showWorkspace(animated, null);
3642 }
3643
Adam Cohened307df2013-10-02 09:37:31 -07003644 protected void showWorkspace() {
3645 showWorkspace(true);
3646 }
3647
Adam Cohened66b2b2012-01-23 17:28:51 -08003648 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003649 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003650 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003651 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003652 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003653
Winson Chungc7d2b602012-05-16 17:02:20 -07003654 // Show the search bar (only animate if we were showing the drop target bar in spring
3655 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003656 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003657 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003658 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003659
Michael Jurkab3e22d92011-10-31 15:58:33 -07003660 // Set focus to the AppsCustomize button
3661 if (mAllAppsButton != null) {
3662 mAllAppsButton.requestFocus();
3663 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003664 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003665
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003666 // Change the state *after* we've called all the transition code
3667 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003668
Winson Chung5fb63472011-02-02 17:03:37 -08003669 // Resume the auto-advance of widgets
3670 mUserPresent = true;
3671 updateRunning();
3672
alanv1d4fde62012-10-17 13:15:47 -07003673 // Send an accessibility event to announce the context change
3674 getWindow().getDecorView()
3675 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003676
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003677 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003678 }
3679
Adam Cohened307df2013-10-02 09:37:31 -07003680 void showOverviewMode(boolean animated) {
3681 mWorkspace.setVisibility(View.VISIBLE);
3682 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3683 mState = State.WORKSPACE;
3684 onWorkspaceShown(animated);
3685 }
3686
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003687 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003688 }
3689
Winson Chung82963d52013-10-09 11:20:57 -07003690 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3691 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003692 if (mState != State.WORKSPACE) return;
3693
Winson Chung82963d52013-10-09 11:20:57 -07003694 if (resetPageToZero) {
3695 mAppsCustomizeTabHost.reset();
3696 }
Winson Chungc58497e2013-09-03 17:48:37 -07003697 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003698 mAppsCustomizeTabHost.post(new Runnable() {
3699 @Override
3700 public void run() {
3701 // We post this in-case the all apps view isn't yet constructed.
3702 mAppsCustomizeTabHost.requestFocus();
3703 }
3704 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003705
Michael Jurkab3e22d92011-10-31 15:58:33 -07003706 // Change the state *after* we've called all the transition code
3707 mState = State.APPS_CUSTOMIZE;
3708
3709 // Pause the auto-advance of widgets until we are out of AllApps
3710 mUserPresent = false;
3711 updateRunning();
3712 closeFolder();
3713
3714 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003715 getWindow().getDecorView()
3716 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003717 }
3718
Adam Cohen7777d962011-08-18 18:58:38 -07003719 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003720 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003721 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003722 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003723 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003724 }
Adam Cohen7777d962011-08-18 18:58:38 -07003725
Adam Cohenad4e15c2013-10-17 16:21:35 -07003726 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003727 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003728 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3729
Winson Chunge7a03942011-08-05 15:05:12 -07003730 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003731 @Override
3732 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003733 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003734 // Before we show workspace, hide all apps again because
3735 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3736 // clean up our state transition functions
3737 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003738 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003739 } else {
3740 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003741 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003742 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003743 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003744 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003745
Michael Jurkad3ef3062010-11-23 16:23:58 -08003746 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003747 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003748 final boolean animated = true;
3749 final boolean springLoaded = true;
3750 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003751 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003752 }
3753 // Otherwise, we are not in spring loaded mode, so don't do anything.
3754 }
3755
Michael Jurkab3e22d92011-10-31 15:58:33 -07003756 void lockAllApps() {
3757 // TODO
3758 }
3759
3760 void unlockAllApps() {
3761 // TODO
3762 }
3763
Winson Chungf0ea4d32011-06-06 14:27:16 -07003764 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003765 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003766 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003767 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003768 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003769 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003770 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003771 int duration = 0;
3772 if (mSearchDropTargetBar != null) {
3773 duration = mSearchDropTargetBar.getTransitionInDuration();
3774 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003775 mHotseat.animate().alpha(1f).setDuration(duration);
3776 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003777 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003778 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003779 }
3780 }
3781 }
3782
3783 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003784 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003785 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003786 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003787 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003788 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003789 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003790 int duration = 0;
3791 if (mSearchDropTargetBar != null) {
3792 duration = mSearchDropTargetBar.getTransitionOutDuration();
3793 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003794 mHotseat.animate().alpha(0f).setDuration(duration);
3795 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003796 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003797 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003798 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003799 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003800 }
3801
Patrick Dubroy5f445422011-02-18 14:35:21 -08003802 /**
3803 * Add an item from all apps or customize onto the given workspace screen.
3804 * If layout is null, add to the current screen.
3805 */
3806 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003807 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003808 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003809 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003810 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003811
Winson Chungdff8ebb2011-09-08 17:25:31 -07003812 /** Maps the current orientation to an index for referencing orientation correct global icons */
3813 private int getCurrentOrientationIndexForGlobalIcons() {
3814 // default - 0, landscape - 1
3815 switch (getResources().getConfiguration().orientation) {
3816 case Configuration.ORIENTATION_LANDSCAPE:
3817 return 1;
3818 default:
3819 return 0;
3820 }
3821 }
3822
Michael Jurkaae65ee32012-04-30 11:45:54 -07003823 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003824 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003825 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003826 // Look for the toolbar icon specified in the activity meta-data
3827 Bundle metaData = packageManager.getActivityInfo(
3828 activityName, PackageManager.GET_META_DATA).metaData;
3829 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003830 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003831 if (iconResId != 0) {
3832 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003833 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003834 }
3835 }
3836 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003837 // This can happen if the activity defines an invalid drawable
3838 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3839 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003840 } catch (Resources.NotFoundException nfe) {
3841 // This can happen if the activity defines an invalid drawable
3842 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3843 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003844 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003845 return null;
3846 }
3847
3848 // if successful in getting icon, return it; otherwise, set button to use default drawable
3849 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003850 int buttonId, ComponentName activityName, int fallbackDrawableId,
3851 String toolbarResourceName) {
3852 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003853 Resources r = getResources();
3854 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3855 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003856
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003857 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003858 // If we were unable to find the icon via the meta-data, use a generic one
3859 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003860 toolbarIcon = r.getDrawable(fallbackDrawableId);
3861 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003862 if (button != null) {
3863 button.setCompoundDrawables(toolbarIcon, null, null, null);
3864 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003865 return null;
3866 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003867 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003868 if (button != null) {
3869 button.setCompoundDrawables(toolbarIcon, null, null, null);
3870 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003871 return toolbarIcon.getConstantState();
3872 }
3873 }
3874
3875 // if successful in getting icon, return it; otherwise, set button to use default drawable
3876 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003877 int buttonId, ComponentName activityName, int fallbackDrawableId,
3878 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003879 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003880 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003881
Michael Jurka19e0fc52011-07-22 18:00:21 -07003882 if (button != null) {
3883 // If we were unable to find the icon via the meta-data, use a
3884 // generic one
3885 if (toolbarIcon == null) {
3886 button.setImageResource(fallbackDrawableId);
3887 } else {
3888 button.setImageDrawable(toolbarIcon);
3889 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003890 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003891
3892 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3893
Michael Jurka0423dcf2010-10-05 14:56:18 -07003894 }
3895
Winson Chung1b884092012-06-08 17:13:02 -07003896 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003897 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003898 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003899 }
3900
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003901 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003902 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003903 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003904 }
3905
Winson Chungbb185bd2011-11-21 12:31:42 -08003906 private void invalidatePressedFocusedStates(View container, View button) {
3907 if (container instanceof HolographicLinearLayout) {
3908 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3909 layout.invalidatePressedFocusedStates();
3910 } else if (button instanceof HolographicImageView) {
3911 HolographicImageView view = (HolographicImageView) button;
3912 view.invalidatePressedFocusedStates();
3913 }
3914 }
3915
Cristina Stancu476493b2013-08-07 17:20:14 +01003916 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003917 if (mQsb == null) {
3918 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3919 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003920 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003921 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003922 }
3923
3924 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003925 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003926 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003927 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003928 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003929
Winson Chung1cad91e2011-05-25 17:41:01 -07003930 final SearchManager searchManager =
3931 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3932 ComponentName activityName = searchManager.getGlobalSearchActivity();
3933 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003934 int coi = getCurrentOrientationIndexForGlobalIcons();
3935 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003936 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3937 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3938 if (sGlobalSearchIcon[coi] == null) {
3939 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3940 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3941 TOOLBAR_ICON_METADATA_NAME);
3942 }
3943
Winson Chungc51db6a2011-10-05 11:44:49 -07003944 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3945 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003946 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003947 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003948 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003949 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003950 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3951 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003952 if (searchButton != null) searchButton.setVisibility(View.GONE);
3953 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003954 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003955 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003956 }
3957 }
3958
Cristina Stancu476493b2013-08-07 17:20:14 +01003959 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003960 final View searchButtonContainer = findViewById(R.id.search_button_container);
3961 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003962 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003963 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003964 }
3965
Cristina Stancu476493b2013-08-07 17:20:14 +01003966 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003967 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003968 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003969
Winson Chungc51db6a2011-10-05 11:44:49 -07003970 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003971 final SearchManager searchManager =
3972 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3973 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3974
3975 ComponentName activityName = null;
3976 if (globalSearchActivity != null) {
3977 // Check if the global search activity handles voice search
3978 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3979 intent.setPackage(globalSearchActivity.getPackageName());
3980 activityName = intent.resolveActivity(getPackageManager());
3981 }
3982
3983 if (activityName == null) {
3984 // Fallback: check if an activity other than the global search activity
3985 // resolves this
3986 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3987 activityName = intent.resolveActivity(getPackageManager());
3988 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003989 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003990 int coi = getCurrentOrientationIndexForGlobalIcons();
3991 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003992 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3993 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3994 if (sVoiceSearchIcon[coi] == null) {
3995 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3996 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3997 TOOLBAR_ICON_METADATA_NAME);
3998 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003999 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07004000 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07004001 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08004002 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07004003 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07004004 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07004005 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04004006 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004007 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07004008 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004009 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004010 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07004011
Cristina Stancu476493b2013-08-07 17:20:14 +01004012 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08004013 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4014 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08004015 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08004016 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08004017 }
4018
Winson Chung5841efa2013-09-30 18:06:44 -07004019 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004020 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
4021 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07004022 boolean visible = !forceDisableVoiceButtonProxy &&
4023 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004024 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004025 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004026 }
4027 }
Winson Chung5841efa2013-09-30 18:06:44 -07004028
4029 /**
4030 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
4031 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4032 */
4033 public void disableVoiceButtonProxy(boolean disabled) {
4034 updateVoiceButtonProxyVisible(disabled);
4035 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004036 /**
Winson Chungeb66b142011-06-16 13:14:22 -07004037 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004038 */
4039 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07004040 if (!DISABLE_MARKET_BUTTON) {
4041 final View marketButton = findViewById(R.id.market_button);
4042 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
4043 // Find the app market activity by resolving an intent.
4044 // (If multiple app markets are installed, it will return the ResolverActivity.)
4045 ComponentName activityName = intent.resolveActivity(getPackageManager());
4046 if (activityName != null) {
4047 int coi = getCurrentOrientationIndexForGlobalIcons();
4048 mAppMarketIntent = intent;
4049 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
4050 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
4051 TOOLBAR_ICON_METADATA_NAME);
4052 marketButton.setVisibility(View.VISIBLE);
4053 } else {
4054 // We should hide and disable the view so that we don't try and restore the visibility
4055 // of it when we swap between drag & normal states from IconDropTarget subclasses.
4056 marketButton.setVisibility(View.GONE);
4057 marketButton.setEnabled(false);
4058 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07004059 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004060 }
4061
Michael Jurkae7bf83b2010-12-14 18:02:21 -08004062 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07004063 if (!DISABLE_MARKET_BUTTON) {
4064 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
4065 Resources r = getResources();
4066 Drawable marketIconDrawable = d.newDrawable(r);
4067 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
4068 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
4069 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07004070
Winson Chungd64a6662013-09-30 11:06:59 -07004071 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
4072 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08004073 }
4074
Michael Jurkad7c28052012-04-27 15:43:36 -07004075 @Override
4076 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004077 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004078 final List<CharSequence> text = event.getText();
4079 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004080 // Populate event with a fake title based on the current state.
4081 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004082 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004083 } else {
4084 text.add(getString(R.string.all_apps_home_button_label));
4085 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004086 return result;
4087 }
4088
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004089 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004090 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004091 */
4092 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4093 @Override
4094 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004095 closeSystemDialogs();
4096 }
4097 }
4098
4099 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004100 * Receives notifications whenever the appwidgets are reset.
4101 */
4102 private class AppWidgetResetObserver extends ContentObserver {
4103 public AppWidgetResetObserver() {
4104 super(new Handler());
4105 }
4106
4107 @Override
4108 public void onChange(boolean selfChange) {
4109 onAppWidgetReset();
4110 }
4111 }
4112
4113 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004114 * If the activity is currently paused, signal that we need to run the passed Runnable
4115 * in onResume.
4116 *
4117 * This needs to be called from incoming places where resources might have been loaded
4118 * while we are paused. That is becaues the Configuration might be wrong
4119 * when we're not running, and if it comes back to what it was when we
4120 * were paused, we are not restarted.
4121 *
4122 * Implementation of the method from LauncherModel.Callbacks.
4123 *
4124 * @return true if we are currently paused. The caller might be able to
4125 * skip some work in that case since we will come back again.
4126 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004127 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004128 if (mPaused) {
4129 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004130 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004131 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004132 }
4133 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004134 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004135 return true;
4136 } else {
4137 return false;
4138 }
4139 }
4140
Michael Jurkac402cd92013-05-20 15:49:32 +02004141 private boolean waitUntilResume(Runnable run) {
4142 return waitUntilResume(run, false);
4143 }
4144
Michael Jurka1e2f4652013-07-08 18:03:46 -07004145 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004146 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004147 }
4148
Michael Jurka7607c2f2013-04-03 14:33:19 -07004149 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004150 * If the activity is currently paused, signal that we need to re-run the loader
4151 * in onResume.
4152 *
4153 * This needs to be called from incoming places where resources might have been loaded
4154 * while we are paused. That is becaues the Configuration might be wrong
4155 * when we're not running, and if it comes back to what it was when we
4156 * were paused, we are not restarted.
4157 *
4158 * Implementation of the method from LauncherModel.Callbacks.
4159 *
4160 * @return true if we are currently paused. The caller might be able to
4161 * skip some work in that case since we will come back again.
4162 */
4163 public boolean setLoadOnResume() {
4164 if (mPaused) {
4165 Log.i(TAG, "setLoadOnResume");
4166 mOnResumeNeedsLoad = true;
4167 return true;
4168 } else {
4169 return false;
4170 }
4171 }
4172
4173 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004174 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004175 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004176 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004177 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004178 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004179 } else {
4180 return SCREEN_COUNT / 2;
4181 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004182 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004183
Joe Onorato9c1289c2009-08-17 11:03:03 -04004184 /**
4185 * Refreshes the shortcuts shown on the workspace.
4186 *
4187 * Implementation of the method from LauncherModel.Callbacks.
4188 */
4189 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004190 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004191
Michael Jurka7607c2f2013-04-03 14:33:19 -07004192 // If we're starting binding all over again, clear any bind calls we'd postponed in
4193 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4194 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004195 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004196
Winson Chungd64d1762013-08-20 14:37:16 -07004197 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004198 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004199 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004200
Michael Jurka05bf6442011-11-30 20:28:53 -08004201 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004202 if (mHotseat != null) {
4203 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004204 }
4205 }
4206
Adam Cohendcd297f2013-06-18 13:13:40 -07004207 @Override
4208 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004209 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004210
Adam Cohen5084cba2013-09-03 12:01:16 -07004211 // If there are no screens, we need to have an empty screen
4212 if (orderedScreenIds.size() == 0) {
4213 mWorkspace.addExtraEmptyScreen();
4214 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004215
4216 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004217 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004218 if (hasCustomContentToLeft()) {
4219 mWorkspace.createCustomContentContainer();
4220 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004221 }
Winson Chung64359a52013-07-08 17:17:08 -07004222 }
4223
4224 @Override
4225 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004226 // Log to disk
4227 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4228 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4229 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004230 int count = orderedScreenIds.size();
4231 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004232 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004233 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004234 }
4235
Adam Cohen39a06042013-07-19 14:30:12 -07004236 private boolean shouldShowWeightWatcher() {
4237 String spKey = LauncherAppState.getSharedPreferencesKey();
4238 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004239 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004240
4241 return show;
4242 }
4243
4244 private void toggleShowWeightWatcher() {
4245 String spKey = LauncherAppState.getSharedPreferencesKey();
4246 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4247 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4248
4249 show = !show;
4250
4251 SharedPreferences.Editor editor = sp.edit();
4252 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4253 editor.commit();
4254
4255 if (mWeightWatcher != null) {
4256 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4257 }
4258 }
4259
Winson Chungd64d1762013-08-20 14:37:16 -07004260 public void bindAppsAdded(final ArrayList<Long> newScreens,
4261 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004262 final ArrayList<ItemInfo> addAnimated,
4263 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004264 Runnable r = new Runnable() {
4265 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004266 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004267 }
4268 };
4269 if (waitUntilResume(r)) {
4270 return;
4271 }
4272
Winson Chungd64d1762013-08-20 14:37:16 -07004273 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004274 if (newScreens != null) {
4275 bindAddScreens(newScreens);
4276 }
Winson Chungd64d1762013-08-20 14:37:16 -07004277
4278 // We add the items without animation on non-visible pages, and with
4279 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004280 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004281 bindItems(addNotAnimated, 0,
4282 addNotAnimated.size(), false);
4283 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004284 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004285 bindItems(addAnimated, 0,
4286 addAnimated.size(), true);
4287 }
Winson Chungc58497e2013-09-03 17:48:37 -07004288
Winson Chung87412982013-10-03 18:34:14 -07004289 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004290 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004291
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004292 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004293 addedApps != null && mAppsCustomizeContent != null) {
4294 mAppsCustomizeContent.addApps(addedApps);
4295 }
Winson Chungd64d1762013-08-20 14:37:16 -07004296 }
4297
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004298 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004299 * Bind the items start-end from the list.
4300 *
4301 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004302 */
Winson Chung64359a52013-07-08 17:17:08 -07004303 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4304 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004305 Runnable r = new Runnable() {
4306 public void run() {
4307 bindItems(shortcuts, start, end, forceAnimateIcons);
4308 }
4309 };
4310 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004311 return;
4312 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004313
Winson Chungf0c6ae02012-03-21 16:10:31 -07004314 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004315 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4316 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004317 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004318 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004319 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004320 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004321 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004322
4323 // Short circuit if we are loading dock items for a configuration which has no dock
4324 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4325 mHotseat == null) {
4326 continue;
4327 }
4328
Joe Onorato9c1289c2009-08-17 11:03:03 -04004329 switch (item.itemType) {
4330 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4331 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004332 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004333 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004334
Winson Chung64359a52013-07-08 17:17:08 -07004335 /*
4336 * TODO: FIX collision case
4337 */
Winson Chungce376632013-07-11 16:12:41 -07004338 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4339 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4340 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004341 View v = cl.getChildAt(item.cellX, item.cellY);
4342 Object tag = v.getTag();
4343 String desc = "Collision while binding workspace item: " + item
4344 + ". Collides with " + tag;
4345 if (LauncherAppState.isDogfoodBuild()) {
4346 throw (new RuntimeException(desc));
4347 } else {
4348 Log.d(TAG, desc);
4349 }
Winson Chungce376632013-07-11 16:12:41 -07004350 }
Winson Chung64359a52013-07-08 17:17:08 -07004351 }
4352
Adam Cohendcd297f2013-06-18 13:13:40 -07004353 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4354 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004355 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004356 // Animate all the applications up now
4357 shortcut.setAlpha(0f);
4358 shortcut.setScaleX(0f);
4359 shortcut.setScaleY(0f);
4360 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004361 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004362 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004363 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004364 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004365 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004366 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004367 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004368 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4369 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004370 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004371 default:
4372 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004373 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004374 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004375
Winson Chung997a9232013-07-24 15:33:46 -07004376 if (animateIcons) {
4377 // Animate to the correct page
4378 if (newShortcutsScreenId > -1) {
4379 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004380 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004381 final Runnable startBounceAnimRunnable = new Runnable() {
4382 public void run() {
4383 anim.playTogether(bounceAnims);
4384 anim.start();
4385 }
4386 };
Winson Chung997a9232013-07-24 15:33:46 -07004387 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004388 // We post the animation slightly delayed to prevent slowdowns
4389 // when we are loading right after we return to launcher.
4390 mWorkspace.postDelayed(new Runnable() {
4391 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004392 if (mWorkspace != null) {
4393 mWorkspace.snapToPage(newScreenIndex);
4394 mWorkspace.postDelayed(startBounceAnimRunnable,
4395 NEW_APPS_ANIMATION_DELAY);
4396 }
Winson Chung94d67682013-09-25 16:29:40 -07004397 }
4398 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004399 } else {
4400 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004401 }
4402 }
Winson Chung64359a52013-07-08 17:17:08 -07004403 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004404 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004405 }
4406
Joe Onorato9c1289c2009-08-17 11:03:03 -04004407 /**
4408 * Implementation of the method from LauncherModel.Callbacks.
4409 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004410 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004411 Runnable r = new Runnable() {
4412 public void run() {
4413 bindFolders(folders);
4414 }
4415 };
4416 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004417 return;
4418 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004419 sFolders.clear();
4420 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004421 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004422
4423 /**
4424 * Add the views for a widget to the workspace.
4425 *
4426 * Implementation of the method from LauncherModel.Callbacks.
4427 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004428 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004429 Runnable r = new Runnable() {
4430 public void run() {
4431 bindAppWidget(item);
4432 }
4433 };
4434 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004435 return;
4436 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004437
Daniel Sandler843e8602010-06-07 14:59:01 -04004438 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4439 if (DEBUG_WIDGETS) {
4440 Log.d(TAG, "bindAppWidget: " + item);
4441 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004442 final Workspace workspace = mWorkspace;
4443
Sunny Goyalff572272014-07-23 13:58:07 -07004444 AppWidgetProviderInfo appWidgetInfo;
4445 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4446 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4447
4448 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4449 if (appWidgetInfo == null) {
4450 if (DEBUG_WIDGETS) {
4451 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4452 + " belongs to component " + item.providerName
4453 + ", as the povider is null");
4454 }
4455 LauncherModel.deleteItemFromDatabase(this, item);
4456 return;
4457 }
4458 // Note: This assumes that the id remap broadcast is received before this step.
4459 // If that is not the case, the id remap will be ignored and user may see the
4460 // click to setup view.
4461 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4462 pendingInfo.spanX = item.spanX;
4463 pendingInfo.spanY = item.spanY;
4464 pendingInfo.minSpanX = item.minSpanX;
4465 pendingInfo.minSpanY = item.minSpanY;
4466 Bundle options =
4467 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4468
4469 boolean success = false;
4470 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4471 if (options != null) {
4472 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4473 appWidgetInfo.provider, options);
4474 } else {
4475 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4476 appWidgetInfo.provider);
4477 }
4478
4479 // TODO consider showing a permission dialog when the widget is clicked.
4480 if (!success) {
4481 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4482 if (DEBUG_WIDGETS) {
4483 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4484 + " belongs to component " + item.providerName
4485 + ", as the launcher is unable to bing a new widget id");
4486 }
4487 LauncherModel.deleteItemFromDatabase(this, item);
4488 return;
4489 }
4490
4491 item.appWidgetId = newWidgetId;
4492
4493 // If the widget has a configure activity, it is still needs to set it up, otherwise
4494 // the widget is ready to go.
4495 item.restoreStatus = (appWidgetInfo.configure == null)
4496 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4497 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4498
4499 LauncherModel.updateItemInDatabase(this, item);
4500 }
4501
Sunny Goyal651077b2014-06-30 14:15:31 -07004502 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4503 final int appWidgetId = item.appWidgetId;
4504 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4505 if (DEBUG_WIDGETS) {
4506 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4507 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004508
Sunny Goyal651077b2014-06-30 14:15:31 -07004509 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4510 } else {
4511 appWidgetInfo = null;
Sunny Goyalff572272014-07-23 13:58:07 -07004512 item.hostView = new PendingAppWidgetHostView(this, item.restoreStatus);
Sunny Goyal651077b2014-06-30 14:15:31 -07004513 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004514 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004515 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004516
Joe Onorato9c1289c2009-08-17 11:03:03 -04004517 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004518 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004519
Adam Cohendcd297f2013-06-18 13:13:40 -07004520 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004521 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004522 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4523
Joe Onorato9c1289c2009-08-17 11:03:03 -04004524 workspace.requestLayout();
4525
Daniel Sandler843e8602010-06-07 14:59:01 -04004526 if (DEBUG_WIDGETS) {
4527 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4528 + (SystemClock.uptimeMillis()-start) + "ms");
4529 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004530 }
4531
Sunny Goyalff572272014-07-23 13:58:07 -07004532 /**
4533 * Restores a pending widget.
4534 *
4535 * @param appWidgetId The app widget id
4536 * @param cellInfo The position on screen where to create the widget.
4537 */
4538 private void completeRestoreAppWidget(final int appWidgetId) {
4539 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4540 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4541 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4542 return;
4543 }
4544
4545 PendingAppWidgetHostView pendingView = (PendingAppWidgetHostView) view;
4546 pendingView.setStatus(LauncherAppWidgetInfo.RESTORE_COMPLETED);
4547
4548 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) pendingView.getTag();
4549 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4550
4551 mWorkspace.reinflateWidgetsIfNecessary();
4552 LauncherModel.updateItemInDatabase(this, info);
4553 }
4554
Adam Cohen1462de32012-07-24 22:34:36 -07004555 public void onPageBoundSynchronously(int page) {
4556 mSynchronouslyBoundPages.add(page);
4557 }
4558
Joe Onorato9c1289c2009-08-17 11:03:03 -04004559 /**
4560 * Callback saying that there aren't any more items to bind.
4561 *
4562 * Implementation of the method from LauncherModel.Callbacks.
4563 */
Adam Cohene25af792013-06-06 23:08:25 -07004564 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004565 Runnable r = new Runnable() {
4566 public void run() {
4567 finishBindingItems(upgradePath);
4568 }
4569 };
4570 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004571 return;
4572 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004573 if (mSavedState != null) {
4574 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004575 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004576 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004577 mSavedState = null;
4578 }
4579
Adam Cohen1462de32012-07-24 22:34:36 -07004580 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004581
Winson Chungc51db6a2011-10-05 11:44:49 -07004582 // Update the market app icon as necessary (the other icons will be managed in response to
4583 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004584 if (!DISABLE_MARKET_BUTTON) {
4585 updateAppMarketIcon();
4586 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004587
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004588 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004589 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004590
4591 // If we received the result of any pending adds while the loader was running (e.g. the
4592 // widget configuration forced an orientation change), process them now.
4593 if (sPendingAddItem != null) {
4594 final long screenId = completeAdd(sPendingAddItem);
4595
4596 // TODO: this moves the user to the page where the pending item was added. Ideally,
4597 // the screen would be guaranteed to exist after bind, and the page would be set through
4598 // the workspace restore process.
4599 mWorkspace.post(new Runnable() {
4600 @Override
4601 public void run() {
4602 mWorkspace.snapToScreenId(screenId);
4603 }
4604 });
4605 sPendingAddItem = null;
4606 }
4607
Adam Cohene25af792013-06-06 23:08:25 -07004608 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004609 mWorkspace.getUniqueComponents(true, null);
4610 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004611 }
Sunny Goyale755d462014-07-22 13:48:29 -07004612 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004613 }
4614
Adam Cohen3ed316a2014-07-23 18:21:20 -07004615 private void sendLoadingCompleteBroadcastIfNecessary() {
4616 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4617 String permission =
4618 getResources().getString(R.string.receive_first_load_broadcast_permission);
4619 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4620 sendBroadcast(intent, permission);
4621 SharedPreferences.Editor editor = mSharedPrefs.edit();
4622 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4623 editor.apply();
4624 }
4625 }
4626
Winson Chunga0b7e862013-09-05 16:03:15 -07004627 public boolean isAllAppsButtonRank(int rank) {
4628 if (mHotseat != null) {
4629 return mHotseat.isAllAppsButtonRank(rank);
4630 }
4631 return false;
4632 }
4633
Winson Chunga2413752012-04-03 14:22:34 -07004634 private boolean canRunNewAppsAnimation() {
4635 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4636 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4637 }
4638
Winson Chungc9168342013-06-26 14:54:55 -07004639 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4640 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4641 PropertyValuesHolder.ofFloat("alpha", 1f),
4642 PropertyValuesHolder.ofFloat("scaleX", 1f),
4643 PropertyValuesHolder.ofFloat("scaleY", 1f));
4644 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4645 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4646 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4647 return bounceAnim;
4648 }
4649
Adam Cohen27772732013-11-11 14:00:56 +00004650 public boolean useVerticalBarLayout() {
4651 return LauncherAppState.getInstance().getDynamicGrid().
4652 getDeviceProfile().isVerticalBarLayout();
4653 }
4654
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004655 protected Rect getSearchBarBounds() {
4656 return LauncherAppState.getInstance().getDynamicGrid().
4657 getDeviceProfile().getSearchBarBounds();
4658 }
4659
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004660 @Override
4661 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004662 boolean searchVisible = updateGlobalSearchIcon();
4663 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004664 if (mSearchDropTargetBar != null) {
4665 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4666 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004667 }
4668
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004669 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004670 * Add the icons for all apps.
4671 *
4672 * Implementation of the method from LauncherModel.Callbacks.
4673 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004674 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004675 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004676 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4677 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4678 getHotseat().addAllAppsFolder(mIconCache, apps,
4679 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4680 }
4681 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004682 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004683 if (mAppsCustomizeContent != null) {
4684 mAppsCustomizeContent.onPackagesUpdated(
4685 LauncherModel.getSortedWidgetsAndShortcuts(this));
4686 }
Winson Chungc58497e2013-09-03 17:48:37 -07004687 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004688 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004689 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004690 mAppsCustomizeContent.onPackagesUpdated(
4691 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004692 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004693 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004694 }
4695
4696 /**
4697 * A package was updated.
4698 *
4699 * Implementation of the method from LauncherModel.Callbacks.
4700 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004701 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004702 Runnable r = new Runnable() {
4703 public void run() {
4704 bindAppsUpdated(apps);
4705 }
4706 };
4707 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004708 return;
4709 }
4710
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004711 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004712 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004713 }
Winson Chungc58497e2013-09-03 17:48:37 -07004714
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004715 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004716 mAppsCustomizeContent != null) {
4717 mAppsCustomizeContent.updateApps(apps);
4718 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004719 }
4720
4721 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004722 * Update the state of a package, typically related to install state.
4723 *
4724 * Implementation of the method from LauncherModel.Callbacks.
4725 */
Sunny Goyale755d462014-07-22 13:48:29 -07004726 @Override
4727 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004728 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004729 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004730 }
4731 }
4732
4733 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004734 * A package was uninstalled. We take both the super set of packageNames
4735 * in addition to specific applications to remove, the reason being that
4736 * this can be called when a package is updated as well. In that scenario,
4737 * we only remove specific components from the workspace, where as
4738 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004739 *
4740 * Implementation of the method from LauncherModel.Callbacks.
4741 */
Winson Chung83892cc2013-05-01 16:53:33 -07004742 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004743 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004744 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004745 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004746 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004747 }
Winson Chungd64d1762013-08-20 14:37:16 -07004748 };
4749 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004750 return;
4751 }
4752
Winson Chungdf95eb12013-10-16 14:57:07 -07004753 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004754 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004755 }
4756 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004757 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004758 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004759
Winson Chunga1820962011-10-03 16:31:06 -07004760 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004761 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004762
Winson Chungdf95eb12013-10-16 14:57:07 -07004763 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004764 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004765 mAppsCustomizeContent != null) {
4766 mAppsCustomizeContent.removeApps(appInfos);
4767 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004768 }
Joe Onoratobe386092009-11-17 17:32:16 -08004769
4770 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004771 * A number of packages were updated.
4772 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004773 private ArrayList<Object> mWidgetsAndShortcuts;
4774 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004775 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004776 bindPackagesUpdated(mWidgetsAndShortcuts);
4777 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004778 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004779 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004780 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4781 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4782 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004783 return;
4784 }
4785
Winson Chung64359a52013-07-08 17:17:08 -07004786 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004787 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004788 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004789 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004790 }
4791
Winson Chung400438b2011-01-16 17:53:48 -08004792 private int mapConfigurationOriActivityInfoOri(int configOri) {
4793 final Display d = getWindowManager().getDefaultDisplay();
4794 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4795 switch (d.getRotation()) {
4796 case Surface.ROTATION_0:
4797 case Surface.ROTATION_180:
4798 // We are currently in the same basic orientation as the natural orientation
4799 naturalOri = configOri;
4800 break;
4801 case Surface.ROTATION_90:
4802 case Surface.ROTATION_270:
4803 // We are currently in the other basic orientation to the natural orientation
4804 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4805 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4806 break;
4807 }
4808
4809 int[] oriMap = {
4810 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4811 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4812 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4813 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4814 };
4815 // Since the map starts at portrait, we need to offset if this device's natural orientation
4816 // is landscape.
4817 int indexOffset = 0;
4818 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4819 indexOffset = 1;
4820 }
4821 return oriMap[(d.getRotation() + indexOffset) % 4];
4822 }
Adam Cohen446e9402011-09-15 18:21:21 -07004823
Winson Chung4b919f82012-05-01 10:44:08 -07004824 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004825 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004826 getResources().getBoolean(R.bool.allow_rotation);
4827 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004828 }
Winson Chung4b919f82012-05-01 10:44:08 -07004829 public void lockScreenOrientation() {
4830 if (isRotationEnabled()) {
4831 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4832 .getConfiguration().orientation));
4833 }
4834 }
4835 public void unlockScreenOrientation(boolean immediate) {
4836 if (isRotationEnabled()) {
4837 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004838 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004839 } else {
4840 mHandler.postDelayed(new Runnable() {
4841 public void run() {
4842 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4843 }
4844 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004845 }
Winson Chung4b919f82012-05-01 10:44:08 -07004846 }
Winson Chung400438b2011-01-16 17:53:48 -08004847 }
4848
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004849 /**
4850 * Called when the SearchBar hint should be changed.
4851 *
4852 * @param hint the hint to be displayed in the search bar.
4853 */
4854 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004855 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004856 }
4857
Winson Chunge43a1e72014-01-15 10:33:02 -08004858 protected boolean isLauncherPreinstalled() {
4859 PackageManager pm = getPackageManager();
4860 try {
4861 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4862 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4863 return true;
4864 } else {
4865 return false;
4866 }
4867 } catch (NameNotFoundException e) {
4868 e.printStackTrace();
4869 return false;
4870 }
4871 }
4872
Adam Cohenea90f832014-05-21 15:03:34 -07004873 /**
4874 * This method indicates whether or not we should suggest default wallpaper dimensions
4875 * when our wallpaper cropper was not yet used to set a wallpaper.
4876 */
4877 protected boolean overrideWallpaperDimensions() {
4878 return true;
4879 }
4880
Adam Cohen5eed5d82014-05-19 13:12:13 -07004881 protected boolean shouldClingFocusHotseatApp() {
4882 return false;
4883 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004884 protected String getFirstRunClingSearchBarHint() {
4885 return "";
4886 }
4887 protected String getFirstRunCustomContentHint() {
4888 return "";
4889 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004890 protected int getFirstRunFocusedHotseatAppDrawableId() {
4891 return -1;
4892 }
4893 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4894 return null;
4895 }
4896 protected int getFirstRunFocusedHotseatAppRank() {
4897 return -1;
4898 }
4899 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4900 return "";
4901 }
4902 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4903 return "";
4904 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004905
Winson Chungaf40f202013-09-18 18:26:31 -07004906 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004907 mLauncherClings.dismissFirstRunCling(v);
4908 }
4909 public void dismissMigrationClingCopyApps(View v) {
4910 mLauncherClings.dismissMigrationClingCopyApps(v);
4911 }
4912 public void dismissMigrationClingUseDefault(View v) {
4913 mLauncherClings.dismissMigrationClingUseDefault(v);
4914 }
4915 public void dismissMigrationWorkspaceCling(View v) {
4916 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004917 }
Winson Chung82f55532011-08-09 14:14:23 -07004918 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004919 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004920 }
4921 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004922 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004923 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004924 public void markFolderClingDismissedIfNecessary() {
4925 mLauncherClings.markFolderClingDismissedIfNecessary();
4926 }
Adam Cohen432609a2014-03-13 17:03:22 -07004927
4928 /**
4929 * To be overridden by subclasses to indicate that there is an activity to launch
4930 * before showing the standard launcher experience.
4931 */
4932 protected boolean hasFirstRunActivity() {
4933 return false;
4934 }
4935
4936 /**
4937 * To be overridden by subclasses to launch any first run activity
4938 */
4939 protected Intent getFirstRunActivity() {
4940 return null;
4941 }
4942
Winson Chunga6945242014-01-08 14:04:34 -08004943 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004944 return !ActivityManager.isRunningInTestHarness() &&
4945 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004946 }
4947
Adam Cohen4a9423d2014-03-28 14:22:31 -07004948 protected boolean hasRunFirstRunActivity() {
4949 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4950 }
4951
Adam Cohen432609a2014-03-13 17:03:22 -07004952 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004953 if (shouldRunFirstRunActivity() &&
4954 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004955 Intent firstRunIntent = getFirstRunActivity();
4956 if (firstRunIntent != null) {
4957 startActivity(firstRunIntent);
4958 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004959 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004960 }
4961 }
Adam Cohen432609a2014-03-13 17:03:22 -07004962 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004963 }
4964
4965 private void markFirstRunActivityShown() {
4966 SharedPreferences.Editor editor = mSharedPrefs.edit();
4967 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4968 editor.apply();
4969 }
4970
Adam Cohen432609a2014-03-13 17:03:22 -07004971 /**
4972 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4973 * screen that must be displayed and dismissed.
4974 */
4975 protected boolean hasDismissableIntroScreen() {
4976 return false;
4977 }
4978
4979 /**
4980 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4981 */
4982 protected View getIntroScreen() {
4983 return null;
4984 }
4985
4986 /**
4987 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4988 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4989 */
4990 private boolean shouldShowIntroScreen() {
4991 return hasDismissableIntroScreen() &&
4992 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4993 }
4994
4995 protected void showIntroScreen() {
4996 View introScreen = getIntroScreen();
4997 changeWallpaperVisiblity(false);
4998 if (introScreen != null) {
4999 mDragLayer.showOverlayView(introScreen);
5000 }
5001 }
5002
5003 public void dismissIntroScreen() {
5004 markIntroScreenDismissed();
5005 if (showFirstRunActivity()) {
5006 // We delay hiding the intro view until the first run activity is showing. This
5007 // avoids a blip.
5008 mWorkspace.postDelayed(new Runnable() {
5009 @Override
5010 public void run() {
5011 mDragLayer.dismissOverlayView();
5012 }
5013 }, ACTIVITY_START_DELAY);
5014 } else {
5015 mDragLayer.dismissOverlayView();
5016 }
5017 changeWallpaperVisiblity(true);
5018 }
5019
5020 private void markIntroScreenDismissed() {
5021 SharedPreferences.Editor editor = mSharedPrefs.edit();
5022 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
5023 editor.apply();
5024 }
5025
Winson Chunga6945242014-01-08 14:04:34 -08005026 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005027 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5028 if (mHotseat != null) mHotseat.setAlpha(1f);
5029 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5030 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005031 }
5032
5033 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005034 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5035 if (mHotseat != null) mHotseat.setAlpha(0f);
5036 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5037 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005038 }
5039
Mathew Inwood72fbec12013-11-19 15:45:07 +00005040 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01005041 // Called from search suggestion, not supported in other profiles.
5042 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5043 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5044 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5045 myUser);
5046 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00005047 return null;
5048 }
Kenny Guyed131872014-04-30 03:02:21 +01005049 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005050 }
5051
5052 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5053 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01005054 // Called from search suggestion, not supported in other profiles.
5055 return createShortcutDragInfo(shortcutIntent, caption, icon,
5056 UserHandleCompat.myUserHandle());
5057 }
5058
5059 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5060 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01005061 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01005062 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01005063 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005064 }
5065
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005066 protected void moveWorkspaceToDefaultScreen() {
5067 mWorkspace.moveToDefaultScreen(false);
5068 }
5069
Mathew Inwood72fbec12013-11-19 15:45:07 +00005070 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5071 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005072 mWorkspace.onExternalDragStartedWithItem(dragView);
5073 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005074 }
5075
Anjali Koppalf5d29132014-02-28 13:33:27 -08005076 @Override
5077 public void onPageSwitch(View newPage, int newPageIndex) {
5078 }
5079
Winson Chung80baf5a2010-08-09 16:03:15 -07005080 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005081 * Prints out out state for debugging.
5082 */
5083 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005084 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005085 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005086 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5087 Log.d(TAG, "mRestoring=" + mRestoring);
5088 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5089 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005090 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005091 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005092
Winson Chung785d2eb2011-04-14 16:08:02 -07005093 if (mAppsCustomizeContent != null) {
5094 mAppsCustomizeContent.dumpState();
5095 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005096 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005097 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005098
5099 @Override
5100 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5101 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005102 synchronized (sDumpLogs) {
5103 writer.println(" ");
5104 writer.println("Debug logs: ");
5105 for (int i = 0; i < sDumpLogs.size(); i++) {
5106 writer.println(" " + sDumpLogs.get(i));
5107 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005108 }
5109 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005110
5111 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005112 if (DEBUG_DUMP_LOG) {
5113 synchronized (sDumpLogs) {
5114 Log.d(TAG, "");
5115 Log.d(TAG, "*********************");
5116 Log.d(TAG, "Launcher debug logs: ");
5117 for (int i = 0; i < sDumpLogs.size(); i++) {
5118 Log.d(TAG, " " + sDumpLogs.get(i));
5119 }
5120 Log.d(TAG, "*********************");
5121 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005122 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005123 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005124 }
5125
5126 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005127 addDumpLog(tag, log, null, debugLog);
5128 }
5129
5130 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005131 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005132 if (e != null) {
5133 Log.d(tag, log, e);
5134 } else {
5135 Log.d(tag, log);
5136 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005137 }
Winson Chungede41292013-09-19 16:27:36 -07005138 if (DEBUG_DUMP_LOG) {
5139 sDateStamp.setTime(System.currentTimeMillis());
5140 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005141 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5142 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005143 }
Winson Chungede41292013-09-19 16:27:36 -07005144 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005145 }
5146
Winson Chungede41292013-09-19 16:27:36 -07005147 public void dumpLogsToLocalData() {
5148 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005149 new AsyncTask<Void, Void, Void>() {
5150 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005151 boolean success = false;
5152 sDateStamp.setTime(sRunStart);
5153 String FILENAME = sDateStamp.getMonth() + "-"
5154 + sDateStamp.getDay() + "_"
5155 + sDateStamp.getHours() + "-"
5156 + sDateStamp.getMinutes() + "_"
5157 + sDateStamp.getSeconds() + ".txt";
5158
5159 FileOutputStream fos = null;
5160 File outFile = null;
5161 try {
5162 outFile = new File(getFilesDir(), FILENAME);
5163 outFile.createNewFile();
5164 fos = new FileOutputStream(outFile);
5165 } catch (Exception e) {
5166 e.printStackTrace();
5167 }
5168 if (fos != null) {
5169 PrintWriter writer = new PrintWriter(fos);
5170
5171 writer.println(" ");
5172 writer.println("Debug logs: ");
5173 synchronized (sDumpLogs) {
5174 for (int i = 0; i < sDumpLogs.size(); i++) {
5175 writer.println(" " + sDumpLogs.get(i));
5176 }
5177 }
5178 writer.close();
5179 }
5180 try {
5181 if (fos != null) {
5182 fos.close();
5183 success = true;
5184 }
5185 } catch (IOException e) {
5186 e.printStackTrace();
5187 }
Michael Jurka43467462013-11-14 12:03:58 +01005188 return null;
Winson Chungede41292013-09-19 16:27:36 -07005189 }
Michael Jurka43467462013-11-14 12:03:58 +01005190 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005191 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005192 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005193}
Michael Jurka2763be32011-02-24 11:19:57 -08005194
Michael Jurkaabded662011-03-04 12:06:57 -08005195interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005196 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005197 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005198 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005199 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005200 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005201}
Dan Sandlerd5024042014-01-09 15:01:33 -05005202
5203interface DebugIntents {
5204 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5205 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005206}