blob: 31482f77e3a285462bd9c39f36a0cd013e35cf49 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080046import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070054import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070055import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040059import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070060import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020062import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070064import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070065import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040066import android.os.SystemClock;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Sunny Goyale755d462014-07-22 13:48:29 -070085import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewGroup;
87import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080088import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Sunny Goyal651077b2014-06-30 14:15:31 -070089import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070090import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080091import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070092import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080093import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070095import android.widget.Advanceable;
96import android.widget.FrameLayout;
97import android.widget.ImageView;
98import android.widget.TextView;
99import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700100
Sunny Goyal651077b2014-06-30 14:15:31 -0700101import com.android.launcher3.DropTarget.DragObject;
102import com.android.launcher3.PagedView.PageSwitchListener;
Kenny Guyed131872014-04-30 03:02:21 +0100103import com.android.launcher3.compat.LauncherActivityInfoCompat;
104import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700105import com.android.launcher3.compat.PackageInstallerCompat;
106import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100107import com.android.launcher3.compat.UserHandleCompat;
108import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700109
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.io.DataInputStream;
111import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700113import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700115import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700117import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000118import java.lang.reflect.Field;
119import java.lang.reflect.InvocationTargetException;
120import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700121import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700122import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700123import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700124import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700126import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000127import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700128
Winson Chunga6945242014-01-08 14:04:34 -0800129
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130/**
131 * Default launcher application.
132 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100133public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700134 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700135 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800136 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700137 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138
Daniel Sandlerf061f822013-06-27 13:59:36 -0400139 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400140 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700141 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700143 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700144
Dan Sandlerd5024042014-01-09 15:01:33 -0500145 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
146
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700148 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700150 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700151 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
Michael Jurka8b805b12012-04-18 14:23:14 -0700153 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700154 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700155
Mathew Inwood876a8462013-06-14 14:12:41 +0100156 /**
157 * IntentStarter uses request codes starting with this. This must be greater than all activity
158 * request codes used internally.
159 */
160 protected static final int REQUEST_LAST = 100;
161
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
163
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800164 static final int SCREEN_COUNT = 5;
165 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Romain Guy98d01652009-06-30 16:21:04 -0700167 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800168 // To turn on these properties, type
169 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
170 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
171 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800172 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Winson Chung2672ff92012-05-04 16:22:30 -0700174 // The Intent extra that defines whether to ignore the launch animation
175 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400176 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700177
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178 // Type: int
179 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700180 // Type: int
181 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700183 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
184 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
186 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700187 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700189 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 // Type: boolean
191 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
192 // Type: long
193 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700194 // Type: int
195 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
196 // Type: int
197 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
198 // Type: parcelable
199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000200 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800201 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000202 // Type: int[]
203 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
Adam Cohen432609a2014-03-13 17:03:22 -0700205 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800206 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
207
Adam Cohen3ed316a2014-07-23 18:21:20 -0700208 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
209 static final String ACTION_FIRST_LOAD_COMPLETE =
210 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
211
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100212 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700213 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100214 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700215 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100216 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700217
Adam Cohen39a06042013-07-19 14:30:12 -0700218 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700219 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700220
Winson Chunga6945242014-01-08 14:04:34 -0800221 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
222
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700223 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700224 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700225 private State mState = State.WORKSPACE;
226 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700227
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700228 private boolean mIsSafeModeEnabled;
229
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700231 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
232 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700233 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800236 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000238 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
239 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
240
Winson Chunga2413752012-04-03 14:22:34 -0700241 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700242 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
243 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700244 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700245 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700246
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800247 private final BroadcastReceiver mCloseSystemDialogsReceiver
248 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800249 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
250
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 private LayoutInflater mInflater;
252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700254 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800255 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800256 private DragLayer mDragLayer;
257 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700258 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800259 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700261 private AppWidgetManager mAppWidgetManager;
262 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700263
Michael Jurkac9d95c52011-08-29 14:03:34 -0700264 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700265 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800266 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700267
Michael Jurka0280c3b2010-09-17 15:00:07 -0700268 private int[] mTmpAddItemCellCoordinates = new int[2];
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private FolderInfo mFolderInfo;
271
Winson Chung3d503fb2011-07-13 17:25:49 -0700272 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800273 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700274
Michael Jurka838a4ca2011-02-07 13:33:06 -0800275 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700276
Winson Chungc51db6a2011-10-05 11:44:49 -0700277 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700278 private AppsCustomizeTabHost mAppsCustomizeTabHost;
279 private AppsCustomizePagedView mAppsCustomizeContent;
280 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800281 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700284 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
285 // scroll issues (because the workspace may not have been measured yet) and extra work.
286 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
287 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288
289 private SpannableStringBuilder mDefaultKeySsb = null;
290
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291 private boolean mWorkspaceLoading = true;
292
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800293 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 private boolean mRestoring;
295 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700296 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297
Michael Jurka1e2f4652013-07-08 18:03:46 -0700298 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700299 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
300
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800301 private Bundle mSavedInstanceState;
302
Joe Onorato9c1289c2009-08-17 11:03:03 -0400303 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800304 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800305 private boolean mUserPresent = true;
306 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700307 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800308 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400309
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700310 private static LocaleConfiguration sLocaleConfiguration = null;
311
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700312 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700313
Adam Cohen61f560d2013-09-30 15:58:20 -0700314 private View.OnTouchListener mHapticFeedbackTouchListener;
315
Adam Cohended9f8d2010-11-03 13:25:16 -0700316 // Related to the auto-advancing of widgets
317 private final int ADVANCE_MSG = 1;
318 private final int mAdvanceInterval = 20000;
319 private final int mAdvanceStagger = 250;
320 private long mAutoAdvanceSentTime;
321 private long mAutoAdvanceTimeLeft = -1;
322 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
323 new HashMap<View, AppWidgetProviderInfo>();
324
Winson Chung400438b2011-01-16 17:53:48 -0800325 // Determines how long to wait after a rotation before restoring the screen orientation to
326 // match the sensor state.
327 private final int mRestoreScreenOrientationDelay = 500;
328
Michael Jurka4ef207b2010-11-29 17:05:45 -0800329 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700330 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
331 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
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
459 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700461
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100463 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800465 registerContentObservers();
466
Joe Onorato7c312c12009-08-13 21:36:53 -0700467 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700468
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800469 mSavedState = savedInstanceState;
470 restoreState(mSavedState);
471
472 if (PROFILE_STARTUP) {
473 android.os.Debug.stopMethodTracing();
474 }
475
476 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700477 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700478 // If the user leaves launcher, then we should just load items asynchronously when
479 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500480 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700481 } else {
482 // We only load the page synchronously if the user rotates (or triggers a
483 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800484 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700485 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800486 }
487
488 // For handling default keys
489 mDefaultKeySsb = new SpannableStringBuilder();
490 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800491
492 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
493 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800494
Adam Cohenf9426d52012-06-04 17:26:21 -0700495 updateGlobalIcons();
496
497 // On large interfaces, we want the screen to auto-rotate based on the current orientation
498 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700499
Adam Cohen432609a2014-03-13 17:03:22 -0700500 if (shouldShowIntroScreen()) {
501 showIntroScreen();
502 } else {
503 showFirstRunActivity();
504 }
505
Winson Chunge43a1e72014-01-15 10:33:02 -0800506 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
507 // on the device, then we always show the first run cling experience (or if there is no
508 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800509 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
510 if (mModel.canMigrateFromOldLauncherDb(this)) {
511 mLauncherClings.showMigrationCling();
512 } else {
513 mLauncherClings.showFirstRunCling();
514 }
Winson Chunga6945242014-01-08 14:04:34 -0800515 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800516 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800517 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700518 }
519
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700520 @Override
521 public void onLauncherProviderChange() { }
522
Winson Chung98ca0f72013-07-29 12:58:51 -0700523 /** To be overriden by subclasses to hint to Launcher that we have custom content */
524 protected boolean hasCustomContentToLeft() {
525 return false;
526 }
527
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500529 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600530 * {@link #addToCustomContentPage}. This will only be invoked if
531 * {@link #hasCustomContentToLeft()} is {@code true}.
532 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500533 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600534 }
535
536 /**
537 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
538 * ensure the custom content page is added or removed if necessary.
539 */
540 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600541 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600542 // Not bound yet, wait for bindScreens to be called.
543 return;
544 }
545
546 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
547 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500548 mWorkspace.createCustomContentContainer();
549 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600550 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
551 mWorkspace.removeCustomContentPage();
552 }
553 }
554
Adam Cohenf9426d52012-06-04 17:26:21 -0700555 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700556 boolean searchVisible = false;
557 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800558 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700559 int coi = getCurrentOrientationIndexForGlobalIcons();
560 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
561 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700562 if (!DISABLE_MARKET_BUTTON) {
563 updateAppMarketIcon();
564 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700565 searchVisible = updateGlobalSearchIcon();
566 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700567 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700568 if (sGlobalSearchIcon[coi] != null) {
569 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700570 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700571 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700572 if (sVoiceSearchIcon[coi] != null) {
573 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700574 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700575 }
Winson Chungd64a6662013-09-30 11:06:59 -0700576 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700577 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800578 }
Winson Chungadf0c182012-08-23 14:59:07 -0700579 if (mSearchDropTargetBar != null) {
580 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
581 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 }
Romain Guycbb89e42009-06-08 15:52:54 -0700583
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800584 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585 if (sLocaleConfiguration == null) {
586 new AsyncTask<Void, Void, LocaleConfiguration>() {
587 @Override
588 protected LocaleConfiguration doInBackground(Void... unused) {
589 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
590 readConfiguration(Launcher.this, localeConfiguration);
591 return localeConfiguration;
592 }
593
594 @Override
595 protected void onPostExecute(LocaleConfiguration result) {
596 sLocaleConfiguration = result;
597 checkForLocaleChange(); // recursive, but now with a locale configuration
598 }
599 }.execute();
600 return;
601 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700602
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final Configuration configuration = getResources().getConfiguration();
604
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700605 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606 final String locale = configuration.locale.toString();
607
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609 final int mcc = configuration.mcc;
610
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700611 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800612 final int mnc = configuration.mnc;
613
Romain Guy84f296c2009-11-04 15:00:44 -0800614 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800615
Romain Guy84f296c2009-11-04 15:00:44 -0800616 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 sLocaleConfiguration.locale = locale;
618 sLocaleConfiguration.mcc = mcc;
619 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700620
Joe Onorato0589f0f2010-02-08 13:44:00 -0800621 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700622
623 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100624 new AsyncTask<Void, Void, Void>() {
625 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700626 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100627 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700628 }
Michael Jurka43467462013-11-14 12:03:58 +0100629 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700630 }
631 }
632
633 private static class LocaleConfiguration {
634 public String locale;
635 public int mcc = -1;
636 public int mnc = -1;
637 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700638
Romain Guy98d01652009-06-30 16:21:04 -0700639 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
640 DataInputStream in = null;
641 try {
642 in = new DataInputStream(context.openFileInput(PREFERENCES));
643 configuration.locale = in.readUTF();
644 configuration.mcc = in.readInt();
645 configuration.mnc = in.readInt();
646 } catch (FileNotFoundException e) {
647 // Ignore
648 } catch (IOException e) {
649 // Ignore
650 } finally {
651 if (in != null) {
652 try {
653 in.close();
654 } catch (IOException e) {
655 // Ignore
656 }
657 }
658 }
659 }
660
661 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
662 DataOutputStream out = null;
663 try {
664 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
665 out.writeUTF(configuration.locale);
666 out.writeInt(configuration.mcc);
667 out.writeInt(configuration.mnc);
668 out.flush();
669 } catch (FileNotFoundException e) {
670 // Ignore
671 } catch (IOException e) {
672 //noinspection ResultOfMethodCallIgnored
673 context.getFileStreamPath(PREFERENCES).delete();
674 } finally {
675 if (out != null) {
676 try {
677 out.close();
678 } catch (IOException e) {
679 // Ignore
680 }
681 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 }
683 }
684
Anton Hanssona2f665f2013-09-26 12:18:32 +0100685 public Stats getStats() {
686 return mStats;
687 }
688
Bjorn Bringertc459e522013-06-07 19:36:01 +0100689 public LayoutInflater getInflater() {
690 return mInflater;
691 }
692
Winson Chung36a62fe2012-05-06 18:04:42 -0700693 boolean isDraggingEnabled() {
694 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
695 // that is subsequently removed from the workspace in startBinding().
696 return !mModel.isLoadingWorkspace();
697 }
698
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 static int getScreen() {
700 synchronized (sLock) {
701 return sScreen;
702 }
703 }
704
705 static void setScreen(int screen) {
706 synchronized (sLock) {
707 sScreen = screen;
708 }
709 }
710
Winson Chung557d6ed2011-07-08 15:34:52 -0700711 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000712 * Copied from View -- the View version of the method isn't called
713 * anywhere else in our process and only exists for API level 17+,
714 * so it's ok to keep our own version with no API requirement.
715 */
716 public static int generateViewId() {
717 for (;;) {
718 final int result = sNextGeneratedId.get();
719 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
720 int newValue = result + 1;
721 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
722 if (sNextGeneratedId.compareAndSet(result, newValue)) {
723 return result;
724 }
725 }
726 }
727
728 public int getViewIdForItem(ItemInfo info) {
729 // This cast is safe given the > 2B range for int.
730 int itemId = (int) info.id;
731 if (mItemIdToViewId.containsKey(itemId)) {
732 return mItemIdToViewId.get(itemId);
733 }
734 int viewId = generateViewId();
735 mItemIdToViewId.put(itemId, viewId);
736 return viewId;
737 }
738
739 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700740 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
741 * a configuration step, this allows the proper animations to run after other transitions.
742 */
Adam Cohendb364c32014-05-20 14:23:40 -0700743 private long completeAdd(PendingAddArguments args) {
744
745 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800746 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700748 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700749 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700750 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800751 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700752 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700753 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700754 case REQUEST_RECONFIGURE_APPWIDGET:
755 completeRestoreAppWidget(args.appWidgetId);
756 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800757 }
Michael Jurka27614d22012-04-02 06:40:22 -0700758 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
759 // if you turned the screen off and then back while in All Apps, Launcher would not
760 // return to the workspace. Clearing mAddInfo.container here fixes this issue
761 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700762 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800763 }
764
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 protected void onActivityResult(
767 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700768 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700769 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700770 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800771 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700772
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 Runnable exitSpringLoaded = new Runnable() {
774 @Override
775 public void run() {
776 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
777 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
778 }
779 };
780
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700783 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
784 if (resultCode == RESULT_CANCELED) {
785 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700786 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700787 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700788 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700789 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
790 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700791 }
792 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200793 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
794 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
795 mWorkspace.exitOverviewMode(false);
796 }
797 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700798 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200799
Adam Cohened66b2b2012-01-23 17:28:51 -0800800 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
801 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700802
Adam Cohendb364c32014-05-20 14:23:40 -0700803 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800804 // We have special handling for widgets
805 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800806 final int appWidgetId;
807 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
808 : -1;
809 if (widgetId < 0) {
810 appWidgetId = pendingAddWidgetId;
811 } else {
812 appWidgetId = widgetId;
813 }
814
Adam Cohenad4e15c2013-10-17 16:21:35 -0700815 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800816 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700817 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
818 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700819 result = RESULT_CANCELED;
820 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700821 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700822 @Override
823 public void run() {
824 exitSpringLoadedDragModeDelayed(false, 0, null);
825 }
826 };
Adam Cohendb364c32014-05-20 14:23:40 -0700827 if (workspaceLocked) {
828 // No need to remove the empty screen if we're mid-binding, as the
829 // the bind will not add the empty screen.
830 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
831 } else {
832 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
833 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
834 }
Winson Chung5aaab772012-04-27 15:24:02 -0700835 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700836 if (!workspaceLocked) {
837 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
838 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
839
840 dropLayout.setDropPending(true);
841 final Runnable onComplete = new Runnable() {
842 @Override
843 public void run() {
844 completeTwoStageWidgetDrop(resultCode, appWidgetId);
845 dropLayout.setDropPending(false);
846 }
847 };
848 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
849 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
850 } else {
851 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
852 mPendingAddInfo);
853 sPendingAddItem = args;
854 }
Winson Chung5aaab772012-04-27 15:24:02 -0700855 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800856 return;
857 }
858
Sunny Goyalff572272014-07-23 13:58:07 -0700859 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
860 if (resultCode == RESULT_OK) {
861 // Update the widget view.
862 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
863 pendingAddWidgetId, mPendingAddInfo);
864 if (workspaceLocked) {
865 sPendingAddItem = args;
866 } else {
867 completeAdd(args);
868 }
869 }
870 // Leave the widget in the pending state if the user canceled the configure.
871 return;
872 }
873
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 // The pattern used here is that a user PICKs a specific application,
875 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700876
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
878 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700879 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700880 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
881 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800882 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700883 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800884 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700885 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700886 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
887 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888 }
Adam Cohen00074722013-10-11 17:46:09 -0700889 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700890 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700891 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800892 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800893 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800894 }
895
Adam Cohendb364c32014-05-20 14:23:40 -0700896 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
897 appWidgetId, ItemInfo info) {
898 PendingAddArguments args = new PendingAddArguments();
899 args.requestCode = requestCode;
900 args.intent = data;
901 args.container = info.container;
902 args.screenId = info.screenId;
903 args.cellX = info.cellX;
904 args.cellY = info.cellY;
905 args.appWidgetId = appWidgetId;
906 return args;
907 }
908
909 /**
910 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
911 *
912 * @param screenId the screen id to check
913 * @return the new screen, or screenId if it exists
914 */
915 private long ensurePendingDropLayoutExists(long screenId) {
916 CellLayout dropLayout =
917 (CellLayout) mWorkspace.getScreenWithId(screenId);
918 if (dropLayout == null) {
919 // it's possible that the add screen was removed because it was
920 // empty and a re-bind occurred
921 mWorkspace.addExtraEmptyScreen();
922 return mWorkspace.commitExtraEmptyScreen();
923 } else {
924 return screenId;
925 }
926 }
927
Adam Cohened66b2b2012-01-23 17:28:51 -0800928 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700929 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700930 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 Runnable onCompleteRunnable = null;
932 int animationType = 0;
933
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700934 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800935 if (resultCode == RESULT_OK) {
936 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
937 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700938 mPendingAddWidgetInfo);
939 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800940 onCompleteRunnable = new Runnable() {
941 @Override
942 public void run() {
943 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700944 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700945 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
946 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800947 }
948 };
949 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800950 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800951 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800952 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700953 if (mDragLayer.getAnimatedView() != null) {
954 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
955 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
956 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700957 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700958 // The animated view may be null in the case of a rotation during widget configuration
959 onCompleteRunnable.run();
960 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800961 }
962
963 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700964 protected void onStop() {
965 super.onStop();
966 FirstFrameAnimatorHelper.setIsVisible(false);
967 }
968
969 @Override
970 protected void onStart() {
971 super.onStart();
972 FirstFrameAnimatorHelper.setIsVisible(true);
973 }
974
975 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200977 long startTime = 0;
978 if (DEBUG_RESUME_TIME) {
979 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400980 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200981 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700983
Winson Chung4a2afa32012-07-19 14:53:05 -0700984 // Restore the previous launcher state
985 if (mOnResumeState == State.WORKSPACE) {
986 showWorkspace(false);
987 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800988 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700989 }
990 mOnResumeState = State.NONE;
991
Craig Mautner360310b2012-10-26 15:13:08 -0700992 // Background was set to gradient in onPause(), restore to black if in all apps.
993 setWorkspaceBackground(mState == State.WORKSPACE);
994
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800995 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700996 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700997 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500998 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400999 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001000 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001002 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001003 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1004 // execute them here
1005 long startTimeCallbacks = 0;
1006 if (DEBUG_RESUME_TIME) {
1007 startTimeCallbacks = System.currentTimeMillis();
1008 }
1009
1010 if (mAppsCustomizeContent != null) {
1011 mAppsCustomizeContent.setBulkBind(true);
1012 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001013 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1014 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001015 }
1016 if (mAppsCustomizeContent != null) {
1017 mAppsCustomizeContent.setBulkBind(false);
1018 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001019 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001020 if (DEBUG_RESUME_TIME) {
1021 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1022 (System.currentTimeMillis() - startTimeCallbacks));
1023 }
Michael Jurka447bf842013-05-15 14:52:15 +02001024 }
Michael Jurka54554252013-08-01 12:52:23 +02001025 if (mOnResumeCallbacks.size() > 0) {
1026 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1027 mOnResumeCallbacks.get(i).run();
1028 }
1029 mOnResumeCallbacks.clear();
1030 }
Winson Chunge4e50662012-01-23 14:45:13 -08001031
1032 // Reset the pressed state of icons that were locked in the press state while activities
1033 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001034 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001035 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001036 mWaitingForResume.setStayPressed(false);
1037 }
Winson Chunge4e50662012-01-23 14:45:13 -08001038 if (mAppsCustomizeContent != null) {
1039 // Resets the previous all apps icon press state
1040 mAppsCustomizeContent.resetDrawableState();
1041 }
Winson Chung82963d52013-10-09 11:20:57 -07001042
Adam Cohen06dff352012-06-01 17:17:08 -07001043 // It is possible that widgets can receive updates while launcher is not in the foreground.
1044 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1045 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1046 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001047 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001048
Winson Chung780fe592013-09-26 14:48:44 -07001049 // Process any items that were added while Launcher was away.
1050 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1051
Winson Chung5841efa2013-09-30 18:06:44 -07001052 // Update the voice search button proxy
1053 updateVoiceButtonProxyVisible(false);
1054
Adam Cohenf9426d52012-06-04 17:26:21 -07001055 // Again, as with the above scenario, it's possible that one or more of the global icons
1056 // were updated in the wrong orientation.
1057 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001058 if (DEBUG_RESUME_TIME) {
1059 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1060 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001061
1062 if (mWorkspace.getCustomContentCallbacks() != null) {
1063 // If we are resuming and the custom content is the current page, we call onShow().
1064 // It is also poassible that onShow will instead be called slightly after first layout
1065 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1066 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001067 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001068 }
1069 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001070 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001071 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001072
1073 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001074 }
1075
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001077 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001078 // Ensure that items added to Launcher are queued until Launcher returns
1079 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001080 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001081
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001082 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001083 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001084 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001085 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001086
1087 // We call onHide() aggressively. The custom content callbacks should be able to
1088 // debounce excess onHide calls.
1089 if (mWorkspace.getCustomContentCallbacks() != null) {
1090 mWorkspace.getCustomContentCallbacks().onHide();
1091 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001092 }
Romain Guycbb89e42009-06-08 15:52:54 -07001093
Adam Cohenbffe7452013-07-22 18:21:45 -07001094 QSBScroller mQsbScroller = new QSBScroller() {
1095 int scrollY = 0;
1096
1097 @Override
1098 public void setScrollY(int scroll) {
1099 scrollY = scroll;
1100
1101 if (mWorkspace.isOnOrMovingToCustomContent()) {
1102 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001103 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001104 }
1105 }
1106 };
1107
1108 public void resetQSBScroll() {
1109 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001110 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001111 }
1112
1113 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001114 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1115 // by a onResume or by scrolling otherwise.
1116 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001117
1118 // Custom content is completely hidden
1119 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001120
1121 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1122 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001123
1124 // Indicates whether the user is allowed to scroll away from the custom content.
1125 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001126 }
1127
Jorim Jaggid017f882014-01-14 17:08:48 -08001128 protected boolean hasSettings() {
1129 return false;
1130 }
1131
Adam Cohenbffe7452013-07-22 18:21:45 -07001132 public interface QSBScroller {
1133 public void setScrollY(int scrollY);
1134 }
1135
Winson Chung98ca0f72013-07-29 12:58:51 -07001136 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001137 CustomContentCallbacks callbacks, String description) {
1138 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001139 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001140 }
1141
Adam Cohenedb40762013-07-18 16:45:45 -07001142 // The custom content needs to offset its content to account for the QSB
1143 public int getTopOffsetForCustomContent() {
1144 return mWorkspace.getPaddingTop();
1145 }
1146
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001147 @Override
1148 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001149 // Flag the loader to stop early before switching
1150 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001151 if (mAppsCustomizeContent != null) {
1152 mAppsCustomizeContent.surrender();
1153 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001154 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001155 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001156
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001157 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001158 @Override
1159 public void onWindowFocusChanged(boolean hasFocus) {
1160 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001161 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001162 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001163
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164 private boolean acceptFilter() {
1165 final InputMethodManager inputManager = (InputMethodManager)
1166 getSystemService(Context.INPUT_METHOD_SERVICE);
1167 return !inputManager.isFullscreenMode();
1168 }
1169
1170 @Override
1171 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001172 final int uniChar = event.getUnicodeChar();
1173 final boolean handled = super.onKeyDown(keyCode, event);
1174 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1175 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001176 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1177 keyCode, event);
1178 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001179 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001180 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001181 // showSearchDialog()
1182 // If there are multiple keystrokes before the search dialog takes focus,
1183 // onSearchRequested() will be called for every keystroke,
1184 // but it is idempotent, so it's fine.
1185 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001186 }
1187 }
1188
Joe Onorato8a9625e2010-01-28 15:55:35 -08001189 // Eat the long press event so the keyboard doesn't come up.
1190 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1191 return true;
1192 }
1193
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 return handled;
1195 }
1196
Karl Rosaen138a0412009-04-23 19:00:21 -07001197 private String getTypedText() {
1198 return mDefaultKeySsb.toString();
1199 }
1200
1201 private void clearTypedText() {
1202 mDefaultKeySsb.clear();
1203 mDefaultKeySsb.clearSpans();
1204 Selection.setSelection(mDefaultKeySsb, 0);
1205 }
1206
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001208 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1209 * State
1210 */
1211 private static State intToState(int stateOrdinal) {
1212 State state = State.WORKSPACE;
1213 final State[] stateValues = State.values();
1214 for (int i = 0; i < stateValues.length; i++) {
1215 if (stateValues[i].ordinal() == stateOrdinal) {
1216 state = stateValues[i];
1217 break;
1218 }
1219 }
1220 return state;
1221 }
1222
1223 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224 * Restores the previous state, if it exists.
1225 *
1226 * @param savedState The previous state.
1227 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001228 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 private void restoreState(Bundle savedState) {
1230 if (savedState == null) {
1231 return;
1232 }
1233
Michael Jurka883f55b2010-10-21 15:47:14 -07001234 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001235 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001236 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001237 }
1238
Adam Cohen21cd0022013-10-09 18:57:02 -07001239 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1240 PagedView.INVALID_RESTORE_PAGE);
1241 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001242 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243 }
1244
Winson Chung3d503fb2011-07-13 17:25:49 -07001245 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001246 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001247
Winson Chung3d503fb2011-07-13 17:25:49 -07001248 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1249 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001250 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001251 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1252 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001253 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1254 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1255 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001256 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001257 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 mRestoring = true;
1259 }
1260
1261 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1262 if (renameFolder) {
1263 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001264 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 mRestoring = true;
1266 }
Winson Chunga12a2502010-12-20 14:41:35 -08001267
Winson Chung785d2eb2011-04-14 16:08:02 -07001268 // Restore the AppsCustomize tab
1269 if (mAppsCustomizeTabHost != null) {
1270 String curTab = savedState.getString("apps_customize_currentTab");
1271 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001272 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001273 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001274 mAppsCustomizeContent.loadAssociatedPages(
1275 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001276 }
1277
Winson Chung5afbf7b2011-07-25 11:53:08 -07001278 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1279 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001280 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001281 mItemIdToViewId = (HashMap<Integer, Integer>)
1282 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283 }
1284
1285 /**
1286 * Finds all the views we need and configure them properly.
1287 */
1288 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001289 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001290
Craig Mautner360310b2012-10-26 15:13:08 -07001291 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001292 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1293 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001294 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001295 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001296
John Spurlock77e1f472013-09-11 10:09:51 -04001297 mLauncherView.setSystemUiVisibility(
1298 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001299 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300
Winson Chung4c98d922011-05-31 16:50:48 -07001301 // Setup the drag layer
1302 mDragLayer.setup(this, dragController);
1303
Winson Chung3d503fb2011-07-13 17:25:49 -07001304 // Setup the hotseat
1305 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1306 if (mHotseat != null) {
1307 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001308 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001309 }
1310
Jorim Jaggid017f882014-01-14 17:08:48 -08001311 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001312 View widgetButton = findViewById(R.id.widget_button);
1313 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001314 @Override
1315 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001316 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001317 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001318 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001319 }
1320 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001321 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1322
1323 View wallpaperButton = findViewById(R.id.wallpaper_button);
1324 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001325 @Override
1326 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001327 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001328 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001329 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001330 }
1331 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001332 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1333
1334 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001335 if (hasSettings()) {
1336 settingsButton.setOnClickListener(new OnClickListener() {
1337 @Override
1338 public void onClick(View arg0) {
1339 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001340 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001341 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001342 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001343 });
1344 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1345 } else {
1346 settingsButton.setVisibility(View.GONE);
1347 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1348 lp.gravity = Gravity.END | Gravity.TOP;
1349 widgetButton.requestLayout();
1350 }
1351
Adam Cohendbdff6b2013-09-18 19:09:15 -07001352 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001353
Winson Chung4c98d922011-05-31 16:50:48 -07001354 // Setup the workspace
1355 mWorkspace.setHapticFeedbackEnabled(false);
1356 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001357 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001358 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001359
Winson Chungf0ea4d32011-06-06 14:27:16 -07001360 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001361 mSearchDropTargetBar = (SearchDropTargetBar)
1362 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001363
Winson Chungf0ea4d32011-06-06 14:27:16 -07001364 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001365 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001366 mAppsCustomizeContent = (AppsCustomizePagedView)
1367 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1368 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001369
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001371 dragController.setDragScoller(mWorkspace);
1372 dragController.setScrollView(mDragLayer);
1373 dragController.setMoveTarget(mWorkspace);
1374 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001375 if (mSearchDropTargetBar != null) {
1376 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001377 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001378
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001379 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001380 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001381 mWeightWatcher = new WeightWatcher(this);
1382 mWeightWatcher.setAlpha(0.5f);
1383 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001384 new FrameLayout.LayoutParams(
1385 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001386 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001387 Gravity.BOTTOM)
1388 );
Adam Cohen39a06042013-07-19 14:30:12 -07001389
1390 boolean show = shouldShowWeightWatcher();
1391 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001392 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 }
1394
1395 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001396 * Sets the all apps button. This method is called from {@link Hotseat}.
1397 */
1398 public void setAllAppsButton(View allAppsButton) {
1399 mAllAppsButton = allAppsButton;
1400 }
1401
1402 public View getAllAppsButton() {
1403 return mAllAppsButton;
1404 }
1405
1406 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 * Creates a view representing a shortcut.
1408 *
1409 * @param info The data structure describing the shortcut.
1410 *
1411 * @return A View inflated from R.layout.application.
1412 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001413 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001415 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
1417
1418 /**
1419 * Creates a view representing a shortcut inflated from the specified resource.
1420 *
1421 * @param layoutResId The id of the XML layout used to create the shortcut.
1422 * @param parent The group the shortcut belongs to.
1423 * @param info The data structure describing the shortcut.
1424 *
1425 * @return A View inflated from layoutResId.
1426 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001427 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001428 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001429 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 return favorite;
1432 }
1433
1434 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 * Add a shortcut to the workspace.
1436 *
1437 * @param data The intent describing the shortcut.
1438 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001440 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001441 int cellY) {
1442 int[] cellXY = mTmpAddItemCellCoordinates;
1443 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001444 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001445
Michael Jurkad3ef3062010-11-23 16:23:58 -08001446 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001447
Adam Cohen558baaf2011-08-15 15:22:57 -07001448 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001449 if (info == null) {
1450 return;
1451 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001452 final View view = createShortcut(info);
1453
Adam Cohenfbba09b2011-07-18 21:43:05 -07001454 // First we check if we already know the exact location where we want to add this item.
1455 if (cellX >= 0 && cellY >= 0) {
1456 cellXY[0] = cellX;
1457 cellXY[1] = cellY;
1458 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001459
1460 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001461 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001462 true, null,null)) {
1463 return;
1464 }
1465 DragObject dragObject = new DragObject();
1466 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001467 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1468 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001469 return;
1470 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001471 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001472 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001473 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001474 foundCellSpan = (result != null);
1475 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001476 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001477 }
1478
1479 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001480 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001481 return;
1482 }
1483
Adam Cohendcd297f2013-06-18 13:13:40 -07001484 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001485
1486 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001487 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001488 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 }
1490 }
1491
Adam Cohen2f093b62012-04-30 18:59:53 -07001492 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1493 int minHeight) {
1494 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001495 // We want to account for the extra amount of padding that we are adding to the widget
1496 // to ensure that it gets the full amount of space that it has requested
1497 int requiredWidth = minWidth + padding.left + padding.right;
1498 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001499 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001500 }
1501
Adam Cohen2f093b62012-04-30 18:59:53 -07001502 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1503 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001504 }
1505
Adam Cohen2f093b62012-04-30 18:59:53 -07001506 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1507 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001508 }
1509
Adam Cohen2f093b62012-04-30 18:59:53 -07001510 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1511 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001512 }
1513
Adam Cohen2f093b62012-04-30 18:59:53 -07001514 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1515 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001516 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001517 }
1518
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001520 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001522 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001523 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001525 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001526 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1527 if (appWidgetInfo == null) {
1528 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1529 }
Romain Guycbb89e42009-06-08 15:52:54 -07001530
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001531 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001532 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001533
Adam Cohen2f093b62012-04-30 18:59:53 -07001534 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1535 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001536
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001538 // We have saved the position to which the widget was dragged-- this really only matters
1539 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001540 int[] cellXY = mTmpAddItemCellCoordinates;
1541 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001542 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001543 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001544 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1545 cellXY[0] = mPendingAddInfo.cellX;
1546 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001547 spanXY[0] = mPendingAddInfo.spanX;
1548 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001549 foundCellSpan = true;
1550 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001551 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001552 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001553 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1554 spanXY[1], cellXY, finalSpan);
1555 spanXY[0] = finalSpan[0];
1556 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001557 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001558 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001559 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001560 }
1561
Michael Jurka0280c3b2010-09-17 15:00:07 -07001562 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001563 if (appWidgetId != -1) {
1564 // Deleting an app widget ID is a void call but writes to disk before returning
1565 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001566 new AsyncTask<Void, Void, Void>() {
1567 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001568 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001569 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001570 }
Michael Jurka43467462013-11-14 12:03:58 +01001571 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001572 }
Winson Chung93eef082012-03-23 15:59:27 -07001573 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001574 return;
1575 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001577 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001578 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1579 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 launcherInfo.spanX = spanXY[0];
1581 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001582 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1583 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001584
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001586 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587
1588 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001589 if (hostView == null) {
1590 // Perform actual inflation because we're live
1591 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1592 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1593 } else {
1594 // The AppWidgetHostView has already been inflated and instantiated
1595 launcherInfo.hostView = hostView;
1596 }
Romain Guycbb89e42009-06-08 15:52:54 -07001597
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001599 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001600 launcherInfo.notifyWidgetSizeChanged(this);
1601
Adam Cohendcd297f2013-06-18 13:13:40 -07001602 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001603 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001604
1605 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001607 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 }
Romain Guycbb89e42009-06-08 15:52:54 -07001609
Adam Cohended9f8d2010-11-03 13:25:16 -07001610 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1611 @Override
1612 public void onReceive(Context context, Intent intent) {
1613 final String action = intent.getAction();
1614 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1615 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001616 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001617 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001618
Winson Chungc100e8e2011-08-09 16:02:43 -07001619 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001620 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001621 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001622 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001623 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001624 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1625 mUserPresent = true;
1626 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001627 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1628 mModel.resetLoadedState(false, true);
1629 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1630 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1631 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1632 mModel.resetLoadedState(false, true);
1633 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1634 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1635 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001636 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1637 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1638 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001639 }
1640 }
1641 };
1642
1643 @Override
1644 public void onAttachedToWindow() {
1645 super.onAttachedToWindow();
1646
1647 // Listen for broadcasts related to user-presence
1648 final IntentFilter filter = new IntentFilter();
1649 filter.addAction(Intent.ACTION_SCREEN_OFF);
1650 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001651 // For handling managed profiles
1652 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1653 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001654 if (ENABLE_DEBUG_INTENTS) {
1655 filter.addAction(DebugIntents.DELETE_DATABASE);
1656 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1657 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001658 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001659 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001660 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001661 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001662 mVisible = true;
1663 }
1664
Adam Cohen0b395352014-06-09 22:54:36 +00001665 /**
1666 * Sets up transparent navigation and status bars in LMP.
1667 * This method is a no-op for other platform versions.
1668 */
1669 @TargetApi(19)
1670 private void setupTransparentSystemBarsForLmp() {
1671 // TODO(sansid): use the APIs directly when compiling against L sdk.
1672 // Currently we use reflection to access the flags and the API to set the transparency
1673 // on the System bars.
1674 if (Utilities.isLmp()) {
1675 try {
1676 getWindow().getAttributes().systemUiVisibility |=
1677 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1678 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1679 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1680 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1681 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1682 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1683 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1684 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1685
1686 Method setStatusBarColorMethod =
1687 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1688 Method setNavigationBarColorMethod =
1689 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1690 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1691 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1692 } catch (NoSuchFieldException e) {
1693 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1694 } catch (NoSuchMethodException ex) {
1695 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1696 } catch (IllegalAccessException e) {
1697 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1698 } catch (IllegalArgumentException e) {
1699 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1700 } catch (InvocationTargetException e) {
1701 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1702 } finally {}
1703 }
1704 }
1705
Adam Cohended9f8d2010-11-03 13:25:16 -07001706 @Override
1707 public void onDetachedFromWindow() {
1708 super.onDetachedFromWindow();
1709 mVisible = false;
1710
Adam Cohend113e0c2010-11-11 10:48:05 -08001711 if (mAttached) {
1712 unregisterReceiver(mReceiver);
1713 mAttached = false;
1714 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001715 updateRunning();
1716 }
1717
1718 public void onWindowVisibilityChanged(int visibility) {
1719 mVisible = visibility == View.VISIBLE;
1720 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001721 // The following code used to be in onResume, but it turns out onResume is called when
1722 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1723 // is a more appropriate event to handle
1724 if (mVisible) {
1725 mAppsCustomizeTabHost.onWindowVisible();
1726 if (!mWorkspaceLoading) {
1727 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001728 // We want to let Launcher draw itself at least once before we force it to build
1729 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001730 // apps is nice and speedy.
1731 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001732 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001733 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001734 if (mStarted) return;
1735 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001736 // We delay the layer building a bit in order to give
1737 // other message processing a time to run. In particular
1738 // this avoids a delay in hiding the IME if it was
1739 // currently shown, because doing that may involve
1740 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001741 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001742 final ViewTreeObserver.OnDrawListener listener = this;
1743 mWorkspace.post(new Runnable() {
1744 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001745 if (mWorkspace != null &&
1746 mWorkspace.getViewTreeObserver() != null) {
1747 mWorkspace.getViewTreeObserver().
1748 removeOnDrawListener(listener);
1749 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001750 }
1751 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001752 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001753 }
1754 });
1755 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001756 // When Launcher comes back to foreground, a different Activity might be responsible for
1757 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001758 if (!DISABLE_MARKET_BUTTON) {
1759 updateAppMarketIcon();
1760 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001761 clearTypedText();
1762 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001763 }
1764
1765 private void sendAdvanceMessage(long delay) {
1766 mHandler.removeMessages(ADVANCE_MSG);
1767 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1768 mHandler.sendMessageDelayed(msg, delay);
1769 mAutoAdvanceSentTime = System.currentTimeMillis();
1770 }
1771
1772 private void updateRunning() {
1773 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1774 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1775 mAutoAdvanceRunning = autoAdvanceRunning;
1776 if (autoAdvanceRunning) {
1777 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1778 sendAdvanceMessage(delay);
1779 } else {
1780 if (!mWidgetsToAdvance.isEmpty()) {
1781 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1782 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1783 }
1784 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001785 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001786 }
1787 }
1788 }
1789
1790 private final Handler mHandler = new Handler() {
1791 @Override
1792 public void handleMessage(Message msg) {
1793 if (msg.what == ADVANCE_MSG) {
1794 int i = 0;
1795 for (View key: mWidgetsToAdvance.keySet()) {
1796 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1797 final int delay = mAdvanceStagger * i;
1798 if (v instanceof Advanceable) {
1799 postDelayed(new Runnable() {
1800 public void run() {
1801 ((Advanceable) v).advance();
1802 }
1803 }, delay);
1804 }
1805 i++;
1806 }
1807 sendAdvanceMessage(mAdvanceInterval);
1808 }
1809 }
1810 };
1811
1812 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001813 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001814 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1815 if (v instanceof Advanceable) {
1816 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001817 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001818 updateRunning();
1819 }
1820 }
1821
1822 void removeWidgetToAutoAdvance(View hostView) {
1823 if (mWidgetsToAdvance.containsKey(hostView)) {
1824 mWidgetsToAdvance.remove(hostView);
1825 updateRunning();
1826 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001827 }
1828
Joe Onorato9c1289c2009-08-17 11:03:03 -04001829 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001830 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001831 launcherInfo.hostView = null;
1832 }
1833
Winson Chung93eef082012-03-23 15:59:27 -07001834 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1835 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1836 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001837 }
1838
Winson Chunga6945242014-01-08 14:04:34 -08001839 public DragLayer getDragLayer() {
1840 return mDragLayer;
1841 }
1842
1843 public Workspace getWorkspace() {
1844 return mWorkspace;
1845 }
1846
1847 public Hotseat getHotseat() {
1848 return mHotseat;
1849 }
1850
Jorim Jaggid017f882014-01-14 17:08:48 -08001851 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001852 return mOverviewPanel;
1853 }
1854
1855 public SearchDropTargetBar getSearchBar() {
1856 return mSearchDropTargetBar;
1857 }
1858
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001859 public LauncherAppWidgetHost getAppWidgetHost() {
1860 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 }
Romain Guycbb89e42009-06-08 15:52:54 -07001862
Winson Chunga9abd0e2010-10-27 17:18:37 -07001863 public LauncherModel getModel() {
1864 return mModel;
1865 }
1866
Winson Chunga6945242014-01-08 14:04:34 -08001867 public LauncherClings getLauncherClings() {
1868 return mLauncherClings;
1869 }
1870
1871 protected SharedPreferences getSharedPrefs() {
1872 return mSharedPrefs;
1873 }
1874
Bjorn Bringertc459e522013-06-07 19:36:01 +01001875 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001876 getWindow().closeAllPanels();
1877
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001878 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001879 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001880 }
1881
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 @Override
1883 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001884 long startTime = 0;
1885 if (DEBUG_RESUME_TIME) {
1886 startTime = System.currentTimeMillis();
1887 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 super.onNewIntent(intent);
1889
1890 // Close the menu
1891 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001892 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001893 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001894
Adam Cohened307df2013-10-02 09:37:31 -07001895 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1896 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1897 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001898
Adam Cohen6fecd412013-10-02 17:41:50 -07001899 if (mWorkspace == null) {
1900 // Can be cases where mWorkspace is null, this prevents a NPE
1901 return;
1902 }
1903 Folder openFolder = mWorkspace.getOpenFolder();
1904 // In all these cases, only animate if we're already on home
1905 mWorkspace.exitWidgetResizeMode();
1906 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001907 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001908 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001909 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001910
Adam Cohen6fecd412013-10-02 17:41:50 -07001911 closeFolder();
1912 exitSpringLoadedDragMode();
1913
1914 // If we are already on home, then just animate back to the workspace,
1915 // otherwise, just wait until onResume to set the state back to Workspace
1916 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001917 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001918 } else {
1919 mOnResumeState = State.WORKSPACE;
1920 }
1921
1922 final View v = getWindow().peekDecorView();
1923 if (v != null && v.getWindowToken() != null) {
1924 InputMethodManager imm = (InputMethodManager)getSystemService(
1925 INPUT_METHOD_SERVICE);
1926 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1927 }
1928
1929 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001930 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001931 mAppsCustomizeTabHost.reset();
1932 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001933
1934 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 }
Adam Cohened307df2013-10-02 09:37:31 -07001936
Michael Jurka447bf842013-05-15 14:52:15 +02001937 if (DEBUG_RESUME_TIME) {
1938 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1939 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 }
1941
Adam Coppa120b8e2013-11-12 16:26:04 +00001942 /**
1943 * Override point for subclasses to prevent movement to the default screen when the home
1944 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1945 */
1946 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1947 return true;
1948 }
1949
1950 /**
1951 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1952 */
1953 protected void onHomeIntent() {
1954 // Do nothing
1955 }
1956
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001958 public void onRestoreInstanceState(Bundle state) {
1959 super.onRestoreInstanceState(state);
1960 for (int page: mSynchronouslyBoundPages) {
1961 mWorkspace.restoreInstanceStateForChild(page);
1962 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001963 }
1964
1965 @Override
1966 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001967 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001968 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1969 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001970 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001971 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972
Michael Jurka883f55b2010-10-21 15:47:14 -07001973 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001974 // We close any open folder since it will not be re-opened, and we need to make sure
1975 // this state is reflected.
1976 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977
Adam Cohendcd297f2013-06-18 13:13:40 -07001978 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001979 mWaitingForResult) {
1980 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001981 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001982 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1983 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001984 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1985 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1986 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001987 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001988 }
1989
1990 if (mFolderInfo != null && mWaitingForResult) {
1991 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1992 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1993 }
Michael Jurka946ad472010-07-09 18:05:18 -07001994
Winson Chung785d2eb2011-04-14 16:08:02 -07001995 // Save the current AppsCustomize tab
1996 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001997 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1998 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001999 if (currentTabTag != null) {
2000 outState.putString("apps_customize_currentTab", currentTabTag);
2001 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002002 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2003 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002004 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002005 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 }
2007
2008 @Override
2009 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002011
Winson Chunge7a03942011-08-05 15:05:12 -07002012 // Remove all pending runnables
2013 mHandler.removeMessages(ADVANCE_MSG);
2014 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002015 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002016
Winson Chungcd2b0142011-06-08 16:02:26 -07002017 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002018 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002019 mModel.stopLoader();
2020 app.setLauncher(null);
2021
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002023 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002025 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002027 mAppWidgetHost = null;
2028
2029 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030
2031 TextKeyListener.getInstance().release();
2032
Winson Chung81b52252012-08-27 15:34:29 -07002033 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2034 // to prevent leaking Launcher activities on orientation change.
2035 if (mModel != null) {
2036 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2037 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002038
2039 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002040 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002041
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002042 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002043 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002044 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002045 mWorkspace = null;
2046 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002047
Sunny Goyale755d462014-07-22 13:48:29 -07002048 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002049 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 }
2051
Adam Cohena9cf38f2011-05-02 15:36:58 -07002052 public DragController getDragController() {
2053 return mDragController;
2054 }
2055
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 @Override
2057 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002058 if (requestCode >= 0) {
2059 setWaitingForResult(true);
2060 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 super.startActivityForResult(intent, requestCode);
2062 }
2063
Winson Chung70d72102011-08-12 11:24:35 -07002064 /**
2065 * Indicates that we want global search for this activity by setting the globalSearch
2066 * argument for {@link #startSearch} to true.
2067 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002069 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002071
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002072 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002073
Karl Rosaen138a0412009-04-23 19:00:21 -07002074 if (initialQuery == null) {
2075 // Use any text typed in the launcher as the initial query
2076 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002077 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002078 if (appSearchData == null) {
2079 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002080 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002081 }
Winson Chungadf0c182012-08-23 14:59:07 -07002082 Rect sourceBounds = new Rect();
2083 if (mSearchDropTargetBar != null) {
2084 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2085 }
Romain Guycbb89e42009-06-08 15:52:54 -07002086
Bjorn Bringertc459e522013-06-07 19:36:01 +01002087 startSearch(initialQuery, selectInitialQuery,
2088 appSearchData, sourceBounds);
2089 }
2090
2091 public void startSearch(String initialQuery,
2092 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002093 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002094 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002095 }
2096
2097 /**
2098 * Starts the global search activity. This code is a copied from SearchManager
2099 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002100 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002101 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002102 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002103 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2104 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2105 if (globalSearchActivity == null) {
2106 Log.w(TAG, "No global search activity found.");
2107 return;
2108 }
2109 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2110 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2111 intent.setComponent(globalSearchActivity);
2112 // Make sure that we have a Bundle to put source in
2113 if (appSearchData == null) {
2114 appSearchData = new Bundle();
2115 } else {
2116 appSearchData = new Bundle(appSearchData);
2117 }
2118 // Set source to package name of app that starts global search, if not set already.
2119 if (!appSearchData.containsKey("source")) {
2120 appSearchData.putString("source", getPackageName());
2121 }
2122 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2123 if (!TextUtils.isEmpty(initialQuery)) {
2124 intent.putExtra(SearchManager.QUERY, initialQuery);
2125 }
2126 if (selectInitialQuery) {
2127 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2128 }
2129 intent.setSourceBounds(sourceBounds);
2130 try {
2131 startActivity(intent);
2132 } catch (ActivityNotFoundException ex) {
2133 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2134 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 }
2136
Yura4f93ec62014-02-04 14:15:21 +00002137 public boolean isOnCustomContent() {
2138 return mWorkspace.isOnOrMovingToCustomContent();
2139 }
2140
Winson Chung70d72102011-08-12 11:24:35 -07002141 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002142 public boolean onPrepareOptionsMenu(Menu menu) {
2143 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002144 if (!isOnCustomContent()) {
2145 // Close any open folders
2146 closeFolder();
2147 // Stop resizing any widgets
2148 mWorkspace.exitWidgetResizeMode();
2149 if (!mWorkspace.isInOverviewMode()) {
2150 // Show the overview mode
2151 showOverviewMode(true);
2152 } else {
2153 showWorkspace(true);
2154 }
Winson Chunge0298742014-01-17 12:03:00 -08002155 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002156 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002157 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002159 @Override
2160 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002161 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002162 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002163 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002164 }
2165
Joe Onorato9c1289c2009-08-17 11:03:03 -04002166 public boolean isWorkspaceLocked() {
2167 return mWorkspaceLoading || mWaitingForResult;
2168 }
2169
Adam Cohen517a7f52014-03-01 12:12:59 -08002170 public boolean isWorkspaceLoading() {
2171 return mWorkspaceLoading;
2172 }
2173
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002174 private void setWorkspaceLoading(boolean value) {
2175 boolean isLocked = isWorkspaceLocked();
2176 mWorkspaceLoading = value;
2177 if (isLocked != isWorkspaceLocked()) {
2178 onWorkspaceLockedChanged();
2179 }
2180 }
2181
2182 private void setWaitingForResult(boolean value) {
2183 boolean isLocked = isWorkspaceLocked();
2184 mWaitingForResult = value;
2185 if (isLocked != isWorkspaceLocked()) {
2186 onWorkspaceLockedChanged();
2187 }
2188 }
2189
2190 protected void onWorkspaceLockedChanged() { }
2191
Michael Jurka0280c3b2010-09-17 15:00:07 -07002192 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002193 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002194 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002195 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2196 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002197 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002198 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002199 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002200
Adam Cohenad4e15c2013-10-17 16:21:35 -07002201 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2202 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2203 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2204 }
2205
2206 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2207 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2208 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002209 if (appWidgetInfo.configure != null) {
2210 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002211 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002212
Bjorn Bringert7984c942009-12-09 15:38:25 +00002213 // Launch over to configure widget, if needed
2214 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002215 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002216 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002217 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002218 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002219 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002220 Runnable onComplete = new Runnable() {
2221 @Override
2222 public void run() {
2223 // Exit spring loaded mode if necessary after adding the widget
2224 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2225 null);
2226 }
2227 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002228 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002229 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002230 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 }
2232 }
Romain Guycbb89e42009-06-08 15:52:54 -07002233
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002234 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002235 // Close any folders that may be open.
2236 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002237 mWorkspace.moveToCustomContentScreen(animate);
2238 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002239 /**
2240 * Process a shortcut drop.
2241 *
2242 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002243 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002244 * @param cell The cell it should be added to, optional
2245 * @param position The location on the screen where it was dropped, optional
2246 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002247 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002248 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002249 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002250 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002251 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002252 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253
2254 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002255 mPendingAddInfo.cellX = cell[0];
2256 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002258
2259 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2260 createShortcutIntent.setComponent(componentName);
2261 processShortcut(createShortcutIntent);
2262 }
2263
Adam Cohenfbba09b2011-07-18 21:43:05 -07002264 /**
2265 * Process a widget drop.
2266 *
2267 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002268 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002269 * @param cell The cell it should be added to, optional
2270 * @param position The location on the screen where it was dropped, optional
2271 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002272 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002273 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002274 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002275 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002276 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002277 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002278 mPendingAddInfo.minSpanX = info.minSpanX;
2279 mPendingAddInfo.minSpanY = info.minSpanY;
2280
Adam Cohenfbba09b2011-07-18 21:43:05 -07002281 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002282 mPendingAddInfo.cellX = cell[0];
2283 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002284 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002285 if (span != null) {
2286 mPendingAddInfo.spanX = span[0];
2287 mPendingAddInfo.spanY = span[1];
2288 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002289
Adam Cohened66b2b2012-01-23 17:28:51 -08002290 AppWidgetHostView hostView = info.boundWidget;
2291 int appWidgetId;
2292 if (hostView != null) {
2293 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002294 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002295 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002296 // In this case, we either need to start an activity to get permission to bind
2297 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002298 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002299 Bundle options = info.bindOptions;
2300
2301 boolean success = false;
2302 if (options != null) {
2303 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2304 info.componentName, options);
2305 } else {
2306 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2307 info.componentName);
2308 }
2309 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002310 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002311 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002312 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002313 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2314 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2315 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002316 // TODO: we need to make sure that this accounts for the options bundle.
2317 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002318 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2319 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002320 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002321 }
2322
Joe Onoratodeb98af2010-02-19 14:59:39 -08002323 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002324 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002325 }
2326
Winson Chung24ab2f12010-09-16 14:10:47 -07002327 void processWallpaper(Intent intent) {
2328 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2329 }
2330
Adam Cohendcd297f2013-06-18 13:13:40 -07002331 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002332 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002333 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002334 folderInfo.title = getText(R.string.folder_name);
2335
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002336 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002337 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002338 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002339 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340
2341 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002342 FolderIcon newFolder =
2343 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002344 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002345 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002346 // Force measure the new folder icon
2347 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2348 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002349 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002350 }
Romain Guycbb89e42009-06-08 15:52:54 -07002351
Joe Onorato9c1289c2009-08-17 11:03:03 -04002352 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002353 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002354 }
2355
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002356 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002357 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002358 }
2359
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002360 /**
2361 * Registers various content observers. The current implementation registers
2362 * only a favorites observer to keep track of the favorites applications.
2363 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002364 private void registerContentObservers() {
2365 ContentResolver resolver = getContentResolver();
2366 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2367 true, mWidgetObserver);
2368 }
2369
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 @Override
2371 public boolean dispatchKeyEvent(KeyEvent event) {
2372 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2373 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002375 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002376 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002377 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002378 dumpState();
2379 return true;
2380 }
2381 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002382 }
2383 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2384 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002385 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 return true;
2387 }
2388 }
2389
2390 return super.dispatchKeyEvent(event);
2391 }
2392
Joe Onorato88ec0992009-11-19 13:16:06 -08002393 @Override
2394 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002395 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002396 if (mAppsCustomizeContent.getContentType() ==
2397 AppsCustomizePagedView.ContentType.Applications) {
2398 showWorkspace(true);
2399 } else {
2400 showOverviewMode(true);
2401 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002402 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002403 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002404 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002405 Folder openFolder = mWorkspace.getOpenFolder();
2406 if (openFolder.isEditingName()) {
2407 openFolder.dismissEditingName();
2408 } else {
2409 closeFolder();
2410 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002411 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002412 mWorkspace.exitWidgetResizeMode();
2413
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002414 // Back button is a no-op here, but give at least some feedback for the button press
2415 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002416 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002417 }
2418
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002419 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002420 * Re-listen when widgets are reset.
2421 */
2422 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002423 if (mAppWidgetHost != null) {
2424 mAppWidgetHost.startListening();
2425 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002426 }
2427
2428 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429 * Launches the intent referred by the clicked shortcut.
2430 *
2431 * @param v The view representing the clicked shortcut.
2432 */
2433 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002434 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2435 // view has detached (it's possible for this to happen if the view is removed mid touch).
2436 if (v.getWindowToken() == null) {
2437 return;
2438 }
2439
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002440 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002441 return;
2442 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002443
Adam Cohen1697b792013-09-17 19:08:21 -07002444 if (v instanceof Workspace) {
2445 if (mWorkspace.isInOverviewMode()) {
2446 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002447 }
2448 return;
2449 }
2450
2451 if (v instanceof CellLayout) {
2452 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002453 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002454 }
2455 }
2456
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002457 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002458 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002459 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002460 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002461 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002462 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002463 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002464 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002465 onClickAllAppsButton(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002466 } else if (tag instanceof LauncherAppWidgetInfo) {
2467 if (v instanceof PendingAppWidgetHostView) {
2468 onClickPendingWidget((PendingAppWidgetHostView) v);
2469 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002470 }
2471 }
2472
Michael Jurka0e260592010-06-30 17:07:39 -07002473 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002474 return false;
2475 }
2476
Michael Jurkaaf442092010-06-10 17:01:57 -07002477 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002478 * Event handler for the app widget view which has not fully restored.
2479 */
2480 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2481 if (v.isReadyForClickSetup()) {
2482 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2483 int widgetId = info.appWidgetId;
2484 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2485 if (appWidgetInfo != null) {
2486 mPendingAddWidgetInfo = appWidgetInfo;
2487 mPendingAddInfo.copyFrom(info);
2488 mPendingAddWidgetId = widgetId;
2489
2490 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2491 intent.setComponent(appWidgetInfo.configure);
2492 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2493 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2494 }
2495 }
2496 }
2497
2498 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002499 * Event handler for the search button
2500 *
2501 * @param v The view that was clicked.
2502 */
2503 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002504 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2505
Amith Yamasania135ba82011-08-09 17:42:01 -07002506 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002507 }
2508
2509 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002510 * Event handler for the voice button
2511 *
2512 * @param v The view that was clicked.
2513 */
2514 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002515 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002516
Bjorn Bringertc459e522013-06-07 19:36:01 +01002517 startVoice();
2518 }
2519
2520 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002521 try {
2522 final SearchManager searchManager =
2523 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2524 ComponentName activityName = searchManager.getGlobalSearchActivity();
2525 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002526 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002527 if (activityName != null) {
2528 intent.setPackage(activityName.getPackageName());
2529 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002530 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002531 } catch (ActivityNotFoundException e) {
2532 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002533 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002534 startActivitySafely(null, intent, "onClickVoiceButton");
2535 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002536 }
2537
2538 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002539 * Event handler for the "grid" button that appears on the home screen, which
2540 * enters all apps mode.
2541 *
2542 * @param v The view that was clicked.
2543 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002544 protected void onClickAllAppsButton(View v) {
2545 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2546 if (isAllAppsVisible()) {
2547 showWorkspace(true);
2548 } else {
2549 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2550 }
2551 }
2552
2553 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002554 * Event handler for a paged view icon click.
2555 * @param v The view that was clicked.
2556 * @param appInfo The {link AppInfo} of the view.
2557 */
2558 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2559 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2560 startActivitySafely(v, appInfo.intent, appInfo);
2561 getStats().recordLaunch(appInfo.intent);
2562 }
2563
2564 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002565 * Event handler for an app shortcut click.
2566 *
2567 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2568 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002569 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002570 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2571 Object tag = v.getTag();
2572 if (!(tag instanceof ShortcutInfo)) {
2573 throw new IllegalArgumentException("Input must be a Shortcut");
2574 }
2575
2576 // Open shortcut
2577 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2578 final Intent intent = shortcut.intent;
2579
2580 // Check for special shortcuts
2581 if (intent.getComponent() != null) {
2582 final String shortcutClass = intent.getComponent().getClassName();
2583
2584 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2585 MemoryDumpActivity.startDump(this);
2586 return;
2587 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2588 toggleShowWeightWatcher();
2589 return;
2590 }
2591 }
2592
Chris Wren40c5ed32014-06-24 18:24:23 -04002593 // Check for abandoned promise
2594 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002595 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2596 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002597 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002598 builder.setPositiveButton(R.string.abandoned_search,
2599 new DialogInterface.OnClickListener() {
2600 public void onClick(DialogInterface dialog, int id) {
2601 startAppShortcutActivity(v);
2602 }
2603 }
2604 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002605 builder.setNeutralButton(R.string.abandoned_clean_this,
2606 new DialogInterface.OnClickListener() {
2607 public void onClick(DialogInterface dialog, int id) {
2608 final BubbleTextView bubble = (BubbleTextView) v;
2609 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2610 mWorkspace.removeAbandonedPromise(bubble, user);
2611 }
2612 });
2613 builder.create().show();
2614 return;
2615 }
2616
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617 // Start activities
Chris Wren40c5ed32014-06-24 18:24:23 -04002618 startAppShortcutActivity(v);
2619 }
2620
2621 private void startAppShortcutActivity(View v) {
2622 Object tag = v.getTag();
2623 if (!(tag instanceof ShortcutInfo)) {
2624 throw new IllegalArgumentException("Input must be a Shortcut");
2625 }
2626 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2627 final Intent intent = shortcut.intent;
2628
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002629 int[] pos = new int[2];
2630 v.getLocationOnScreen(pos);
2631 intent.setSourceBounds(new Rect(pos[0], pos[1],
2632 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2633
2634 boolean success = startActivitySafely(v, intent, tag);
2635
2636 mStats.recordLaunch(intent, shortcut);
2637
2638 if (success && v instanceof BubbleTextView) {
2639 mWaitingForResume = (BubbleTextView) v;
2640 mWaitingForResume.setStayPressed(true);
2641 }
2642 }
2643
2644 /**
2645 * Event handler for a folder icon click.
2646 *
2647 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2648 */
2649 protected void onClickFolderIcon(View v) {
2650 if (LOGD) Log.d(TAG, "onClickFolder");
2651 if (!(v instanceof FolderIcon)){
2652 throw new IllegalArgumentException("Input must be a FolderIcon");
2653 }
2654
2655 FolderIcon folderIcon = (FolderIcon) v;
2656 final FolderInfo info = folderIcon.getFolderInfo();
2657 Folder openFolder = mWorkspace.getFolderForTag(info);
2658
2659 // If the folder info reports that the associated folder is open, then verify that
2660 // it is actually opened. There have been a few instances where this gets out of sync.
2661 if (info.opened && openFolder == null) {
2662 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2663 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2664 info.opened = false;
2665 }
2666
2667 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2668 // Close any open folder
2669 closeFolder();
2670 // Open the requested folder
2671 openFolder(folderIcon);
2672 } else {
2673 // Find the open folder...
2674 int folderScreen;
2675 if (openFolder != null) {
2676 folderScreen = mWorkspace.getPageForView(openFolder);
2677 // .. and close it
2678 closeFolder(openFolder);
2679 if (folderScreen != mWorkspace.getCurrentPage()) {
2680 // Close any folder open on the current screen
2681 closeFolder();
2682 // Pull the folder onto this screen
2683 openFolder(folderIcon);
2684 }
2685 }
2686 }
Michael Jurka5130e402011-10-13 04:55:35 -07002687 }
2688
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002689 /**
2690 * Event handler for the (Add) Widgets button that appears after a long press
2691 * on the home screen.
2692 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002693 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002694 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002695 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2696 }
2697
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002698 /**
2699 * Event handler for the wallpaper picker button that appears after a long press
2700 * on the home screen.
2701 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002702 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002703 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2704 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2705 pickWallpaper.setComponent(getWallpaperPickerComponent());
2706 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2707 }
2708
2709 /**
2710 * Event handler for a click on the settings button that appears after a long press
2711 * on the home screen.
2712 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002713 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002714 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2715 }
2716
Michael Jurka5130e402011-10-13 04:55:35 -07002717 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002718 // Provide the same haptic feedback that the system offers for virtual keys.
2719 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002720 }
2721
Adam Cohen61f560d2013-09-30 15:58:20 -07002722 public void performHapticFeedbackOnTouchDown(View v) {
2723 // Provide the same haptic feedback that the system offers for virtual keys.
2724 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2725 }
2726
2727 public View.OnTouchListener getHapticFeedbackTouchListener() {
2728 if (mHapticFeedbackTouchListener == null) {
2729 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2730 @Override
2731 public boolean onTouch(View v, MotionEvent event) {
2732 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2733 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2734 }
2735 return false;
2736 }
2737 };
2738 }
2739 return mHapticFeedbackTouchListener;
2740 }
2741
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002742 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002743 if (!DISABLE_MARKET_BUTTON) {
2744 if (mAppMarketIntent != null) {
2745 startActivitySafely(v, mAppMarketIntent, "app market");
2746 } else {
2747 Log.e(TAG, "Invalid app market intent.");
2748 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002749 }
2750 }
2751
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002752 public void onDragStarted(View view) {}
2753
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002754 /**
2755 * Called when the user stops interacting with the launcher.
2756 * This implies that the user is now on the homescreen and is not doing housekeeping.
2757 */
2758 protected void onInteractionEnd() {}
2759
2760 /**
2761 * Called when the user starts interacting with the launcher.
2762 * The possible interactions are:
2763 * - open all apps
2764 * - reorder an app shortcut, or a widget
2765 * - open the overview mode.
2766 * This is a good time to stop doing things that only make sense
2767 * when the user is on the homescreen and not doing housekeeping.
2768 */
2769 protected void onInteractionBegin() {}
2770
Kenny Guyf07af7b2014-07-31 11:39:16 +01002771 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002772 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002773 try {
2774 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2775 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2776 launcherApps.showAppDetailsForProfile(componentName, user);
2777 } catch (SecurityException e) {
2778 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2779 Log.e(TAG, "Launcher does not have permission to launch settings");
2780 } catch (ActivityNotFoundException e) {
2781 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2782 Log.e(TAG, "Unable to launch settings");
2783 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002784 }
2785
Michael Jurka1e2f4652013-07-08 18:03:46 -07002786 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002787 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2788 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002789 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002790 // System applications cannot be installed. For now, show a toast explaining that.
2791 // We may give them the option of disabling apps this way.
2792 int messageId = R.string.uninstall_system_app_text;
2793 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002794 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002795 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002796 String packageName = componentName.getPackageName();
2797 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002798 Intent intent = new Intent(
2799 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002800 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2801 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002802 if (user != null) {
2803 user.addToIntent(intent, Intent.EXTRA_USER);
2804 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002805 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002806 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002807 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002808 }
2809
Michael Jurka86a720e2012-05-09 11:23:23 -07002810 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002811 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002812 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002813 // Only launch using the new animation if the shortcut has not opted out (this is a
2814 // private contract between launcher and may be ignored in the future).
2815 boolean useLaunchAnimation = (v != null) &&
2816 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002817 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2818 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002819
Kenny Guy1317e2d2014-05-08 18:52:50 +01002820 UserHandleCompat user = null;
2821 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2822 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2823 user = userManager.getUserForSerialNumber(serialNumber);
2824 }
2825
2826 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002827 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002828 ActivityOptions opts = Utilities.isLmp() ?
2829 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2830 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002831 optsBundle = opts.toBundle();
2832 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002833
2834 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2835 // Could be launching some bookkeeping activity
2836 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002837 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002838 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002839 launcherApps.startActivityForProfile(intent.getComponent(), user,
2840 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002841 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002842 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002843 } catch (SecurityException e) {
2844 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002845 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002846 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002847 "or use the exported attribute for this activity. "
2848 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002849 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002850 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002851 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002852
Michael Jurka86a720e2012-05-09 11:23:23 -07002853 boolean startActivitySafely(View v, Intent intent, Object tag) {
2854 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002855 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2856 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2857 return false;
2858 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002859 try {
2860 success = startActivity(v, intent, tag);
2861 } catch (ActivityNotFoundException e) {
2862 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2863 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2864 }
2865 return success;
2866 }
2867
Adam Cohen268c4752012-06-06 17:47:33 -07002868 /**
2869 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2870 * in the DragLayer in the exact absolute location of the original FolderIcon.
2871 */
2872 private void copyFolderIconToImage(FolderIcon fi) {
2873 final int width = fi.getMeasuredWidth();
2874 final int height = fi.getMeasuredHeight();
2875
2876 // Lazy load ImageView, Bitmap and Canvas
2877 if (mFolderIconImageView == null) {
2878 mFolderIconImageView = new ImageView(this);
2879 }
2880 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2881 mFolderIconBitmap.getHeight() != height) {
2882 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2883 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2884 }
2885
2886 DragLayer.LayoutParams lp;
2887 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2888 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2889 } else {
2890 lp = new DragLayer.LayoutParams(width, height);
2891 }
2892
Adam Cohen307fe232012-08-16 17:55:58 -07002893 // The layout from which the folder is being opened may be scaled, adjust the starting
2894 // view size by this scale factor.
2895 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002896 lp.customPosition = true;
2897 lp.x = mRectForFolderAnimation.left;
2898 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002899 lp.width = (int) (scale * width);
2900 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002901
2902 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2903 fi.draw(mFolderIconCanvas);
2904 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002905 if (fi.getFolder() != null) {
2906 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2907 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002908 }
Adam Cohen268c4752012-06-06 17:47:33 -07002909 // Just in case this image view is still in the drag layer from a previous animation,
2910 // we remove it and re-add it.
2911 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2912 mDragLayer.removeView(mFolderIconImageView);
2913 }
2914 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002915 if (fi.getFolder() != null) {
2916 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002917 }
Adam Cohen268c4752012-06-06 17:47:33 -07002918 }
2919
Adam Cohen2801caf2011-05-13 20:57:39 -07002920 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002921 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002922 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2923 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2924 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2925
Adam Cohenc51934b2011-07-26 21:07:43 -07002926 FolderInfo info = (FolderInfo) fi.getTag();
2927 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2928 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002929 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2930 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002931 }
2932
Adam Cohen268c4752012-06-06 17:47:33 -07002933 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2934 copyFolderIconToImage(fi);
2935 fi.setVisibility(View.INVISIBLE);
2936
Michael Jurka2ecf9952012-06-18 12:52:28 -07002937 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002938 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002939 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2940 oa.start();
2941 }
2942
Adam Cohen268c4752012-06-06 17:47:33 -07002943 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002944 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002945 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2946 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2947 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2948
Adam Cohen268c4752012-06-06 17:47:33 -07002949 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002950
Adam Cohen268c4752012-06-06 17:47:33 -07002951 // We remove and re-draw the FolderIcon in-case it has changed
2952 mDragLayer.removeView(mFolderIconImageView);
2953 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002954 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002955 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002956 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002957 oa.addListener(new AnimatorListenerAdapter() {
2958 @Override
2959 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002960 if (cl != null) {
2961 cl.clearFolderLeaveBehind();
2962 // Remove the ImageView copy of the FolderIcon and make the original visible.
2963 mDragLayer.removeView(mFolderIconImageView);
2964 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002965 }
2966 }
2967 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002968 oa.start();
2969 }
2970
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002971 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002972 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002973 * is animated relative to the specified View. If the View is null, no animation
2974 * is played.
2975 *
2976 * @param folderInfo The FolderInfo describing the folder to open.
2977 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002978 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002979 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002980 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002981
Adam Cohena9cf38f2011-05-02 15:36:58 -07002982 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002983
Adam Cohen4554ee12011-08-03 16:13:21 -07002984 // Just verify that the folder hasn't already been added to the DragLayer.
2985 // There was a one-off crash where the folder had a parent already.
2986 if (folder.getParent() == null) {
2987 mDragLayer.addView(folder);
2988 mDragController.addDropTarget((DropTarget) folder);
2989 } else {
2990 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2991 folder.getParent() + ").");
2992 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002993 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002994 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002995
2996 // Notify the accessibility manager that this folder "window" has appeared and occluded
2997 // the workspace items
2998 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2999 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003000 }
3001
3002 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003003 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003004 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003005 if (folder.isEditingName()) {
3006 folder.dismissEditingName();
3007 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003008 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07003009
3010 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08003011 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07003012 }
3013 }
3014
3015 void closeFolder(Folder folder) {
3016 folder.getInfo().opened = false;
3017
3018 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3019 if (parent != null) {
3020 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3021 shrinkAndFadeInFolderIcon(fi);
3022 }
3023 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003024
3025 // Notify the accessibility manager that this folder "window" has disappeard and no
3026 // longer occludeds the workspace items
3027 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003028 }
3029
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003030 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003031 if (!isDraggingEnabled()) return false;
3032 if (isWorkspaceLocked()) return false;
3033 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003034
Adam Cohen1697b792013-09-17 19:08:21 -07003035 if (v instanceof Workspace) {
3036 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003037 if (mWorkspace.enterOverviewMode()) {
3038 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3039 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3040 return true;
3041 } else {
3042 return false;
3043 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003044 } else {
3045 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003046 }
Adam Cohen1697b792013-09-17 19:08:21 -07003047 }
3048
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003049 CellLayout.CellInfo longClickCellInfo = null;
3050 View itemUnderLongClick = null;
3051 if (v.getTag() instanceof ItemInfo) {
3052 ItemInfo info = (ItemInfo) v.getTag();
3053 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3054 itemUnderLongClick = longClickCellInfo.cell;
3055 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003056 }
3057
Winson Chung3d503fb2011-07-13 17:25:49 -07003058 // The hotseat touch handling does not go through Workspace, and we always allow long press
3059 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003060 final boolean inHotseat = isHotseatLayout(v);
3061 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003062 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003063 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003064 // User long pressed on empty space
3065 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3066 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003067 if (mWorkspace.isInOverviewMode()) {
3068 mWorkspace.startReordering(v);
3069 } else {
3070 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003071 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003072 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003073 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3074 mHotseat.getOrderInHotseat(
3075 longClickCellInfo.cellX,
3076 longClickCellInfo.cellY));
3077 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003078 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003079 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003080 }
3081 }
3082 }
3083 return true;
3084 }
3085
Winson Chung3d503fb2011-07-13 17:25:49 -07003086 boolean isHotseatLayout(View layout) {
3087 return mHotseat != null && layout != null &&
3088 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3089 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003090
Winson Chung3d503fb2011-07-13 17:25:49 -07003091 /**
3092 * Returns the CellLayout of the specified container at the specified screen.
3093 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003094 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003095 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3096 if (mHotseat != null) {
3097 return mHotseat.getLayout();
3098 } else {
3099 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003100 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003101 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003102 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003103 }
3104 }
3105
Daniel Sandler843e8602010-06-07 14:59:01 -04003106 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003107 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003108 }
3109
Craig Mautner360310b2012-10-26 15:13:08 -07003110 private void setWorkspaceBackground(boolean workspace) {
3111 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003112 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003113 }
3114
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003115 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003116 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3117 int curflags = getWindow().getAttributes().flags
3118 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3119 if (wpflags != curflags) {
3120 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3121 }
Craig Mautner360310b2012-10-26 15:13:08 -07003122 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003123 }
3124
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003125 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3126 if (v instanceof LauncherTransitionable) {
3127 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3128 }
3129 }
3130
Michael Jurkabed61d22012-02-14 22:51:29 -08003131 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3132 if (v instanceof LauncherTransitionable) {
3133 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3134 }
Winson Chung70442722012-02-10 15:43:22 -08003135
3136 // Update the workspace transition step as well
3137 dispatchOnLauncherTransitionStep(v, 0f);
3138 }
3139
3140 private void dispatchOnLauncherTransitionStep(View v, float t) {
3141 if (v instanceof LauncherTransitionable) {
3142 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3143 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003144 }
3145
3146 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3147 if (v instanceof LauncherTransitionable) {
3148 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3149 }
Winson Chung70442722012-02-10 15:43:22 -08003150
3151 // Update the workspace transition step as well
3152 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003153 }
3154
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003155 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003156 * Things to test when changing the following seven functions.
3157 * - Home from workspace
3158 * - from center screen
3159 * - from other screens
3160 * - Home from all apps
3161 * - from center screen
3162 * - from other screens
3163 * - Back from all apps
3164 * - from center screen
3165 * - from other screens
3166 * - Launch app from workspace and quit
3167 * - with back
3168 * - with home
3169 * - Launch app from all apps and quit
3170 * - with back
3171 * - with home
3172 * - Go to a screen that's not the default, then all
3173 * apps, and launch and app, and go back
3174 * - with back
3175 * -with home
3176 * - On workspace, long press power and go back
3177 * - with back
3178 * - with home
3179 * - On all apps, long press power and go back
3180 * - with back
3181 * - with home
3182 * - On workspace, power off
3183 * - On all apps, power off
3184 * - Launch an app and turn off the screen while in that app
3185 * - Go back with home key
3186 * - Go back with back key TODO: make this not go to workspace
3187 * - From all apps
3188 * - From workspace
3189 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3190 * - From all apps
3191 * - From the center workspace
3192 * - From another workspace
3193 */
3194
3195 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003196 * Zoom the camera out from the workspace to reveal 'toView'.
3197 * Assumes that the view to show is anchored at either the very top or very bottom
3198 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003199 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003200 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003201 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3202 showAppsCustomizeHelper(animated, springLoaded, contentType);
3203 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003204
Winson Chungc58497e2013-09-03 17:48:37 -07003205 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3206 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003207 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003208 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003209 mStateAnimation.cancel();
3210 mStateAnimation = null;
3211 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003212
3213 boolean material = Utilities.isLmp();
3214
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003215 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003216
Winson Chungf0ea4d32011-06-06 14:27:16 -07003217 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3218 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003219 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003220 final int itemsAlphaStagger =
3221 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003222
Winson Chungf0ea4d32011-06-06 14:27:16 -07003223 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003224 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003225 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003226
Adam Cohen6c5891a2014-07-09 23:53:15 -07003227 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3228 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003229 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003230 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003231 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003232 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3233 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003234 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3235 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003236
3237 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003238 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003239
Adam Cohen9bfdb762014-07-21 17:44:06 -07003240 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3241 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003242
Adam Cohen9bfdb762014-07-21 17:44:06 -07003243 final View page = content.getPageAt(content.getCurrentPage());
3244 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003245
Adam Cohen63f1ec02014-08-12 09:23:13 -07003246 final float initialPanelAlpha = 1f;
3247
3248 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3249 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003250 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3251 } else {
3252 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3253 }
3254
Adam Cohen9bfdb762014-07-21 17:44:06 -07003255 // Hide the real page background, and swap in the fake one
3256 revealView.setVisibility(View.VISIBLE);
3257 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003258
Adam Cohen9bfdb762014-07-21 17:44:06 -07003259 int width = revealView.getMeasuredWidth();
3260 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003261
Adam Cohen9bfdb762014-07-21 17:44:06 -07003262 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003263 revealView.setTranslationY(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003264
Adam Cohen63f1ec02014-08-12 09:23:13 -07003265 // Get the y delta between the center of the page and the center of the all apps button
3266 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3267 getAllAppsButton(), null);
3268 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3269
3270 float initAlpha = isWidgetTray ? 0.3f : 1f;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003271 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003272 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003273 PropertyValuesHolder panelDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003274 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003275
Adam Cohen9bfdb762014-07-21 17:44:06 -07003276 ObjectAnimator panelAlphaAndDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003277 LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003278 panelAlphaAndDrift.setDuration(revealDuration);
3279 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003280
Adam Cohen9bfdb762014-07-21 17:44:06 -07003281 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003282
Adam Cohen4e243a22014-08-10 18:30:55 -07003283 if (page != null) {
3284 page.setVisibility(View.VISIBLE);
3285 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003286
Adam Cohen63f1ec02014-08-12 09:23:13 -07003287 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0);
Adam Cohen4e243a22014-08-10 18:30:55 -07003288 pageDrift.setDuration(revealDuration);
3289 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003290 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003291 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003292
Adam Cohen63f1ec02014-08-12 09:23:13 -07003293 page.setAlpha(0f);
3294 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003295 itemsAlpha.setDuration(revealDuration);
3296 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3297 itemsAlpha.setStartDelay(itemsAlphaStagger);
3298 mStateAnimation.play(itemsAlpha);
3299 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003300
Adam Cohen4e243a22014-08-10 18:30:55 -07003301 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3302 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003303 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003304 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003305 indicatorsAlpha.setDuration(revealDuration);
3306 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003307
Adam Cohen9bfdb762014-07-21 17:44:06 -07003308 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003309 final View allApps = getAllAppsButton();
3310 int allAppsButtonSize = LauncherAppState.getInstance().
3311 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3312 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003313 ValueAnimator reveal = (ValueAnimator)
Adam Cohen63f1ec02014-08-12 09:23:13 -07003314 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3315 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003316 reveal.setDuration(revealDuration);
3317 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003318
3319 reveal.addListener(new AnimatorListenerAdapter() {
3320 public void onAnimationStart(Animator animation) {
3321 if (!isWidgetTray) {
3322 allApps.setVisibility(View.INVISIBLE);
3323 }
3324 }
3325 public void onAnimationEnd(Animator animation) {
3326 if (!isWidgetTray) {
3327 allApps.setVisibility(View.VISIBLE);
3328 }
3329 }
3330 });
3331
Adam Cohen6c5891a2014-07-09 23:53:15 -07003332 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003333 }
Michael Jurka1899a362011-11-03 13:50:45 -07003334
Adam Cohen9bfdb762014-07-21 17:44:06 -07003335 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3336 @Override
3337 public void onAnimationEnd(Animator animation) {
3338 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3339 dispatchOnLauncherTransitionEnd(toView, animated, false);
3340
3341 revealView.setVisibility(View.INVISIBLE);
3342 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003343 if (page != null) {
3344 page.setLayerType(View.LAYER_TYPE_NONE, null);
3345 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003346 content.setPageBackgroundsVisible(true);
3347
3348 // Hide the search bar
3349 if (mSearchDropTargetBar != null) {
3350 mSearchDropTargetBar.hideSearchBar(false);
3351 }
3352 }
3353
3354 @Override
3355 public void onAnimationStart(Animator animation) {
3356 // Prepare the position
3357 toView.bringToFront();
3358 toView.setVisibility(View.VISIBLE);
3359 }
3360 });
3361
Michael Jurka1899a362011-11-03 13:50:45 -07003362 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003363 if (workspaceAnim != null) {
3364 mStateAnimation.play(workspaceAnim);
3365 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003366 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3367 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003368
3369 // If any of the objects being animated haven't been measured/laid out
3370 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003371 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003372 (mWorkspace.getMeasuredWidth() == 0) ||
3373 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003374 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003375 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003376
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003377 final AnimatorSet stateAnimation = mStateAnimation;
3378 final Runnable startAnimRunnable = new Runnable() {
3379 public void run() {
3380 // Check that mStateAnimation hasn't changed while
3381 // we waited for a layout/draw pass
3382 if (mStateAnimation != stateAnimation)
3383 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003384 dispatchOnLauncherTransitionStart(fromView, animated, false);
3385 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003386 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003387 }
3388 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003389 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003390 toView.bringToFront();
3391 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003392 final ViewTreeObserver observer = toView.getViewTreeObserver();
3393 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3394 public void onGlobalLayout() {
3395 startAnimRunnable.run();
3396 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3397 }
3398 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003399 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003400 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003401 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003402 } else {
3403 toView.setTranslationX(0.0f);
3404 toView.setTranslationY(0.0f);
3405 toView.setScaleX(1.0f);
3406 toView.setScaleY(1.0f);
3407 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003408 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003409
Daniel Sandlere4f98912013-06-25 15:13:26 -04003410 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003411 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003412 if (mSearchDropTargetBar != null) {
3413 mSearchDropTargetBar.hideSearchBar(false);
3414 }
Michael Jurkaabded662011-03-04 12:06:57 -08003415 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003416 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003417 dispatchOnLauncherTransitionStart(fromView, animated, false);
3418 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003419 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003420 dispatchOnLauncherTransitionStart(toView, animated, false);
3421 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003422 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003423 }
3424
3425 /**
3426 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003427 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003428 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003429 */
Adam Cohened307df2013-10-02 09:37:31 -07003430 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003431 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003432
Michael Jurkab3e22d92011-10-31 15:58:33 -07003433 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003434 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003435 mStateAnimation.cancel();
3436 mStateAnimation = null;
3437 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003438
3439 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003440 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003441
Winson Chungf0ea4d32011-06-06 14:27:16 -07003442 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003443 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003444 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003445 final int itemsAlphaStagger =
3446 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003447
Winson Chungf0ea4d32011-06-06 14:27:16 -07003448 final float scaleFactor = (float)
3449 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3450 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003451 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003452 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003453 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003454 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen63f1ec02014-08-12 09:23:13 -07003455 toState, animated);
Adam Cohened307df2013-10-02 09:37:31 -07003456 } else if (toState == Workspace.State.SPRING_LOADED ||
3457 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003458 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003459 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003460 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003461
Winson Chung4afe9b32011-07-27 17:46:20 -07003462 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003463 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003464 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003465
Adam Cohen9bfdb762014-07-21 17:44:06 -07003466 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3467 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003468
Adam Cohen9bfdb762014-07-21 17:44:06 -07003469 final View page = content.getPageAt(content.getNextPage());
3470 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003471
Adam Cohen4e243a22014-08-10 18:30:55 -07003472 AppsCustomizePagedView.ContentType contentType = content.getContentType();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003473 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3474
3475 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003476 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3477 } else {
3478 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3479 }
3480
Adam Cohen9bfdb762014-07-21 17:44:06 -07003481 int width = revealView.getMeasuredWidth();
3482 int height = revealView.getMeasuredHeight();
3483 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003484
Adam Cohen9bfdb762014-07-21 17:44:06 -07003485 // Hide the real page background, and swap in the fake one
3486 revealView.setVisibility(View.VISIBLE);
3487 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003488
Adam Cohen63f1ec02014-08-12 09:23:13 -07003489 final View allAppsButton = getAllAppsButton();
3490 revealView.setTranslationY(0);
3491 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3492 allAppsButton, null);
3493 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen6c5891a2014-07-09 23:53:15 -07003494
Adam Cohen9bfdb762014-07-21 17:44:06 -07003495 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003496
Adam Cohen63f1ec02014-08-12 09:23:13 -07003497 // The vertical motion of the apps panel should be delayed by one frame
3498 // from the conceal animation in order to give the right feel. We correpsondingly
3499 // shorten the duration so that the slide and conceal end at the same time.
3500 ObjectAnimator panelDrift = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
3501 panelDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3502 panelDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3503 panelDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3504 mStateAnimation.play(panelDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003505
Adam Cohen63f1ec02014-08-12 09:23:13 -07003506 if (isWidgetTray) {
3507 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f);
3508 panelAlpha.setDuration(revealDuration);
3509 panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3510 mStateAnimation.play(panelAlpha);
3511 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003512
Adam Cohen4e243a22014-08-10 18:30:55 -07003513 if (page != null) {
3514 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003515
Adam Cohen63f1ec02014-08-12 09:23:13 -07003516 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3517 0, yDrift);
3518 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003519 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003520 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003521 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003522
Adam Cohen4e243a22014-08-10 18:30:55 -07003523 page.setAlpha(1f);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003524 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3525 itemsAlpha.setDuration(100);
Adam Cohen4e243a22014-08-10 18:30:55 -07003526 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3527 mStateAnimation.play(itemsAlpha);
3528 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003529
Adam Cohen9bfdb762014-07-21 17:44:06 -07003530 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003531 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003532 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003533 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003534 indicatorsAlpha.setDuration(revealDuration);
3535 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3536 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003537
Adam Cohen9bfdb762014-07-21 17:44:06 -07003538 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003539
Adam Cohen9bfdb762014-07-21 17:44:06 -07003540 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003541 if (!isWidgetTray) {
3542 allAppsButton.setVisibility(View.INVISIBLE);
3543 }
3544 int allAppsButtonSize = LauncherAppState.getInstance().
3545 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3546 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003547 Animator reveal =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003548 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3549 height / 2, revealRadius, finalRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003550 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3551 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003552 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003553
3554 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003555 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003556 revealView.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003557 if (!isWidgetTray) {
3558 allAppsButton.setVisibility(View.VISIBLE);
3559 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003560 }
3561 });
3562
Adam Cohen6c5891a2014-07-09 23:53:15 -07003563 mStateAnimation.play(reveal);
3564 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003565
3566 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3567 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3568 mAppsCustomizeContent.stopScrolling();
3569
Adam Cohen6c5891a2014-07-09 23:53:15 -07003570 if (workspaceAnim != null) {
3571 mStateAnimation.play(workspaceAnim);
3572 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003573
3574 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003575 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003576 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003577 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003578 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3579 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003580 if (onCompleteRunnable != null) {
3581 onCompleteRunnable.run();
3582 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003583
3584 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003585 if (page != null) {
3586 page.setLayerType(View.LAYER_TYPE_NONE, null);
3587 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003588 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003589 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003590 }
3591 });
3592
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003593 dispatchOnLauncherTransitionStart(fromView, animated, true);
3594 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003595 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003596 } else {
3597 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003598 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003599 dispatchOnLauncherTransitionStart(fromView, animated, true);
3600 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003601 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003602 dispatchOnLauncherTransitionStart(toView, animated, true);
3603 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003604 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003605 }
3606
Michael Jurkae326f182011-11-21 14:05:46 -08003607 @Override
3608 public void onTrimMemory(int level) {
3609 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003610 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003611 mAppsCustomizeTabHost.onTrimMemory();
3612 }
3613 }
3614
Adam Cohened307df2013-10-02 09:37:31 -07003615 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003616 showWorkspace(animated, null);
3617 }
3618
Adam Cohened307df2013-10-02 09:37:31 -07003619 protected void showWorkspace() {
3620 showWorkspace(true);
3621 }
3622
Adam Cohened66b2b2012-01-23 17:28:51 -08003623 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003624 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003625 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003626 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003627 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003628
Winson Chungc7d2b602012-05-16 17:02:20 -07003629 // Show the search bar (only animate if we were showing the drop target bar in spring
3630 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003631 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003632 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003633 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003634
Michael Jurkab3e22d92011-10-31 15:58:33 -07003635 // Set focus to the AppsCustomize button
3636 if (mAllAppsButton != null) {
3637 mAllAppsButton.requestFocus();
3638 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003639 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003640
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003641 // Change the state *after* we've called all the transition code
3642 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003643
Winson Chung5fb63472011-02-02 17:03:37 -08003644 // Resume the auto-advance of widgets
3645 mUserPresent = true;
3646 updateRunning();
3647
alanv1d4fde62012-10-17 13:15:47 -07003648 // Send an accessibility event to announce the context change
3649 getWindow().getDecorView()
3650 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003651
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003652 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003653 }
3654
Adam Cohened307df2013-10-02 09:37:31 -07003655 void showOverviewMode(boolean animated) {
3656 mWorkspace.setVisibility(View.VISIBLE);
3657 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3658 mState = State.WORKSPACE;
3659 onWorkspaceShown(animated);
3660 }
3661
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003662 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003663 }
3664
Winson Chung82963d52013-10-09 11:20:57 -07003665 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3666 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003667 if (mState != State.WORKSPACE) return;
3668
Winson Chung82963d52013-10-09 11:20:57 -07003669 if (resetPageToZero) {
3670 mAppsCustomizeTabHost.reset();
3671 }
Winson Chungc58497e2013-09-03 17:48:37 -07003672 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003673 mAppsCustomizeTabHost.post(new Runnable() {
3674 @Override
3675 public void run() {
3676 // We post this in-case the all apps view isn't yet constructed.
3677 mAppsCustomizeTabHost.requestFocus();
3678 }
3679 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003680
Michael Jurkab3e22d92011-10-31 15:58:33 -07003681 // Change the state *after* we've called all the transition code
3682 mState = State.APPS_CUSTOMIZE;
3683
3684 // Pause the auto-advance of widgets until we are out of AllApps
3685 mUserPresent = false;
3686 updateRunning();
3687 closeFolder();
3688
3689 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003690 getWindow().getDecorView()
3691 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003692 }
3693
Adam Cohen7777d962011-08-18 18:58:38 -07003694 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003695 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003696 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003697 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003698 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003699 }
Adam Cohen7777d962011-08-18 18:58:38 -07003700
Adam Cohenad4e15c2013-10-17 16:21:35 -07003701 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003702 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003703 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3704
Winson Chunge7a03942011-08-05 15:05:12 -07003705 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003706 @Override
3707 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003708 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003709 // Before we show workspace, hide all apps again because
3710 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3711 // clean up our state transition functions
3712 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003713 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003714 } else {
3715 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003716 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003717 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003718 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003719 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003720
Michael Jurkad3ef3062010-11-23 16:23:58 -08003721 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003722 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003723 final boolean animated = true;
3724 final boolean springLoaded = true;
3725 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003726 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003727 }
3728 // Otherwise, we are not in spring loaded mode, so don't do anything.
3729 }
3730
Michael Jurkab3e22d92011-10-31 15:58:33 -07003731 void lockAllApps() {
3732 // TODO
3733 }
3734
3735 void unlockAllApps() {
3736 // TODO
3737 }
3738
Winson Chungf0ea4d32011-06-06 14:27:16 -07003739 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003740 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003741 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003742 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003743 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003744 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003745 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003746 int duration = 0;
3747 if (mSearchDropTargetBar != null) {
3748 duration = mSearchDropTargetBar.getTransitionInDuration();
3749 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003750 mHotseat.animate().alpha(1f).setDuration(duration);
3751 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003752 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003753 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003754 }
3755 }
3756 }
3757
3758 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003759 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003760 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003761 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003762 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003763 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003764 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003765 int duration = 0;
3766 if (mSearchDropTargetBar != null) {
3767 duration = mSearchDropTargetBar.getTransitionOutDuration();
3768 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003769 mHotseat.animate().alpha(0f).setDuration(duration);
3770 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003771 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003772 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003773 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003774 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003775 }
3776
Patrick Dubroy5f445422011-02-18 14:35:21 -08003777 /**
3778 * Add an item from all apps or customize onto the given workspace screen.
3779 * If layout is null, add to the current screen.
3780 */
3781 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003782 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003783 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003784 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003785 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003786
Winson Chungdff8ebb2011-09-08 17:25:31 -07003787 /** Maps the current orientation to an index for referencing orientation correct global icons */
3788 private int getCurrentOrientationIndexForGlobalIcons() {
3789 // default - 0, landscape - 1
3790 switch (getResources().getConfiguration().orientation) {
3791 case Configuration.ORIENTATION_LANDSCAPE:
3792 return 1;
3793 default:
3794 return 0;
3795 }
3796 }
3797
Michael Jurkaae65ee32012-04-30 11:45:54 -07003798 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003799 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003800 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003801 // Look for the toolbar icon specified in the activity meta-data
3802 Bundle metaData = packageManager.getActivityInfo(
3803 activityName, PackageManager.GET_META_DATA).metaData;
3804 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003805 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003806 if (iconResId != 0) {
3807 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003808 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003809 }
3810 }
3811 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003812 // This can happen if the activity defines an invalid drawable
3813 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3814 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003815 } catch (Resources.NotFoundException nfe) {
3816 // This can happen if the activity defines an invalid drawable
3817 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3818 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003819 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003820 return null;
3821 }
3822
3823 // if successful in getting icon, return it; otherwise, set button to use default drawable
3824 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003825 int buttonId, ComponentName activityName, int fallbackDrawableId,
3826 String toolbarResourceName) {
3827 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003828 Resources r = getResources();
3829 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3830 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003831
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003832 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003833 // If we were unable to find the icon via the meta-data, use a generic one
3834 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003835 toolbarIcon = r.getDrawable(fallbackDrawableId);
3836 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003837 if (button != null) {
3838 button.setCompoundDrawables(toolbarIcon, null, null, null);
3839 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003840 return null;
3841 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003842 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003843 if (button != null) {
3844 button.setCompoundDrawables(toolbarIcon, null, null, null);
3845 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003846 return toolbarIcon.getConstantState();
3847 }
3848 }
3849
3850 // if successful in getting icon, return it; otherwise, set button to use default drawable
3851 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003852 int buttonId, ComponentName activityName, int fallbackDrawableId,
3853 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003854 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003855 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003856
Michael Jurka19e0fc52011-07-22 18:00:21 -07003857 if (button != null) {
3858 // If we were unable to find the icon via the meta-data, use a
3859 // generic one
3860 if (toolbarIcon == null) {
3861 button.setImageResource(fallbackDrawableId);
3862 } else {
3863 button.setImageDrawable(toolbarIcon);
3864 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003865 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003866
3867 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3868
Michael Jurka0423dcf2010-10-05 14:56:18 -07003869 }
3870
Winson Chung1b884092012-06-08 17:13:02 -07003871 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003872 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003873 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003874 }
3875
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003876 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003877 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003878 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003879 }
3880
Winson Chungbb185bd2011-11-21 12:31:42 -08003881 private void invalidatePressedFocusedStates(View container, View button) {
3882 if (container instanceof HolographicLinearLayout) {
3883 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3884 layout.invalidatePressedFocusedStates();
3885 } else if (button instanceof HolographicImageView) {
3886 HolographicImageView view = (HolographicImageView) button;
3887 view.invalidatePressedFocusedStates();
3888 }
3889 }
3890
Cristina Stancu476493b2013-08-07 17:20:14 +01003891 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003892 if (mQsb == null) {
3893 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3894 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003895 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003896 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003897 }
3898
3899 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003900 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003901 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003902 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003903 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003904
Winson Chung1cad91e2011-05-25 17:41:01 -07003905 final SearchManager searchManager =
3906 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3907 ComponentName activityName = searchManager.getGlobalSearchActivity();
3908 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003909 int coi = getCurrentOrientationIndexForGlobalIcons();
3910 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003911 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3912 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3913 if (sGlobalSearchIcon[coi] == null) {
3914 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3915 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3916 TOOLBAR_ICON_METADATA_NAME);
3917 }
3918
Winson Chungc51db6a2011-10-05 11:44:49 -07003919 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3920 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003921 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003922 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003923 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003924 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003925 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3926 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003927 if (searchButton != null) searchButton.setVisibility(View.GONE);
3928 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003929 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003930 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003931 }
3932 }
3933
Cristina Stancu476493b2013-08-07 17:20:14 +01003934 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003935 final View searchButtonContainer = findViewById(R.id.search_button_container);
3936 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003937 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003938 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003939 }
3940
Cristina Stancu476493b2013-08-07 17:20:14 +01003941 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003942 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003943 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003944
Winson Chungc51db6a2011-10-05 11:44:49 -07003945 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003946 final SearchManager searchManager =
3947 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3948 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3949
3950 ComponentName activityName = null;
3951 if (globalSearchActivity != null) {
3952 // Check if the global search activity handles voice search
3953 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3954 intent.setPackage(globalSearchActivity.getPackageName());
3955 activityName = intent.resolveActivity(getPackageManager());
3956 }
3957
3958 if (activityName == null) {
3959 // Fallback: check if an activity other than the global search activity
3960 // resolves this
3961 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3962 activityName = intent.resolveActivity(getPackageManager());
3963 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003964 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003965 int coi = getCurrentOrientationIndexForGlobalIcons();
3966 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003967 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3968 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3969 if (sVoiceSearchIcon[coi] == null) {
3970 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3971 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3972 TOOLBAR_ICON_METADATA_NAME);
3973 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003974 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003975 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003976 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003977 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003978 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003979 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003980 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003981 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003982 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003983 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003984 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003985 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003986
Cristina Stancu476493b2013-08-07 17:20:14 +01003987 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003988 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3989 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003990 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003991 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003992 }
3993
Winson Chung5841efa2013-09-30 18:06:44 -07003994 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003995 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3996 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003997 boolean visible = !forceDisableVoiceButtonProxy &&
3998 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003999 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004000 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004001 }
4002 }
Winson Chung5841efa2013-09-30 18:06:44 -07004003
4004 /**
4005 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
4006 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4007 */
4008 public void disableVoiceButtonProxy(boolean disabled) {
4009 updateVoiceButtonProxyVisible(disabled);
4010 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004011 /**
Winson Chungeb66b142011-06-16 13:14:22 -07004012 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004013 */
4014 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07004015 if (!DISABLE_MARKET_BUTTON) {
4016 final View marketButton = findViewById(R.id.market_button);
4017 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
4018 // Find the app market activity by resolving an intent.
4019 // (If multiple app markets are installed, it will return the ResolverActivity.)
4020 ComponentName activityName = intent.resolveActivity(getPackageManager());
4021 if (activityName != null) {
4022 int coi = getCurrentOrientationIndexForGlobalIcons();
4023 mAppMarketIntent = intent;
4024 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
4025 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
4026 TOOLBAR_ICON_METADATA_NAME);
4027 marketButton.setVisibility(View.VISIBLE);
4028 } else {
4029 // We should hide and disable the view so that we don't try and restore the visibility
4030 // of it when we swap between drag & normal states from IconDropTarget subclasses.
4031 marketButton.setVisibility(View.GONE);
4032 marketButton.setEnabled(false);
4033 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07004034 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004035 }
4036
Michael Jurkae7bf83b2010-12-14 18:02:21 -08004037 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07004038 if (!DISABLE_MARKET_BUTTON) {
4039 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
4040 Resources r = getResources();
4041 Drawable marketIconDrawable = d.newDrawable(r);
4042 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
4043 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
4044 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07004045
Winson Chungd64a6662013-09-30 11:06:59 -07004046 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
4047 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08004048 }
4049
Michael Jurkad7c28052012-04-27 15:43:36 -07004050 @Override
4051 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004052 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004053 final List<CharSequence> text = event.getText();
4054 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004055 // Populate event with a fake title based on the current state.
4056 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004057 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004058 } else {
4059 text.add(getString(R.string.all_apps_home_button_label));
4060 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004061 return result;
4062 }
4063
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004064 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004065 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004066 */
4067 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4068 @Override
4069 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004070 closeSystemDialogs();
4071 }
4072 }
4073
4074 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004075 * Receives notifications whenever the appwidgets are reset.
4076 */
4077 private class AppWidgetResetObserver extends ContentObserver {
4078 public AppWidgetResetObserver() {
4079 super(new Handler());
4080 }
4081
4082 @Override
4083 public void onChange(boolean selfChange) {
4084 onAppWidgetReset();
4085 }
4086 }
4087
4088 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004089 * If the activity is currently paused, signal that we need to run the passed Runnable
4090 * in onResume.
4091 *
4092 * This needs to be called from incoming places where resources might have been loaded
4093 * while we are paused. That is becaues the Configuration might be wrong
4094 * when we're not running, and if it comes back to what it was when we
4095 * were paused, we are not restarted.
4096 *
4097 * Implementation of the method from LauncherModel.Callbacks.
4098 *
4099 * @return true if we are currently paused. The caller might be able to
4100 * skip some work in that case since we will come back again.
4101 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004102 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004103 if (mPaused) {
4104 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004105 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004106 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004107 }
4108 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004109 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004110 return true;
4111 } else {
4112 return false;
4113 }
4114 }
4115
Michael Jurkac402cd92013-05-20 15:49:32 +02004116 private boolean waitUntilResume(Runnable run) {
4117 return waitUntilResume(run, false);
4118 }
4119
Michael Jurka1e2f4652013-07-08 18:03:46 -07004120 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004121 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004122 }
4123
Michael Jurka7607c2f2013-04-03 14:33:19 -07004124 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004125 * If the activity is currently paused, signal that we need to re-run the loader
4126 * in onResume.
4127 *
4128 * This needs to be called from incoming places where resources might have been loaded
4129 * while we are paused. That is becaues the Configuration might be wrong
4130 * when we're not running, and if it comes back to what it was when we
4131 * were paused, we are not restarted.
4132 *
4133 * Implementation of the method from LauncherModel.Callbacks.
4134 *
4135 * @return true if we are currently paused. The caller might be able to
4136 * skip some work in that case since we will come back again.
4137 */
4138 public boolean setLoadOnResume() {
4139 if (mPaused) {
4140 Log.i(TAG, "setLoadOnResume");
4141 mOnResumeNeedsLoad = true;
4142 return true;
4143 } else {
4144 return false;
4145 }
4146 }
4147
4148 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004149 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004150 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004151 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004152 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004153 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004154 } else {
4155 return SCREEN_COUNT / 2;
4156 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004157 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004158
Joe Onorato9c1289c2009-08-17 11:03:03 -04004159 /**
4160 * Refreshes the shortcuts shown on the workspace.
4161 *
4162 * Implementation of the method from LauncherModel.Callbacks.
4163 */
4164 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004165 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004166
Michael Jurka7607c2f2013-04-03 14:33:19 -07004167 // If we're starting binding all over again, clear any bind calls we'd postponed in
4168 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4169 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004170 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004171
Winson Chungd64d1762013-08-20 14:37:16 -07004172 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004173 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004174 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004175
Michael Jurka05bf644e2011-11-30 20:28:53 -08004176 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004177 if (mHotseat != null) {
4178 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004179 }
4180 }
4181
Adam Cohendcd297f2013-06-18 13:13:40 -07004182 @Override
4183 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004184 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004185
Adam Cohen5084cba2013-09-03 12:01:16 -07004186 // If there are no screens, we need to have an empty screen
4187 if (orderedScreenIds.size() == 0) {
4188 mWorkspace.addExtraEmptyScreen();
4189 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004190
4191 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004192 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004193 if (hasCustomContentToLeft()) {
4194 mWorkspace.createCustomContentContainer();
4195 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004196 }
Winson Chung64359a52013-07-08 17:17:08 -07004197 }
4198
4199 @Override
4200 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004201 // Log to disk
4202 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4203 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4204 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004205 int count = orderedScreenIds.size();
4206 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004207 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004208 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004209 }
4210
Adam Cohen39a06042013-07-19 14:30:12 -07004211 private boolean shouldShowWeightWatcher() {
4212 String spKey = LauncherAppState.getSharedPreferencesKey();
4213 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07004214 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004215
4216 return show;
4217 }
4218
4219 private void toggleShowWeightWatcher() {
4220 String spKey = LauncherAppState.getSharedPreferencesKey();
4221 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4222 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4223
4224 show = !show;
4225
4226 SharedPreferences.Editor editor = sp.edit();
4227 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4228 editor.commit();
4229
4230 if (mWeightWatcher != null) {
4231 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4232 }
4233 }
4234
Winson Chungd64d1762013-08-20 14:37:16 -07004235 public void bindAppsAdded(final ArrayList<Long> newScreens,
4236 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004237 final ArrayList<ItemInfo> addAnimated,
4238 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004239 Runnable r = new Runnable() {
4240 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004241 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004242 }
4243 };
4244 if (waitUntilResume(r)) {
4245 return;
4246 }
4247
Winson Chungd64d1762013-08-20 14:37:16 -07004248 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004249 if (newScreens != null) {
4250 bindAddScreens(newScreens);
4251 }
Winson Chungd64d1762013-08-20 14:37:16 -07004252
4253 // We add the items without animation on non-visible pages, and with
4254 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004255 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004256 bindItems(addNotAnimated, 0,
4257 addNotAnimated.size(), false);
4258 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004259 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004260 bindItems(addAnimated, 0,
4261 addAnimated.size(), true);
4262 }
Winson Chungc58497e2013-09-03 17:48:37 -07004263
Winson Chung87412982013-10-03 18:34:14 -07004264 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004265 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004266
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004267 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004268 addedApps != null && mAppsCustomizeContent != null) {
4269 mAppsCustomizeContent.addApps(addedApps);
4270 }
Winson Chungd64d1762013-08-20 14:37:16 -07004271 }
4272
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004273 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004274 * Bind the items start-end from the list.
4275 *
4276 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004277 */
Winson Chung64359a52013-07-08 17:17:08 -07004278 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4279 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004280 Runnable r = new Runnable() {
4281 public void run() {
4282 bindItems(shortcuts, start, end, forceAnimateIcons);
4283 }
4284 };
4285 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004286 return;
4287 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004288
Winson Chungf0c6ae02012-03-21 16:10:31 -07004289 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004290 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4291 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004292 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004293 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004294 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004295 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004296 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004297
4298 // Short circuit if we are loading dock items for a configuration which has no dock
4299 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4300 mHotseat == null) {
4301 continue;
4302 }
4303
Joe Onorato9c1289c2009-08-17 11:03:03 -04004304 switch (item.itemType) {
4305 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4306 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004307 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004308 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004309
Winson Chung64359a52013-07-08 17:17:08 -07004310 /*
4311 * TODO: FIX collision case
4312 */
Winson Chungce376632013-07-11 16:12:41 -07004313 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4314 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4315 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004316 View v = cl.getChildAt(item.cellX, item.cellY);
4317 Object tag = v.getTag();
4318 String desc = "Collision while binding workspace item: " + item
4319 + ". Collides with " + tag;
4320 if (LauncherAppState.isDogfoodBuild()) {
4321 throw (new RuntimeException(desc));
4322 } else {
4323 Log.d(TAG, desc);
4324 }
Winson Chungce376632013-07-11 16:12:41 -07004325 }
Winson Chung64359a52013-07-08 17:17:08 -07004326 }
4327
Adam Cohendcd297f2013-06-18 13:13:40 -07004328 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4329 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004330 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004331 // Animate all the applications up now
4332 shortcut.setAlpha(0f);
4333 shortcut.setScaleX(0f);
4334 shortcut.setScaleY(0f);
4335 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004336 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004337 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004338 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004339 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004340 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004341 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004342 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004343 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4344 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004345 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004346 default:
4347 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004348 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004349 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004350
Winson Chung997a9232013-07-24 15:33:46 -07004351 if (animateIcons) {
4352 // Animate to the correct page
4353 if (newShortcutsScreenId > -1) {
4354 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004355 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004356 final Runnable startBounceAnimRunnable = new Runnable() {
4357 public void run() {
4358 anim.playTogether(bounceAnims);
4359 anim.start();
4360 }
4361 };
Winson Chung997a9232013-07-24 15:33:46 -07004362 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004363 // We post the animation slightly delayed to prevent slowdowns
4364 // when we are loading right after we return to launcher.
4365 mWorkspace.postDelayed(new Runnable() {
4366 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004367 if (mWorkspace != null) {
4368 mWorkspace.snapToPage(newScreenIndex);
4369 mWorkspace.postDelayed(startBounceAnimRunnable,
4370 NEW_APPS_ANIMATION_DELAY);
4371 }
Winson Chung94d67682013-09-25 16:29:40 -07004372 }
4373 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004374 } else {
4375 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004376 }
4377 }
Winson Chung64359a52013-07-08 17:17:08 -07004378 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004379 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004380 }
4381
Joe Onorato9c1289c2009-08-17 11:03:03 -04004382 /**
4383 * Implementation of the method from LauncherModel.Callbacks.
4384 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004385 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004386 Runnable r = new Runnable() {
4387 public void run() {
4388 bindFolders(folders);
4389 }
4390 };
4391 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004392 return;
4393 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004394 sFolders.clear();
4395 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004396 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004397
4398 /**
4399 * Add the views for a widget to the workspace.
4400 *
4401 * Implementation of the method from LauncherModel.Callbacks.
4402 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004403 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004404 Runnable r = new Runnable() {
4405 public void run() {
4406 bindAppWidget(item);
4407 }
4408 };
4409 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004410 return;
4411 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004412
Daniel Sandler843e8602010-06-07 14:59:01 -04004413 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4414 if (DEBUG_WIDGETS) {
4415 Log.d(TAG, "bindAppWidget: " + item);
4416 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004417 final Workspace workspace = mWorkspace;
4418
Sunny Goyalff572272014-07-23 13:58:07 -07004419 AppWidgetProviderInfo appWidgetInfo;
4420 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4421 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4422
4423 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4424 if (appWidgetInfo == null) {
4425 if (DEBUG_WIDGETS) {
4426 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4427 + " belongs to component " + item.providerName
4428 + ", as the povider is null");
4429 }
4430 LauncherModel.deleteItemFromDatabase(this, item);
4431 return;
4432 }
4433 // Note: This assumes that the id remap broadcast is received before this step.
4434 // If that is not the case, the id remap will be ignored and user may see the
4435 // click to setup view.
4436 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4437 pendingInfo.spanX = item.spanX;
4438 pendingInfo.spanY = item.spanY;
4439 pendingInfo.minSpanX = item.minSpanX;
4440 pendingInfo.minSpanY = item.minSpanY;
4441 Bundle options =
4442 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4443
4444 boolean success = false;
4445 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4446 if (options != null) {
4447 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4448 appWidgetInfo.provider, options);
4449 } else {
4450 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4451 appWidgetInfo.provider);
4452 }
4453
4454 // TODO consider showing a permission dialog when the widget is clicked.
4455 if (!success) {
4456 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4457 if (DEBUG_WIDGETS) {
4458 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4459 + " belongs to component " + item.providerName
4460 + ", as the launcher is unable to bing a new widget id");
4461 }
4462 LauncherModel.deleteItemFromDatabase(this, item);
4463 return;
4464 }
4465
4466 item.appWidgetId = newWidgetId;
4467
4468 // If the widget has a configure activity, it is still needs to set it up, otherwise
4469 // the widget is ready to go.
4470 item.restoreStatus = (appWidgetInfo.configure == null)
4471 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4472 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4473
4474 LauncherModel.updateItemInDatabase(this, item);
4475 }
4476
Sunny Goyal651077b2014-06-30 14:15:31 -07004477 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4478 final int appWidgetId = item.appWidgetId;
4479 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4480 if (DEBUG_WIDGETS) {
4481 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4482 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004483
Sunny Goyal651077b2014-06-30 14:15:31 -07004484 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4485 } else {
4486 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004487 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4488 view.updateIcon(mIconCache);
4489 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004490 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004491 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004492 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004493
Joe Onorato9c1289c2009-08-17 11:03:03 -04004494 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004495 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004496
Adam Cohendcd297f2013-06-18 13:13:40 -07004497 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004498 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004499 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4500
Joe Onorato9c1289c2009-08-17 11:03:03 -04004501 workspace.requestLayout();
4502
Daniel Sandler843e8602010-06-07 14:59:01 -04004503 if (DEBUG_WIDGETS) {
4504 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4505 + (SystemClock.uptimeMillis()-start) + "ms");
4506 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004507 }
4508
Sunny Goyalff572272014-07-23 13:58:07 -07004509 /**
4510 * Restores a pending widget.
4511 *
4512 * @param appWidgetId The app widget id
4513 * @param cellInfo The position on screen where to create the widget.
4514 */
4515 private void completeRestoreAppWidget(final int appWidgetId) {
4516 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4517 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4518 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4519 return;
4520 }
4521
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004522 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004523 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4524
4525 mWorkspace.reinflateWidgetsIfNecessary();
4526 LauncherModel.updateItemInDatabase(this, info);
4527 }
4528
Adam Cohen1462de32012-07-24 22:34:36 -07004529 public void onPageBoundSynchronously(int page) {
4530 mSynchronouslyBoundPages.add(page);
4531 }
4532
Joe Onorato9c1289c2009-08-17 11:03:03 -04004533 /**
4534 * Callback saying that there aren't any more items to bind.
4535 *
4536 * Implementation of the method from LauncherModel.Callbacks.
4537 */
Adam Cohene25af792013-06-06 23:08:25 -07004538 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004539 Runnable r = new Runnable() {
4540 public void run() {
4541 finishBindingItems(upgradePath);
4542 }
4543 };
4544 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004545 return;
4546 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004547 if (mSavedState != null) {
4548 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004549 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004550 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004551 mSavedState = null;
4552 }
4553
Adam Cohen1462de32012-07-24 22:34:36 -07004554 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004555
Winson Chungc51db6a2011-10-05 11:44:49 -07004556 // Update the market app icon as necessary (the other icons will be managed in response to
4557 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004558 if (!DISABLE_MARKET_BUTTON) {
4559 updateAppMarketIcon();
4560 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004561
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004562 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004563 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004564
4565 // If we received the result of any pending adds while the loader was running (e.g. the
4566 // widget configuration forced an orientation change), process them now.
4567 if (sPendingAddItem != null) {
4568 final long screenId = completeAdd(sPendingAddItem);
4569
4570 // TODO: this moves the user to the page where the pending item was added. Ideally,
4571 // the screen would be guaranteed to exist after bind, and the page would be set through
4572 // the workspace restore process.
4573 mWorkspace.post(new Runnable() {
4574 @Override
4575 public void run() {
4576 mWorkspace.snapToScreenId(screenId);
4577 }
4578 });
4579 sPendingAddItem = null;
4580 }
4581
Adam Cohene25af792013-06-06 23:08:25 -07004582 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004583 mWorkspace.getUniqueComponents(true, null);
4584 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004585 }
Sunny Goyale755d462014-07-22 13:48:29 -07004586 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004587 }
4588
Adam Cohen3ed316a2014-07-23 18:21:20 -07004589 private void sendLoadingCompleteBroadcastIfNecessary() {
4590 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4591 String permission =
4592 getResources().getString(R.string.receive_first_load_broadcast_permission);
4593 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4594 sendBroadcast(intent, permission);
4595 SharedPreferences.Editor editor = mSharedPrefs.edit();
4596 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4597 editor.apply();
4598 }
4599 }
4600
Winson Chunga0b7e862013-09-05 16:03:15 -07004601 public boolean isAllAppsButtonRank(int rank) {
4602 if (mHotseat != null) {
4603 return mHotseat.isAllAppsButtonRank(rank);
4604 }
4605 return false;
4606 }
4607
Winson Chunga2413752012-04-03 14:22:34 -07004608 private boolean canRunNewAppsAnimation() {
4609 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4610 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4611 }
4612
Winson Chungc9168342013-06-26 14:54:55 -07004613 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4614 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4615 PropertyValuesHolder.ofFloat("alpha", 1f),
4616 PropertyValuesHolder.ofFloat("scaleX", 1f),
4617 PropertyValuesHolder.ofFloat("scaleY", 1f));
4618 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4619 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4620 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4621 return bounceAnim;
4622 }
4623
Adam Cohen27772732013-11-11 14:00:56 +00004624 public boolean useVerticalBarLayout() {
4625 return LauncherAppState.getInstance().getDynamicGrid().
4626 getDeviceProfile().isVerticalBarLayout();
4627 }
4628
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004629 protected Rect getSearchBarBounds() {
4630 return LauncherAppState.getInstance().getDynamicGrid().
4631 getDeviceProfile().getSearchBarBounds();
4632 }
4633
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004634 @Override
4635 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004636 boolean searchVisible = updateGlobalSearchIcon();
4637 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004638 if (mSearchDropTargetBar != null) {
4639 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4640 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004641 }
4642
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004643 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004644 * Add the icons for all apps.
4645 *
4646 * Implementation of the method from LauncherModel.Callbacks.
4647 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004648 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004649 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004650 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4651 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4652 getHotseat().addAllAppsFolder(mIconCache, apps,
4653 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4654 }
4655 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004656 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004657 if (mAppsCustomizeContent != null) {
4658 mAppsCustomizeContent.onPackagesUpdated(
4659 LauncherModel.getSortedWidgetsAndShortcuts(this));
4660 }
Winson Chungc58497e2013-09-03 17:48:37 -07004661 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004662 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004663 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004664 mAppsCustomizeContent.onPackagesUpdated(
4665 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004666 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004667 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004668 }
4669
4670 /**
4671 * A package was updated.
4672 *
4673 * Implementation of the method from LauncherModel.Callbacks.
4674 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004675 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004676 Runnable r = new Runnable() {
4677 public void run() {
4678 bindAppsUpdated(apps);
4679 }
4680 };
4681 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004682 return;
4683 }
4684
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004685 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004686 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004687 }
Winson Chungc58497e2013-09-03 17:48:37 -07004688
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004689 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004690 mAppsCustomizeContent != null) {
4691 mAppsCustomizeContent.updateApps(apps);
4692 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004693 }
4694
4695 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004696 * Update the state of a package, typically related to install state.
4697 *
4698 * Implementation of the method from LauncherModel.Callbacks.
4699 */
Sunny Goyale755d462014-07-22 13:48:29 -07004700 @Override
4701 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004702 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004703 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004704 }
4705 }
4706
4707 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004708 * A package was uninstalled. We take both the super set of packageNames
4709 * in addition to specific applications to remove, the reason being that
4710 * this can be called when a package is updated as well. In that scenario,
4711 * we only remove specific components from the workspace, where as
4712 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004713 *
4714 * Implementation of the method from LauncherModel.Callbacks.
4715 */
Winson Chung83892cc2013-05-01 16:53:33 -07004716 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004717 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004718 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004719 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004720 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004721 }
Winson Chungd64d1762013-08-20 14:37:16 -07004722 };
4723 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004724 return;
4725 }
4726
Winson Chungdf95eb12013-10-16 14:57:07 -07004727 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004728 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004729 }
4730 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004731 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004732 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004733
Winson Chunga1820962011-10-03 16:31:06 -07004734 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004735 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004736
Winson Chungdf95eb12013-10-16 14:57:07 -07004737 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004738 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004739 mAppsCustomizeContent != null) {
4740 mAppsCustomizeContent.removeApps(appInfos);
4741 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004742 }
Joe Onoratobe386092009-11-17 17:32:16 -08004743
4744 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004745 * A number of packages were updated.
4746 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004747 private ArrayList<Object> mWidgetsAndShortcuts;
4748 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004749 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004750 bindPackagesUpdated(mWidgetsAndShortcuts);
4751 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004752 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004753 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004754 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4755 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4756 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004757 return;
4758 }
4759
Winson Chung64359a52013-07-08 17:17:08 -07004760 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004761 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004762 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004763 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004764 }
4765
Winson Chung400438b2011-01-16 17:53:48 -08004766 private int mapConfigurationOriActivityInfoOri(int configOri) {
4767 final Display d = getWindowManager().getDefaultDisplay();
4768 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4769 switch (d.getRotation()) {
4770 case Surface.ROTATION_0:
4771 case Surface.ROTATION_180:
4772 // We are currently in the same basic orientation as the natural orientation
4773 naturalOri = configOri;
4774 break;
4775 case Surface.ROTATION_90:
4776 case Surface.ROTATION_270:
4777 // We are currently in the other basic orientation to the natural orientation
4778 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4779 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4780 break;
4781 }
4782
4783 int[] oriMap = {
4784 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4785 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4786 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4787 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4788 };
4789 // Since the map starts at portrait, we need to offset if this device's natural orientation
4790 // is landscape.
4791 int indexOffset = 0;
4792 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4793 indexOffset = 1;
4794 }
4795 return oriMap[(d.getRotation() + indexOffset) % 4];
4796 }
Adam Cohen446e9402011-09-15 18:21:21 -07004797
Winson Chung4b919f82012-05-01 10:44:08 -07004798 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004799 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004800 getResources().getBoolean(R.bool.allow_rotation);
4801 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004802 }
Winson Chung4b919f82012-05-01 10:44:08 -07004803 public void lockScreenOrientation() {
4804 if (isRotationEnabled()) {
4805 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4806 .getConfiguration().orientation));
4807 }
4808 }
4809 public void unlockScreenOrientation(boolean immediate) {
4810 if (isRotationEnabled()) {
4811 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004812 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004813 } else {
4814 mHandler.postDelayed(new Runnable() {
4815 public void run() {
4816 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4817 }
4818 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004819 }
Winson Chung4b919f82012-05-01 10:44:08 -07004820 }
Winson Chung400438b2011-01-16 17:53:48 -08004821 }
4822
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004823 /**
4824 * Called when the SearchBar hint should be changed.
4825 *
4826 * @param hint the hint to be displayed in the search bar.
4827 */
4828 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004829 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004830 }
4831
Winson Chunge43a1e72014-01-15 10:33:02 -08004832 protected boolean isLauncherPreinstalled() {
4833 PackageManager pm = getPackageManager();
4834 try {
4835 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4836 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4837 return true;
4838 } else {
4839 return false;
4840 }
4841 } catch (NameNotFoundException e) {
4842 e.printStackTrace();
4843 return false;
4844 }
4845 }
4846
Adam Cohenea90f832014-05-21 15:03:34 -07004847 /**
4848 * This method indicates whether or not we should suggest default wallpaper dimensions
4849 * when our wallpaper cropper was not yet used to set a wallpaper.
4850 */
4851 protected boolean overrideWallpaperDimensions() {
4852 return true;
4853 }
4854
Adam Cohen5eed5d82014-05-19 13:12:13 -07004855 protected boolean shouldClingFocusHotseatApp() {
4856 return false;
4857 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004858 protected String getFirstRunClingSearchBarHint() {
4859 return "";
4860 }
4861 protected String getFirstRunCustomContentHint() {
4862 return "";
4863 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004864 protected int getFirstRunFocusedHotseatAppDrawableId() {
4865 return -1;
4866 }
4867 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4868 return null;
4869 }
4870 protected int getFirstRunFocusedHotseatAppRank() {
4871 return -1;
4872 }
4873 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4874 return "";
4875 }
4876 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4877 return "";
4878 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004879
Winson Chungaf40f202013-09-18 18:26:31 -07004880 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004881 mLauncherClings.dismissFirstRunCling(v);
4882 }
4883 public void dismissMigrationClingCopyApps(View v) {
4884 mLauncherClings.dismissMigrationClingCopyApps(v);
4885 }
4886 public void dismissMigrationClingUseDefault(View v) {
4887 mLauncherClings.dismissMigrationClingUseDefault(v);
4888 }
4889 public void dismissMigrationWorkspaceCling(View v) {
4890 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004891 }
Winson Chung82f55532011-08-09 14:14:23 -07004892 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004893 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004894 }
4895 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004896 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004897 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004898 public void markFolderClingDismissedIfNecessary() {
4899 mLauncherClings.markFolderClingDismissedIfNecessary();
4900 }
Adam Cohen432609a2014-03-13 17:03:22 -07004901
4902 /**
4903 * To be overridden by subclasses to indicate that there is an activity to launch
4904 * before showing the standard launcher experience.
4905 */
4906 protected boolean hasFirstRunActivity() {
4907 return false;
4908 }
4909
4910 /**
4911 * To be overridden by subclasses to launch any first run activity
4912 */
4913 protected Intent getFirstRunActivity() {
4914 return null;
4915 }
4916
Winson Chunga6945242014-01-08 14:04:34 -08004917 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004918 return !ActivityManager.isRunningInTestHarness() &&
4919 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004920 }
4921
Adam Cohen4a9423d2014-03-28 14:22:31 -07004922 protected boolean hasRunFirstRunActivity() {
4923 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4924 }
4925
Adam Cohen432609a2014-03-13 17:03:22 -07004926 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004927 if (shouldRunFirstRunActivity() &&
4928 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004929 Intent firstRunIntent = getFirstRunActivity();
4930 if (firstRunIntent != null) {
4931 startActivity(firstRunIntent);
4932 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004933 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004934 }
4935 }
Adam Cohen432609a2014-03-13 17:03:22 -07004936 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004937 }
4938
4939 private void markFirstRunActivityShown() {
4940 SharedPreferences.Editor editor = mSharedPrefs.edit();
4941 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4942 editor.apply();
4943 }
4944
Adam Cohen432609a2014-03-13 17:03:22 -07004945 /**
4946 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4947 * screen that must be displayed and dismissed.
4948 */
4949 protected boolean hasDismissableIntroScreen() {
4950 return false;
4951 }
4952
4953 /**
4954 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4955 */
4956 protected View getIntroScreen() {
4957 return null;
4958 }
4959
4960 /**
4961 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4962 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4963 */
4964 private boolean shouldShowIntroScreen() {
4965 return hasDismissableIntroScreen() &&
4966 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4967 }
4968
4969 protected void showIntroScreen() {
4970 View introScreen = getIntroScreen();
4971 changeWallpaperVisiblity(false);
4972 if (introScreen != null) {
4973 mDragLayer.showOverlayView(introScreen);
4974 }
4975 }
4976
4977 public void dismissIntroScreen() {
4978 markIntroScreenDismissed();
4979 if (showFirstRunActivity()) {
4980 // We delay hiding the intro view until the first run activity is showing. This
4981 // avoids a blip.
4982 mWorkspace.postDelayed(new Runnable() {
4983 @Override
4984 public void run() {
4985 mDragLayer.dismissOverlayView();
4986 }
4987 }, ACTIVITY_START_DELAY);
4988 } else {
4989 mDragLayer.dismissOverlayView();
4990 }
4991 changeWallpaperVisiblity(true);
4992 }
4993
4994 private void markIntroScreenDismissed() {
4995 SharedPreferences.Editor editor = mSharedPrefs.edit();
4996 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4997 editor.apply();
4998 }
4999
Winson Chunga6945242014-01-08 14:04:34 -08005000 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005001 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5002 if (mHotseat != null) mHotseat.setAlpha(1f);
5003 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5004 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005005 }
5006
5007 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005008 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5009 if (mHotseat != null) mHotseat.setAlpha(0f);
5010 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5011 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005012 }
5013
Mathew Inwood72fbec12013-11-19 15:45:07 +00005014 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01005015 // Called from search suggestion, not supported in other profiles.
5016 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5017 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5018 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5019 myUser);
5020 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00005021 return null;
5022 }
Kenny Guyed131872014-04-30 03:02:21 +01005023 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005024 }
5025
5026 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5027 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01005028 // Called from search suggestion, not supported in other profiles.
5029 return createShortcutDragInfo(shortcutIntent, caption, icon,
5030 UserHandleCompat.myUserHandle());
5031 }
5032
5033 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5034 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01005035 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01005036 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01005037 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005038 }
5039
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005040 protected void moveWorkspaceToDefaultScreen() {
5041 mWorkspace.moveToDefaultScreen(false);
5042 }
5043
Mathew Inwood72fbec12013-11-19 15:45:07 +00005044 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5045 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005046 mWorkspace.onExternalDragStartedWithItem(dragView);
5047 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005048 }
5049
Anjali Koppalf5d29132014-02-28 13:33:27 -08005050 @Override
5051 public void onPageSwitch(View newPage, int newPageIndex) {
5052 }
5053
Winson Chung80baf5a2010-08-09 16:03:15 -07005054 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005055 * Prints out out state for debugging.
5056 */
5057 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005058 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005059 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005060 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5061 Log.d(TAG, "mRestoring=" + mRestoring);
5062 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5063 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005064 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005065 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005066
Winson Chung785d2eb2011-04-14 16:08:02 -07005067 if (mAppsCustomizeContent != null) {
5068 mAppsCustomizeContent.dumpState();
5069 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005070 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005071 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005072
5073 @Override
5074 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5075 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005076 synchronized (sDumpLogs) {
5077 writer.println(" ");
5078 writer.println("Debug logs: ");
5079 for (int i = 0; i < sDumpLogs.size(); i++) {
5080 writer.println(" " + sDumpLogs.get(i));
5081 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005082 }
5083 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005084
5085 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005086 if (DEBUG_DUMP_LOG) {
5087 synchronized (sDumpLogs) {
5088 Log.d(TAG, "");
5089 Log.d(TAG, "*********************");
5090 Log.d(TAG, "Launcher debug logs: ");
5091 for (int i = 0; i < sDumpLogs.size(); i++) {
5092 Log.d(TAG, " " + sDumpLogs.get(i));
5093 }
5094 Log.d(TAG, "*********************");
5095 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005096 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005097 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005098 }
5099
5100 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005101 addDumpLog(tag, log, null, debugLog);
5102 }
5103
5104 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005105 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005106 if (e != null) {
5107 Log.d(tag, log, e);
5108 } else {
5109 Log.d(tag, log);
5110 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005111 }
Winson Chungede41292013-09-19 16:27:36 -07005112 if (DEBUG_DUMP_LOG) {
5113 sDateStamp.setTime(System.currentTimeMillis());
5114 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005115 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5116 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005117 }
Winson Chungede41292013-09-19 16:27:36 -07005118 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005119 }
5120
Winson Chungede41292013-09-19 16:27:36 -07005121 public void dumpLogsToLocalData() {
5122 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005123 new AsyncTask<Void, Void, Void>() {
5124 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005125 boolean success = false;
5126 sDateStamp.setTime(sRunStart);
5127 String FILENAME = sDateStamp.getMonth() + "-"
5128 + sDateStamp.getDay() + "_"
5129 + sDateStamp.getHours() + "-"
5130 + sDateStamp.getMinutes() + "_"
5131 + sDateStamp.getSeconds() + ".txt";
5132
5133 FileOutputStream fos = null;
5134 File outFile = null;
5135 try {
5136 outFile = new File(getFilesDir(), FILENAME);
5137 outFile.createNewFile();
5138 fos = new FileOutputStream(outFile);
5139 } catch (Exception e) {
5140 e.printStackTrace();
5141 }
5142 if (fos != null) {
5143 PrintWriter writer = new PrintWriter(fos);
5144
5145 writer.println(" ");
5146 writer.println("Debug logs: ");
5147 synchronized (sDumpLogs) {
5148 for (int i = 0; i < sDumpLogs.size(); i++) {
5149 writer.println(" " + sDumpLogs.get(i));
5150 }
5151 }
5152 writer.close();
5153 }
5154 try {
5155 if (fos != null) {
5156 fos.close();
5157 success = true;
5158 }
5159 } catch (IOException e) {
5160 e.printStackTrace();
5161 }
Michael Jurka43467462013-11-14 12:03:58 +01005162 return null;
Winson Chungede41292013-09-19 16:27:36 -07005163 }
Michael Jurka43467462013-11-14 12:03:58 +01005164 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005165 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005166 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005167}
Michael Jurka2763be32011-02-24 11:19:57 -08005168
Michael Jurkaabded662011-03-04 12:06:57 -08005169interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005170 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005171 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005172 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005173 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005174 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005175}
Dan Sandlerd5024042014-01-09 15:01:33 -05005176
5177interface DebugIntents {
5178 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5179 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005180}