blob: 90856084ce0912baa205fbb3827e8d2ff99c960a [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080026import android.animation.ValueAnimator.AnimatorUpdateListener;
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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080036import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040037import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080038import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070041import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070042import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070043import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080044import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070046import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070048import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080049import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070050import android.graphics.Bitmap;
51import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070052import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070053import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070054import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040057import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070058import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020060import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080061import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070062import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070063import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040064import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080066import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.text.Selection;
68import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070069import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070071import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070073import android.view.Display;
74import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
76import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070079import android.view.MotionEvent;
80import android.view.Surface;
81import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070082import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080083import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070084import android.view.ViewGroup;
85import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080086import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070089import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080090import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.widget.Advanceable;
93import android.widget.FrameLayout;
94import android.widget.ImageView;
95import android.widget.TextView;
96import android.widget.Toast;
Kenny Guyed131872014-04-30 03:02:21 +010097import com.android.launcher3.compat.LauncherActivityInfoCompat;
98import com.android.launcher3.compat.LauncherAppsCompat;
99import com.android.launcher3.compat.UserHandleCompat;
100import com.android.launcher3.compat.UserManagerCompat;
Daniel Sandler325dc232013-06-05 22:57:57 -0400101import com.android.launcher3.DropTarget.DragObject;
Anjali Koppalf5d29132014-02-28 13:33:27 -0800102import com.android.launcher3.PagedView.PageSwitchListener;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700103import java.io.DataInputStream;
104import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700105import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700106import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700110import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700111import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700112import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700113import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700114import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700116import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000117import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700118
Winson Chunga6945242014-01-08 14:04:34 -0800119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700125 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
Dan Sandlerd5024042014-01-09 15:01:33 -0500135 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
136
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700138 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700140 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700141 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
Michael Jurka8b805b12012-04-18 14:23:14 -0700143 private static final int REQUEST_BIND_APPWIDGET = 11;
144
Mathew Inwood876a8462013-06-14 14:12:41 +0100145 /**
146 * IntentStarter uses request codes starting with this. This must be greater than all activity
147 * request codes used internally.
148 */
149 protected static final int REQUEST_LAST = 100;
150
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
152
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800153 static final int SCREEN_COUNT = 5;
154 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155
Romain Guy98d01652009-06-30 16:21:04 -0700156 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800157 // To turn on these properties, type
158 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
159 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
160 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800161 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162
Winson Chung2672ff92012-05-04 16:22:30 -0700163 // The Intent extra that defines whether to ignore the launch animation
164 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400165 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700166
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 // Type: int
168 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700169 // Type: int
170 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700172 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
173 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700178 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 // Type: boolean
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
181 // Type: long
182 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
185 // Type: int
186 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
187 // Type: parcelable
188 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000189 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800190 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000191 // Type: int[]
192 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193
Adam Cohenb54a5982014-01-08 15:21:04 -0800194
Adam Cohen432609a2014-03-13 17:03:22 -0700195 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800196 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
197
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100198 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700199 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100200 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700201 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100202 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700203
Adam Cohen39a06042013-07-19 14:30:12 -0700204 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700205 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700206
Winson Chunga6945242014-01-08 14:04:34 -0800207 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
208
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700209 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700210 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700211 private State mState = State.WORKSPACE;
212 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700213
Joe Onorato9c1289c2009-08-17 11:03:03 -0400214 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700215 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
216 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700217 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800220 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000222 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
223 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
224
Winson Chunga2413752012-04-03 14:22:34 -0700225 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700226 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
227 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700228 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700229
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800230 private final BroadcastReceiver mCloseSystemDialogsReceiver
231 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800232 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
233
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 private LayoutInflater mInflater;
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700237 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800238 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800239 private DragLayer mDragLayer;
240 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700241 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800242 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700243
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700244 private AppWidgetManager mAppWidgetManager;
245 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700246
Michael Jurkac9d95c52011-08-29 14:03:34 -0700247 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700248 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800249 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700250
Michael Jurka0280c3b2010-09-17 15:00:07 -0700251 private int[] mTmpAddItemCellCoordinates = new int[2];
252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private FolderInfo mFolderInfo;
254
Winson Chung3d503fb2011-07-13 17:25:49 -0700255 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800256 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700257
Michael Jurka838a4ca2011-02-07 13:33:06 -0800258 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700259
Winson Chungc51db6a2011-10-05 11:44:49 -0700260 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700261 private AppsCustomizeTabHost mAppsCustomizeTabHost;
262 private AppsCustomizePagedView mAppsCustomizeContent;
263 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800264 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700267 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
268 // scroll issues (because the workspace may not have been measured yet) and extra work.
269 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
270 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271
272 private SpannableStringBuilder mDefaultKeySsb = null;
273
Joe Onorato9c1289c2009-08-17 11:03:03 -0400274 private boolean mWorkspaceLoading = true;
275
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800276 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 private boolean mRestoring;
278 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700279 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280
Michael Jurka1e2f4652013-07-08 18:03:46 -0700281 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700282 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
283
Winson Chung4a2afa32012-07-19 14:53:05 -0700284 // Keep track of whether the user has left launcher
285 private static boolean sPausedFromUserAction = false;
286
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287 private Bundle mSavedInstanceState;
288
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800290 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800291 private boolean mUserPresent = true;
292 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700293 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800294 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400295
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700296 private static LocaleConfiguration sLocaleConfiguration = null;
297
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700298 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700299
Adam Cohen61f560d2013-09-30 15:58:20 -0700300 private View.OnTouchListener mHapticFeedbackTouchListener;
301
Adam Cohended9f8d2010-11-03 13:25:16 -0700302 // Related to the auto-advancing of widgets
303 private final int ADVANCE_MSG = 1;
304 private final int mAdvanceInterval = 20000;
305 private final int mAdvanceStagger = 250;
306 private long mAutoAdvanceSentTime;
307 private long mAutoAdvanceTimeLeft = -1;
308 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
309 new HashMap<View, AppWidgetProviderInfo>();
310
Winson Chung400438b2011-01-16 17:53:48 -0800311 // Determines how long to wait after a rotation before restoring the screen orientation to
312 // match the sensor state.
313 private final int mRestoreScreenOrientationDelay = 500;
314
Michael Jurka4ef207b2010-11-29 17:05:45 -0800315 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700316 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
317 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
318 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800319
Winson Chungd64a6662013-09-30 11:06:59 -0700320 private Intent mAppMarketIntent = null;
321 private static final boolean DISABLE_MARKET_BUTTON = true;
322
Craig Mautner360310b2012-10-26 15:13:08 -0700323 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700324
Adam Cohen1462de32012-07-24 22:34:36 -0700325 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700326 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700327
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700328 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700329 static Date sDateStamp = new Date();
330 static DateFormat sDateFormat =
331 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
332 static long sRunStart = System.currentTimeMillis();
333 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700334
Winson Chung46353de2012-02-16 14:05:10 -0800335 // We only want to get the SharedPreferences once since it does an FS stat each time we get
336 // it from the context.
337 private SharedPreferences mSharedPrefs;
338
Adam Cohene25af792013-06-06 23:08:25 -0700339 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
340
Winson Chungf0c6ae02012-03-21 16:10:31 -0700341 // Holds the page that we need to animate to, and the icon views that we need to animate up
342 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700343 private ImageView mFolderIconImageView;
344 private Bitmap mFolderIconBitmap;
345 private Canvas mFolderIconCanvas;
346 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700347
Michael Jurkaddd62e92011-02-16 17:49:14 -0800348 private BubbleTextView mWaitingForResume;
349
Michael Jurkac1f5d262011-09-30 19:32:27 -0700350 private Runnable mBuildLayersRunnable = new Runnable() {
351 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700352 if (mWorkspace != null) {
353 mWorkspace.buildPageHardwareLayers();
354 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700355 }
356 };
357
Adam Cohendb364c32014-05-20 14:23:40 -0700358 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800359
Michael Jurka7267fa52013-09-26 15:29:57 -0700360 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800361
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800362 private static class PendingAddArguments {
363 int requestCode;
364 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700365 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700366 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800367 int cellX;
368 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700369 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800370 }
371
Daniel Sandlerff02d492013-08-05 02:12:05 -0400372 private Stats mStats;
373
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800374 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800375 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700376 }
377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 @Override
379 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700380 if (DEBUG_STRICT_MODE) {
381 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
382 .detectDiskReads()
383 .detectDiskWrites()
384 .detectNetwork() // or .detectAll() for all detectable problems
385 .penaltyLog()
386 .build());
387 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
388 .detectLeakedSqlLiteObjects()
389 .detectLeakedClosableObjects()
390 .penaltyLog()
391 .penaltyDeath()
392 .build());
393 }
394
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800395 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400396
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400397 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400398 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700399 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700400 // Determine the dynamic grid properties
401 Point smallestSize = new Point();
402 Point largestSize = new Point();
403 Point realSize = new Point();
404 Display display = getWindowManager().getDefaultDisplay();
405 display.getCurrentSizeRange(smallestSize, largestSize);
406 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700407 DisplayMetrics dm = new DisplayMetrics();
408 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700409
Winson Chung5f8afe62013-08-12 16:19:28 -0700410 // Lazy-initialize the dynamic grid
411 DeviceProfile grid = app.initDynamicGrid(this,
412 Math.min(smallestSize.x, smallestSize.y),
413 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700414 realSize.x, realSize.y,
415 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700416
417 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400418 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700419 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800420 mModel = app.setLauncher(this);
421 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700422 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400423 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800424 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700426
Daniel Sandlerff02d492013-08-05 02:12:05 -0400427 mStats = new Stats(this);
428
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700429 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700430
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700431 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
432 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700433
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700434 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
435 // this also ensures that any synchronous binding below doesn't re-trigger another
436 // LauncherModel load.
437 mPaused = false;
438
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200440 android.os.Debug.startMethodTracing(
441 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 }
443
Adam Cohen53805212013-10-01 10:39:23 -0700444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700447
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100449 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800451 registerContentObservers();
452
Joe Onorato7c312c12009-08-13 21:36:53 -0700453 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700454
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 mSavedState = savedInstanceState;
456 restoreState(mSavedState);
457
458 if (PROFILE_STARTUP) {
459 android.os.Debug.stopMethodTracing();
460 }
461
462 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700463 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700464 // If the user leaves launcher, then we should just load items asynchronously when
465 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500466 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700467 } else {
468 // We only load the page synchronously if the user rotates (or triggers a
469 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800470 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700471 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800472 }
473
474 // For handling default keys
475 mDefaultKeySsb = new SpannableStringBuilder();
476 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800477
478 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
479 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800480
Adam Cohenf9426d52012-06-04 17:26:21 -0700481 updateGlobalIcons();
482
483 // On large interfaces, we want the screen to auto-rotate based on the current orientation
484 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700485
Adam Cohen432609a2014-03-13 17:03:22 -0700486 if (shouldShowIntroScreen()) {
487 showIntroScreen();
488 } else {
489 showFirstRunActivity();
490 }
491
Winson Chunge43a1e72014-01-15 10:33:02 -0800492 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
493 // on the device, then we always show the first run cling experience (or if there is no
494 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800495 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
496 if (mModel.canMigrateFromOldLauncherDb(this)) {
497 mLauncherClings.showMigrationCling();
498 } else {
499 mLauncherClings.showFirstRunCling();
500 }
Winson Chunga6945242014-01-08 14:04:34 -0800501 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800502 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800503 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700504 }
505
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700506 @Override
507 public void onLauncherProviderChange() { }
508
Winson Chung4a2afa32012-07-19 14:53:05 -0700509 protected void onUserLeaveHint() {
510 super.onUserLeaveHint();
511 sPausedFromUserAction = true;
512 }
513
Winson Chung98ca0f72013-07-29 12:58:51 -0700514 /** To be overriden by subclasses to hint to Launcher that we have custom content */
515 protected boolean hasCustomContentToLeft() {
516 return false;
517 }
518
Dave Hawkeya8881582013-09-17 15:55:33 -0600519 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500520 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600521 * {@link #addToCustomContentPage}. This will only be invoked if
522 * {@link #hasCustomContentToLeft()} is {@code true}.
523 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500524 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600525 }
526
527 /**
528 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
529 * ensure the custom content page is added or removed if necessary.
530 */
531 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600532 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600533 // Not bound yet, wait for bindScreens to be called.
534 return;
535 }
536
537 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
538 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500539 mWorkspace.createCustomContentContainer();
540 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600541 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
542 mWorkspace.removeCustomContentPage();
543 }
544 }
545
Adam Cohenf9426d52012-06-04 17:26:21 -0700546 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700547 boolean searchVisible = false;
548 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800549 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700550 int coi = getCurrentOrientationIndexForGlobalIcons();
551 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
552 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700553 if (!DISABLE_MARKET_BUTTON) {
554 updateAppMarketIcon();
555 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700556 searchVisible = updateGlobalSearchIcon();
557 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700558 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700559 if (sGlobalSearchIcon[coi] != null) {
560 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700561 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700562 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700563 if (sVoiceSearchIcon[coi] != null) {
564 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700565 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700566 }
Winson Chungd64a6662013-09-30 11:06:59 -0700567 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700568 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800569 }
Winson Chungadf0c182012-08-23 14:59:07 -0700570 if (mSearchDropTargetBar != null) {
571 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
572 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 }
Romain Guycbb89e42009-06-08 15:52:54 -0700574
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 if (sLocaleConfiguration == null) {
577 new AsyncTask<Void, Void, LocaleConfiguration>() {
578 @Override
579 protected LocaleConfiguration doInBackground(Void... unused) {
580 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
581 readConfiguration(Launcher.this, localeConfiguration);
582 return localeConfiguration;
583 }
584
585 @Override
586 protected void onPostExecute(LocaleConfiguration result) {
587 sLocaleConfiguration = result;
588 checkForLocaleChange(); // recursive, but now with a locale configuration
589 }
590 }.execute();
591 return;
592 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700593
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594 final Configuration configuration = getResources().getConfiguration();
595
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700596 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 final String locale = configuration.locale.toString();
598
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700599 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800600 final int mcc = configuration.mcc;
601
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final int mnc = configuration.mnc;
604
Romain Guy84f296c2009-11-04 15:00:44 -0800605 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606
Romain Guy84f296c2009-11-04 15:00:44 -0800607 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 sLocaleConfiguration.locale = locale;
609 sLocaleConfiguration.mcc = mcc;
610 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700611
Joe Onorato0589f0f2010-02-08 13:44:00 -0800612 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613
614 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100615 new AsyncTask<Void, Void, Void>() {
616 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100618 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700619 }
Michael Jurka43467462013-11-14 12:03:58 +0100620 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700621 }
622 }
623
624 private static class LocaleConfiguration {
625 public String locale;
626 public int mcc = -1;
627 public int mnc = -1;
628 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700629
Romain Guy98d01652009-06-30 16:21:04 -0700630 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
631 DataInputStream in = null;
632 try {
633 in = new DataInputStream(context.openFileInput(PREFERENCES));
634 configuration.locale = in.readUTF();
635 configuration.mcc = in.readInt();
636 configuration.mnc = in.readInt();
637 } catch (FileNotFoundException e) {
638 // Ignore
639 } catch (IOException e) {
640 // Ignore
641 } finally {
642 if (in != null) {
643 try {
644 in.close();
645 } catch (IOException e) {
646 // Ignore
647 }
648 }
649 }
650 }
651
652 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
653 DataOutputStream out = null;
654 try {
655 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
656 out.writeUTF(configuration.locale);
657 out.writeInt(configuration.mcc);
658 out.writeInt(configuration.mnc);
659 out.flush();
660 } catch (FileNotFoundException e) {
661 // Ignore
662 } catch (IOException e) {
663 //noinspection ResultOfMethodCallIgnored
664 context.getFileStreamPath(PREFERENCES).delete();
665 } finally {
666 if (out != null) {
667 try {
668 out.close();
669 } catch (IOException e) {
670 // Ignore
671 }
672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674 }
675
Anton Hanssona2f665f2013-09-26 12:18:32 +0100676 public Stats getStats() {
677 return mStats;
678 }
679
Bjorn Bringertc459e522013-06-07 19:36:01 +0100680 public LayoutInflater getInflater() {
681 return mInflater;
682 }
683
Winson Chung36a62fe2012-05-06 18:04:42 -0700684 boolean isDraggingEnabled() {
685 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
686 // that is subsequently removed from the workspace in startBinding().
687 return !mModel.isLoadingWorkspace();
688 }
689
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 static int getScreen() {
691 synchronized (sLock) {
692 return sScreen;
693 }
694 }
695
696 static void setScreen(int screen) {
697 synchronized (sLock) {
698 sScreen = screen;
699 }
700 }
701
Winson Chung557d6ed2011-07-08 15:34:52 -0700702 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000703 * Copied from View -- the View version of the method isn't called
704 * anywhere else in our process and only exists for API level 17+,
705 * so it's ok to keep our own version with no API requirement.
706 */
707 public static int generateViewId() {
708 for (;;) {
709 final int result = sNextGeneratedId.get();
710 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
711 int newValue = result + 1;
712 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
713 if (sNextGeneratedId.compareAndSet(result, newValue)) {
714 return result;
715 }
716 }
717 }
718
719 public int getViewIdForItem(ItemInfo info) {
720 // This cast is safe given the > 2B range for int.
721 int itemId = (int) info.id;
722 if (mItemIdToViewId.containsKey(itemId)) {
723 return mItemIdToViewId.get(itemId);
724 }
725 int viewId = generateViewId();
726 mItemIdToViewId.put(itemId, viewId);
727 return viewId;
728 }
729
730 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700731 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
732 * a configuration step, this allows the proper animations to run after other transitions.
733 */
Adam Cohendb364c32014-05-20 14:23:40 -0700734 private long completeAdd(PendingAddArguments args) {
735
736 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700739 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700740 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700741 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700743 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700744 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800745 }
Michael Jurka27614d22012-04-02 06:40:22 -0700746 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
747 // if you turned the screen off and then back while in All Apps, Launcher would not
748 // return to the workspace. Clearing mAddInfo.container here fixes this issue
749 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700750 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800751 }
752
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800753 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700754 protected void onActivityResult(
755 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700756 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700757 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700758 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800759 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700760
Adam Cohenad4e15c2013-10-17 16:21:35 -0700761 Runnable exitSpringLoaded = new Runnable() {
762 @Override
763 public void run() {
764 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
765 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
766 }
767 };
768
Michael Jurka8b805b12012-04-18 14:23:14 -0700769 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700770 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700771 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
772 if (resultCode == RESULT_CANCELED) {
773 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700774 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700775 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700776 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700777 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
778 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700779 }
780 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200781 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
782 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
783 mWorkspace.exitOverviewMode(false);
784 }
785 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700786 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200787
Adam Cohened66b2b2012-01-23 17:28:51 -0800788 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
789 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700790
Adam Cohendb364c32014-05-20 14:23:40 -0700791 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800792 // We have special handling for widgets
793 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800794 final int appWidgetId;
795 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
796 : -1;
797 if (widgetId < 0) {
798 appWidgetId = pendingAddWidgetId;
799 } else {
800 appWidgetId = widgetId;
801 }
802
Adam Cohenad4e15c2013-10-17 16:21:35 -0700803 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800804 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700805 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
806 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700807 result = RESULT_CANCELED;
808 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700809 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700810 @Override
811 public void run() {
812 exitSpringLoadedDragModeDelayed(false, 0, null);
813 }
814 };
Adam Cohendb364c32014-05-20 14:23:40 -0700815 if (workspaceLocked) {
816 // No need to remove the empty screen if we're mid-binding, as the
817 // the bind will not add the empty screen.
818 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
819 } else {
820 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
821 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
822 }
Winson Chung5aaab772012-04-27 15:24:02 -0700823 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700824 if (!workspaceLocked) {
825 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
826 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
827
828 dropLayout.setDropPending(true);
829 final Runnable onComplete = new Runnable() {
830 @Override
831 public void run() {
832 completeTwoStageWidgetDrop(resultCode, appWidgetId);
833 dropLayout.setDropPending(false);
834 }
835 };
836 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
837 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
838 } else {
839 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
840 mPendingAddInfo);
841 sPendingAddItem = args;
842 }
Winson Chung5aaab772012-04-27 15:24:02 -0700843 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800844 return;
845 }
846
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 // The pattern used here is that a user PICKs a specific application,
848 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700849
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
851 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700852 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700853 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
854 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800855 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700856 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800857 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700858 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700859 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
860 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861 }
Adam Cohen00074722013-10-11 17:46:09 -0700862 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700863 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700864 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800866 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800867 }
868
Adam Cohendb364c32014-05-20 14:23:40 -0700869 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
870 appWidgetId, ItemInfo info) {
871 PendingAddArguments args = new PendingAddArguments();
872 args.requestCode = requestCode;
873 args.intent = data;
874 args.container = info.container;
875 args.screenId = info.screenId;
876 args.cellX = info.cellX;
877 args.cellY = info.cellY;
878 args.appWidgetId = appWidgetId;
879 return args;
880 }
881
882 /**
883 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
884 *
885 * @param screenId the screen id to check
886 * @return the new screen, or screenId if it exists
887 */
888 private long ensurePendingDropLayoutExists(long screenId) {
889 CellLayout dropLayout =
890 (CellLayout) mWorkspace.getScreenWithId(screenId);
891 if (dropLayout == null) {
892 // it's possible that the add screen was removed because it was
893 // empty and a re-bind occurred
894 mWorkspace.addExtraEmptyScreen();
895 return mWorkspace.commitExtraEmptyScreen();
896 } else {
897 return screenId;
898 }
899 }
900
Adam Cohened66b2b2012-01-23 17:28:51 -0800901 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700902 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700903 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800904 Runnable onCompleteRunnable = null;
905 int animationType = 0;
906
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700907 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800908 if (resultCode == RESULT_OK) {
909 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
910 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700911 mPendingAddWidgetInfo);
912 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800913 onCompleteRunnable = new Runnable() {
914 @Override
915 public void run() {
916 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700917 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700918 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
919 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800920 }
921 };
922 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800923 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800924 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800925 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700926 if (mDragLayer.getAnimatedView() != null) {
927 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
928 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
929 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700930 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700931 // The animated view may be null in the case of a rotation during widget configuration
932 onCompleteRunnable.run();
933 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800934 }
935
936 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700937 protected void onStop() {
938 super.onStop();
939 FirstFrameAnimatorHelper.setIsVisible(false);
940 }
941
942 @Override
943 protected void onStart() {
944 super.onStart();
945 FirstFrameAnimatorHelper.setIsVisible(true);
946 }
947
948 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800949 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200950 long startTime = 0;
951 if (DEBUG_RESUME_TIME) {
952 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400953 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200954 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700956
Winson Chung4a2afa32012-07-19 14:53:05 -0700957 // Restore the previous launcher state
958 if (mOnResumeState == State.WORKSPACE) {
959 showWorkspace(false);
960 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800961 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700962 }
963 mOnResumeState = State.NONE;
964
Craig Mautner360310b2012-10-26 15:13:08 -0700965 // Background was set to gradient in onPause(), restore to black if in all apps.
966 setWorkspaceBackground(mState == State.WORKSPACE);
967
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800968 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700969 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700970 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700971 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500972 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400973 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700974 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800975 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700976 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200977 // We might have postponed some bind calls until onResume (see waitUntilResume) --
978 // execute them here
979 long startTimeCallbacks = 0;
980 if (DEBUG_RESUME_TIME) {
981 startTimeCallbacks = System.currentTimeMillis();
982 }
983
984 if (mAppsCustomizeContent != null) {
985 mAppsCustomizeContent.setBulkBind(true);
986 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700987 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
988 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200989 }
990 if (mAppsCustomizeContent != null) {
991 mAppsCustomizeContent.setBulkBind(false);
992 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700993 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200994 if (DEBUG_RESUME_TIME) {
995 Log.d(TAG, "Time spent processing callbacks in onResume: " +
996 (System.currentTimeMillis() - startTimeCallbacks));
997 }
Michael Jurka447bf842013-05-15 14:52:15 +0200998 }
Michael Jurka54554252013-08-01 12:52:23 +0200999 if (mOnResumeCallbacks.size() > 0) {
1000 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1001 mOnResumeCallbacks.get(i).run();
1002 }
1003 mOnResumeCallbacks.clear();
1004 }
Winson Chunge4e50662012-01-23 14:45:13 -08001005
1006 // Reset the pressed state of icons that were locked in the press state while activities
1007 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001008 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001009 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001010 mWaitingForResume.setStayPressed(false);
1011 }
Winson Chunge4e50662012-01-23 14:45:13 -08001012 if (mAppsCustomizeContent != null) {
1013 // Resets the previous all apps icon press state
1014 mAppsCustomizeContent.resetDrawableState();
1015 }
Winson Chung82963d52013-10-09 11:20:57 -07001016
Adam Cohen06dff352012-06-01 17:17:08 -07001017 // It is possible that widgets can receive updates while launcher is not in the foreground.
1018 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1019 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1020 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001021 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001022
Winson Chung780fe592013-09-26 14:48:44 -07001023 // Process any items that were added while Launcher was away.
1024 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1025
Winson Chung5841efa2013-09-30 18:06:44 -07001026 // Update the voice search button proxy
1027 updateVoiceButtonProxyVisible(false);
1028
Adam Cohenf9426d52012-06-04 17:26:21 -07001029 // Again, as with the above scenario, it's possible that one or more of the global icons
1030 // were updated in the wrong orientation.
1031 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001032 if (DEBUG_RESUME_TIME) {
1033 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1034 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001035
1036 if (mWorkspace.getCustomContentCallbacks() != null) {
1037 // If we are resuming and the custom content is the current page, we call onShow().
1038 // It is also poassible that onShow will instead be called slightly after first layout
1039 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1040 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001041 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001042 }
1043 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001044 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001045 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001046 }
1047
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001048 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001049 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001050 // Ensure that items added to Launcher are queued until Launcher returns
1051 InstallShortcutReceiver.enableInstallQueue();
1052
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001053 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001054 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001055 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001056 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001057
1058 // We call onHide() aggressively. The custom content callbacks should be able to
1059 // debounce excess onHide calls.
1060 if (mWorkspace.getCustomContentCallbacks() != null) {
1061 mWorkspace.getCustomContentCallbacks().onHide();
1062 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001063 }
Romain Guycbb89e42009-06-08 15:52:54 -07001064
Adam Cohenbffe7452013-07-22 18:21:45 -07001065 QSBScroller mQsbScroller = new QSBScroller() {
1066 int scrollY = 0;
1067
1068 @Override
1069 public void setScrollY(int scroll) {
1070 scrollY = scroll;
1071
1072 if (mWorkspace.isOnOrMovingToCustomContent()) {
1073 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001074 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001075 }
1076 }
1077 };
1078
1079 public void resetQSBScroll() {
1080 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001081 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001082 }
1083
1084 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001085 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1086 // by a onResume or by scrolling otherwise.
1087 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001088
1089 // Custom content is completely hidden
1090 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001091
1092 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1093 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001094 }
1095
Jorim Jaggid017f882014-01-14 17:08:48 -08001096 protected boolean hasSettings() {
1097 return false;
1098 }
1099
Adam Cohenbffe7452013-07-22 18:21:45 -07001100 public interface QSBScroller {
1101 public void setScrollY(int scrollY);
1102 }
1103
Winson Chung98ca0f72013-07-29 12:58:51 -07001104 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001105 CustomContentCallbacks callbacks, String description) {
1106 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001107 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001108 }
1109
Adam Cohenedb40762013-07-18 16:45:45 -07001110 // The custom content needs to offset its content to account for the QSB
1111 public int getTopOffsetForCustomContent() {
1112 return mWorkspace.getPaddingTop();
1113 }
1114
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001115 @Override
1116 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001117 // Flag the loader to stop early before switching
1118 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001119 if (mAppsCustomizeContent != null) {
1120 mAppsCustomizeContent.surrender();
1121 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001122 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001123 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001124
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001125 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001126 @Override
1127 public void onWindowFocusChanged(boolean hasFocus) {
1128 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001129 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001130 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001131
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132 private boolean acceptFilter() {
1133 final InputMethodManager inputManager = (InputMethodManager)
1134 getSystemService(Context.INPUT_METHOD_SERVICE);
1135 return !inputManager.isFullscreenMode();
1136 }
1137
1138 @Override
1139 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001140 final int uniChar = event.getUnicodeChar();
1141 final boolean handled = super.onKeyDown(keyCode, event);
1142 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1143 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001144 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1145 keyCode, event);
1146 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001147 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001148 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001149 // showSearchDialog()
1150 // If there are multiple keystrokes before the search dialog takes focus,
1151 // onSearchRequested() will be called for every keystroke,
1152 // but it is idempotent, so it's fine.
1153 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001154 }
1155 }
1156
Joe Onorato8a9625e2010-01-28 15:55:35 -08001157 // Eat the long press event so the keyboard doesn't come up.
1158 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1159 return true;
1160 }
1161
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 return handled;
1163 }
1164
Karl Rosaen138a0412009-04-23 19:00:21 -07001165 private String getTypedText() {
1166 return mDefaultKeySsb.toString();
1167 }
1168
1169 private void clearTypedText() {
1170 mDefaultKeySsb.clear();
1171 mDefaultKeySsb.clearSpans();
1172 Selection.setSelection(mDefaultKeySsb, 0);
1173 }
1174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001176 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1177 * State
1178 */
1179 private static State intToState(int stateOrdinal) {
1180 State state = State.WORKSPACE;
1181 final State[] stateValues = State.values();
1182 for (int i = 0; i < stateValues.length; i++) {
1183 if (stateValues[i].ordinal() == stateOrdinal) {
1184 state = stateValues[i];
1185 break;
1186 }
1187 }
1188 return state;
1189 }
1190
1191 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001192 * Restores the previous state, if it exists.
1193 *
1194 * @param savedState The previous state.
1195 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001196 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001197 private void restoreState(Bundle savedState) {
1198 if (savedState == null) {
1199 return;
1200 }
1201
Michael Jurka883f55b2010-10-21 15:47:14 -07001202 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001203 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001204 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001205 }
1206
Adam Cohen21cd0022013-10-09 18:57:02 -07001207 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1208 PagedView.INVALID_RESTORE_PAGE);
1209 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001210 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 }
1212
Winson Chung3d503fb2011-07-13 17:25:49 -07001213 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001214 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001215
Winson Chung3d503fb2011-07-13 17:25:49 -07001216 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1217 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001218 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001219 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1220 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001221 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1222 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1223 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001224 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001225 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 mRestoring = true;
1227 }
1228
1229 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1230 if (renameFolder) {
1231 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001232 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 mRestoring = true;
1234 }
Winson Chunga12a2502010-12-20 14:41:35 -08001235
Winson Chung785d2eb2011-04-14 16:08:02 -07001236 // Restore the AppsCustomize tab
1237 if (mAppsCustomizeTabHost != null) {
1238 String curTab = savedState.getString("apps_customize_currentTab");
1239 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001240 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001241 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001242 mAppsCustomizeContent.loadAssociatedPages(
1243 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001244 }
1245
Winson Chung5afbf7b2011-07-25 11:53:08 -07001246 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1247 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001248 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001249 mItemIdToViewId = (HashMap<Integer, Integer>)
1250 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
1252
1253 /**
1254 * Finds all the views we need and configure them properly.
1255 */
1256 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001257 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001258
Craig Mautner360310b2012-10-26 15:13:08 -07001259 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001260 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1261 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001262 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001263 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001264
John Spurlock77e1f472013-09-11 10:09:51 -04001265 mLauncherView.setSystemUiVisibility(
1266 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001267 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268
Winson Chung4c98d922011-05-31 16:50:48 -07001269 // Setup the drag layer
1270 mDragLayer.setup(this, dragController);
1271
Winson Chung3d503fb2011-07-13 17:25:49 -07001272 // Setup the hotseat
1273 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1274 if (mHotseat != null) {
1275 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001276 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001277 }
1278
Jorim Jaggid017f882014-01-14 17:08:48 -08001279 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001280 View widgetButton = findViewById(R.id.widget_button);
1281 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001282 @Override
1283 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001284 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001285 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001286 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001287 }
1288 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001289 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1290
1291 View wallpaperButton = findViewById(R.id.wallpaper_button);
1292 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001293 @Override
1294 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001295 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001296 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001297 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001298 }
1299 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001300 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1301
1302 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001303 if (hasSettings()) {
1304 settingsButton.setOnClickListener(new OnClickListener() {
1305 @Override
1306 public void onClick(View arg0) {
1307 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001308 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001309 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001310 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001311 });
1312 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1313 } else {
1314 settingsButton.setVisibility(View.GONE);
1315 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1316 lp.gravity = Gravity.END | Gravity.TOP;
1317 widgetButton.requestLayout();
1318 }
1319
Adam Cohendbdff6b2013-09-18 19:09:15 -07001320 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001321
Winson Chung4c98d922011-05-31 16:50:48 -07001322 // Setup the workspace
1323 mWorkspace.setHapticFeedbackEnabled(false);
1324 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001325 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001326 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001327
Winson Chungf0ea4d32011-06-06 14:27:16 -07001328 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001329 mSearchDropTargetBar = (SearchDropTargetBar)
1330 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001331
Winson Chungf0ea4d32011-06-06 14:27:16 -07001332 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001333 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001334 mAppsCustomizeContent = (AppsCustomizePagedView)
1335 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1336 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001337
Winson Chung3d503fb2011-07-13 17:25:49 -07001338 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001339 dragController.setDragScoller(mWorkspace);
1340 dragController.setScrollView(mDragLayer);
1341 dragController.setMoveTarget(mWorkspace);
1342 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001343 if (mSearchDropTargetBar != null) {
1344 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001345 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001346
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001347 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001348 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001349 mWeightWatcher = new WeightWatcher(this);
1350 mWeightWatcher.setAlpha(0.5f);
1351 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001352 new FrameLayout.LayoutParams(
1353 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001354 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001355 Gravity.BOTTOM)
1356 );
Adam Cohen39a06042013-07-19 14:30:12 -07001357
1358 boolean show = shouldShowWeightWatcher();
1359 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001360 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 }
1362
1363 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001364 * Sets the all apps button. This method is called from {@link Hotseat}.
1365 */
1366 public void setAllAppsButton(View allAppsButton) {
1367 mAllAppsButton = allAppsButton;
1368 }
1369
1370 public View getAllAppsButton() {
1371 return mAllAppsButton;
1372 }
1373
1374 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 * Creates a view representing a shortcut.
1376 *
1377 * @param info The data structure describing the shortcut.
1378 *
1379 * @return A View inflated from R.layout.application.
1380 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001381 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001382 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001383 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384 }
1385
1386 /**
1387 * Creates a view representing a shortcut inflated from the specified resource.
1388 *
1389 * @param layoutResId The id of the XML layout used to create the shortcut.
1390 * @param parent The group the shortcut belongs to.
1391 * @param info The data structure describing the shortcut.
1392 *
1393 * @return A View inflated from layoutResId.
1394 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001395 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001396 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1397 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001398 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 return favorite;
1400 }
1401
1402 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 * Add a shortcut to the workspace.
1404 *
1405 * @param data The intent describing the shortcut.
1406 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001408 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001409 int cellY) {
1410 int[] cellXY = mTmpAddItemCellCoordinates;
1411 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001412 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001413
Michael Jurkad3ef3062010-11-23 16:23:58 -08001414 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001415
Adam Cohen558baaf2011-08-15 15:22:57 -07001416 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001417 if (info == null) {
1418 return;
1419 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001420 final View view = createShortcut(info);
1421
Adam Cohenfbba09b2011-07-18 21:43:05 -07001422 // First we check if we already know the exact location where we want to add this item.
1423 if (cellX >= 0 && cellY >= 0) {
1424 cellXY[0] = cellX;
1425 cellXY[1] = cellY;
1426 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001427
1428 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001429 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001430 true, null,null)) {
1431 return;
1432 }
1433 DragObject dragObject = new DragObject();
1434 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001435 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1436 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001437 return;
1438 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001439 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001440 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001441 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001442 foundCellSpan = (result != null);
1443 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001444 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001445 }
1446
1447 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001448 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001449 return;
1450 }
1451
Adam Cohendcd297f2013-06-18 13:13:40 -07001452 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453
1454 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001455 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001456 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457 }
1458 }
1459
Adam Cohen2f093b62012-04-30 18:59:53 -07001460 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1461 int minHeight) {
1462 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001463 // We want to account for the extra amount of padding that we are adding to the widget
1464 // to ensure that it gets the full amount of space that it has requested
1465 int requiredWidth = minWidth + padding.left + padding.right;
1466 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001467 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001468 }
1469
Adam Cohen2f093b62012-04-30 18:59:53 -07001470 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1471 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001472 }
1473
Adam Cohen2f093b62012-04-30 18:59:53 -07001474 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1475 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001476 }
1477
Adam Cohen2f093b62012-04-30 18:59:53 -07001478 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1479 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001480 }
1481
Adam Cohen2f093b62012-04-30 18:59:53 -07001482 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1483 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001484 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001485 }
1486
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001487 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001488 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001490 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001491 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001493 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001494 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1495 if (appWidgetInfo == null) {
1496 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1497 }
Romain Guycbb89e42009-06-08 15:52:54 -07001498
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001499 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001500 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001501
Adam Cohen2f093b62012-04-30 18:59:53 -07001502 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1503 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001504
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001506 // We have saved the position to which the widget was dragged-- this really only matters
1507 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001508 int[] cellXY = mTmpAddItemCellCoordinates;
1509 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001510 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001511 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001512 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1513 cellXY[0] = mPendingAddInfo.cellX;
1514 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001515 spanXY[0] = mPendingAddInfo.spanX;
1516 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001517 foundCellSpan = true;
1518 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001519 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001520 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001521 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1522 spanXY[1], cellXY, finalSpan);
1523 spanXY[0] = finalSpan[0];
1524 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001525 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001526 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001527 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001528 }
1529
Michael Jurka0280c3b2010-09-17 15:00:07 -07001530 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001531 if (appWidgetId != -1) {
1532 // Deleting an app widget ID is a void call but writes to disk before returning
1533 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001534 new AsyncTask<Void, Void, Void>() {
1535 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001536 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001537 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001538 }
Michael Jurka43467462013-11-14 12:03:58 +01001539 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001540 }
Winson Chung93eef082012-03-23 15:59:27 -07001541 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001542 return;
1543 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001545 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001546 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1547 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001548 launcherInfo.spanX = spanXY[0];
1549 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001550 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1551 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001552
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001554 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555
1556 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001557 if (hostView == null) {
1558 // Perform actual inflation because we're live
1559 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1560 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1561 } else {
1562 // The AppWidgetHostView has already been inflated and instantiated
1563 launcherInfo.hostView = hostView;
1564 }
Romain Guycbb89e42009-06-08 15:52:54 -07001565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001566 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001567 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001568 launcherInfo.notifyWidgetSizeChanged(this);
1569
Adam Cohendcd297f2013-06-18 13:13:40 -07001570 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001572
1573 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001575 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576 }
Romain Guycbb89e42009-06-08 15:52:54 -07001577
Adam Cohended9f8d2010-11-03 13:25:16 -07001578 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1579 @Override
1580 public void onReceive(Context context, Intent intent) {
1581 final String action = intent.getAction();
1582 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1583 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001584 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001585 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001586
Winson Chungc100e8e2011-08-09 16:02:43 -07001587 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001588 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001589 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001590 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001591 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001592 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1593 mUserPresent = true;
1594 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001595 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1596 mModel.resetLoadedState(false, true);
1597 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1598 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1599 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1600 mModel.resetLoadedState(false, true);
1601 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1602 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1603 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001604 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1605 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1606 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001607 }
1608 }
1609 };
1610
1611 @Override
1612 public void onAttachedToWindow() {
1613 super.onAttachedToWindow();
1614
1615 // Listen for broadcasts related to user-presence
1616 final IntentFilter filter = new IntentFilter();
1617 filter.addAction(Intent.ACTION_SCREEN_OFF);
1618 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001619 // For handling managed profiles
1620 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1621 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001622 if (ENABLE_DEBUG_INTENTS) {
1623 filter.addAction(DebugIntents.DELETE_DATABASE);
1624 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1625 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001626 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001627 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001628 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001629 mVisible = true;
1630 }
1631
1632 @Override
1633 public void onDetachedFromWindow() {
1634 super.onDetachedFromWindow();
1635 mVisible = false;
1636
Adam Cohend113e0c2010-11-11 10:48:05 -08001637 if (mAttached) {
1638 unregisterReceiver(mReceiver);
1639 mAttached = false;
1640 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001641 updateRunning();
1642 }
1643
1644 public void onWindowVisibilityChanged(int visibility) {
1645 mVisible = visibility == View.VISIBLE;
1646 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001647 // The following code used to be in onResume, but it turns out onResume is called when
1648 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1649 // is a more appropriate event to handle
1650 if (mVisible) {
1651 mAppsCustomizeTabHost.onWindowVisible();
1652 if (!mWorkspaceLoading) {
1653 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001654 // We want to let Launcher draw itself at least once before we force it to build
1655 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001656 // apps is nice and speedy.
1657 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001658 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001659 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001660 if (mStarted) return;
1661 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001662 // We delay the layer building a bit in order to give
1663 // other message processing a time to run. In particular
1664 // this avoids a delay in hiding the IME if it was
1665 // currently shown, because doing that may involve
1666 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001667 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001668 final ViewTreeObserver.OnDrawListener listener = this;
1669 mWorkspace.post(new Runnable() {
1670 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001671 if (mWorkspace != null &&
1672 mWorkspace.getViewTreeObserver() != null) {
1673 mWorkspace.getViewTreeObserver().
1674 removeOnDrawListener(listener);
1675 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001676 }
1677 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001678 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001679 }
1680 });
1681 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001682 // When Launcher comes back to foreground, a different Activity might be responsible for
1683 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001684 if (!DISABLE_MARKET_BUTTON) {
1685 updateAppMarketIcon();
1686 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001687 clearTypedText();
1688 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001689 }
1690
1691 private void sendAdvanceMessage(long delay) {
1692 mHandler.removeMessages(ADVANCE_MSG);
1693 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1694 mHandler.sendMessageDelayed(msg, delay);
1695 mAutoAdvanceSentTime = System.currentTimeMillis();
1696 }
1697
1698 private void updateRunning() {
1699 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1700 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1701 mAutoAdvanceRunning = autoAdvanceRunning;
1702 if (autoAdvanceRunning) {
1703 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1704 sendAdvanceMessage(delay);
1705 } else {
1706 if (!mWidgetsToAdvance.isEmpty()) {
1707 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1708 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1709 }
1710 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001711 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001712 }
1713 }
1714 }
1715
1716 private final Handler mHandler = new Handler() {
1717 @Override
1718 public void handleMessage(Message msg) {
1719 if (msg.what == ADVANCE_MSG) {
1720 int i = 0;
1721 for (View key: mWidgetsToAdvance.keySet()) {
1722 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1723 final int delay = mAdvanceStagger * i;
1724 if (v instanceof Advanceable) {
1725 postDelayed(new Runnable() {
1726 public void run() {
1727 ((Advanceable) v).advance();
1728 }
1729 }, delay);
1730 }
1731 i++;
1732 }
1733 sendAdvanceMessage(mAdvanceInterval);
1734 }
1735 }
1736 };
1737
1738 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001739 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001740 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1741 if (v instanceof Advanceable) {
1742 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001743 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001744 updateRunning();
1745 }
1746 }
1747
1748 void removeWidgetToAutoAdvance(View hostView) {
1749 if (mWidgetsToAdvance.containsKey(hostView)) {
1750 mWidgetsToAdvance.remove(hostView);
1751 updateRunning();
1752 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001753 }
1754
Joe Onorato9c1289c2009-08-17 11:03:03 -04001755 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001756 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001757 launcherInfo.hostView = null;
1758 }
1759
Winson Chung93eef082012-03-23 15:59:27 -07001760 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1761 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1762 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001763 }
1764
Winson Chunga6945242014-01-08 14:04:34 -08001765 public DragLayer getDragLayer() {
1766 return mDragLayer;
1767 }
1768
1769 public Workspace getWorkspace() {
1770 return mWorkspace;
1771 }
1772
1773 public Hotseat getHotseat() {
1774 return mHotseat;
1775 }
1776
Jorim Jaggid017f882014-01-14 17:08:48 -08001777 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001778 return mOverviewPanel;
1779 }
1780
1781 public SearchDropTargetBar getSearchBar() {
1782 return mSearchDropTargetBar;
1783 }
1784
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001785 public LauncherAppWidgetHost getAppWidgetHost() {
1786 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 }
Romain Guycbb89e42009-06-08 15:52:54 -07001788
Winson Chunga9abd0e2010-10-27 17:18:37 -07001789 public LauncherModel getModel() {
1790 return mModel;
1791 }
1792
Winson Chunga6945242014-01-08 14:04:34 -08001793 public LauncherClings getLauncherClings() {
1794 return mLauncherClings;
1795 }
1796
1797 protected SharedPreferences getSharedPrefs() {
1798 return mSharedPrefs;
1799 }
1800
Bjorn Bringertc459e522013-06-07 19:36:01 +01001801 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001802 getWindow().closeAllPanels();
1803
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001804 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001805 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001806 }
1807
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 @Override
1809 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001810 long startTime = 0;
1811 if (DEBUG_RESUME_TIME) {
1812 startTime = System.currentTimeMillis();
1813 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 super.onNewIntent(intent);
1815
1816 // Close the menu
1817 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001818 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001819 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001820
Adam Cohened307df2013-10-02 09:37:31 -07001821 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1822 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1823 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001824
Adam Cohen6fecd412013-10-02 17:41:50 -07001825 if (mWorkspace == null) {
1826 // Can be cases where mWorkspace is null, this prevents a NPE
1827 return;
1828 }
1829 Folder openFolder = mWorkspace.getOpenFolder();
1830 // In all these cases, only animate if we're already on home
1831 mWorkspace.exitWidgetResizeMode();
1832 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001833 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001834 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001835 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001836
Adam Cohen6fecd412013-10-02 17:41:50 -07001837 closeFolder();
1838 exitSpringLoadedDragMode();
1839
1840 // If we are already on home, then just animate back to the workspace,
1841 // otherwise, just wait until onResume to set the state back to Workspace
1842 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001843 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001844 } else {
1845 mOnResumeState = State.WORKSPACE;
1846 }
1847
1848 final View v = getWindow().peekDecorView();
1849 if (v != null && v.getWindowToken() != null) {
1850 InputMethodManager imm = (InputMethodManager)getSystemService(
1851 INPUT_METHOD_SERVICE);
1852 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1853 }
1854
1855 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001856 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001857 mAppsCustomizeTabHost.reset();
1858 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001859
1860 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 }
Adam Cohened307df2013-10-02 09:37:31 -07001862
Michael Jurka447bf842013-05-15 14:52:15 +02001863 if (DEBUG_RESUME_TIME) {
1864 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1865 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001866 }
1867
Adam Coppa120b8e2013-11-12 16:26:04 +00001868 /**
1869 * Override point for subclasses to prevent movement to the default screen when the home
1870 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1871 */
1872 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1873 return true;
1874 }
1875
1876 /**
1877 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1878 */
1879 protected void onHomeIntent() {
1880 // Do nothing
1881 }
1882
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001884 public void onRestoreInstanceState(Bundle state) {
1885 super.onRestoreInstanceState(state);
1886 for (int page: mSynchronouslyBoundPages) {
1887 mWorkspace.restoreInstanceStateForChild(page);
1888 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 }
1890
1891 @Override
1892 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001893 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001894 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1895 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001896 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001897 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001898
Michael Jurka883f55b2010-10-21 15:47:14 -07001899 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001900 // We close any open folder since it will not be re-opened, and we need to make sure
1901 // this state is reflected.
1902 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903
Adam Cohendcd297f2013-06-18 13:13:40 -07001904 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001905 mWaitingForResult) {
1906 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001907 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001908 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1909 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001910 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1911 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1912 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001913 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914 }
1915
1916 if (mFolderInfo != null && mWaitingForResult) {
1917 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1918 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1919 }
Michael Jurka946ad472010-07-09 18:05:18 -07001920
Winson Chung785d2eb2011-04-14 16:08:02 -07001921 // Save the current AppsCustomize tab
1922 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001923 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1924 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001925 if (currentTabTag != null) {
1926 outState.putString("apps_customize_currentTab", currentTabTag);
1927 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001928 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1929 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001930 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001931 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 }
1933
1934 @Override
1935 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001937
Winson Chunge7a03942011-08-05 15:05:12 -07001938 // Remove all pending runnables
1939 mHandler.removeMessages(ADVANCE_MSG);
1940 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001941 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001942
Winson Chungcd2b0142011-06-08 16:02:26 -07001943 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001944 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001945 mModel.stopLoader();
1946 app.setLauncher(null);
1947
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001949 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001951 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001953 mAppWidgetHost = null;
1954
1955 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001956
1957 TextKeyListener.getInstance().release();
1958
Winson Chung81b52252012-08-27 15:34:29 -07001959 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1960 // to prevent leaking Launcher activities on orientation change.
1961 if (mModel != null) {
1962 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1963 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001964
1965 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001966 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001967
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001968 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001969 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001970 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001971 mWorkspace = null;
1972 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001973
Michael Jurka2ecf9952012-06-18 12:52:28 -07001974 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 }
1976
Adam Cohena9cf38f2011-05-02 15:36:58 -07001977 public DragController getDragController() {
1978 return mDragController;
1979 }
1980
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001981 @Override
1982 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001983 if (requestCode >= 0) {
1984 setWaitingForResult(true);
1985 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 super.startActivityForResult(intent, requestCode);
1987 }
1988
Winson Chung70d72102011-08-12 11:24:35 -07001989 /**
1990 * Indicates that we want global search for this activity by setting the globalSearch
1991 * argument for {@link #startSearch} to true.
1992 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001994 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001996
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001997 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001998
Karl Rosaen138a0412009-04-23 19:00:21 -07001999 if (initialQuery == null) {
2000 // Use any text typed in the launcher as the initial query
2001 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002002 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 if (appSearchData == null) {
2004 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002005 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 }
Winson Chungadf0c182012-08-23 14:59:07 -07002007 Rect sourceBounds = new Rect();
2008 if (mSearchDropTargetBar != null) {
2009 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2010 }
Romain Guycbb89e42009-06-08 15:52:54 -07002011
Bjorn Bringertc459e522013-06-07 19:36:01 +01002012 startSearch(initialQuery, selectInitialQuery,
2013 appSearchData, sourceBounds);
2014 }
2015
2016 public void startSearch(String initialQuery,
2017 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002018 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002019 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002020 }
2021
2022 /**
2023 * Starts the global search activity. This code is a copied from SearchManager
2024 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002025 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002026 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002027 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002028 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2029 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2030 if (globalSearchActivity == null) {
2031 Log.w(TAG, "No global search activity found.");
2032 return;
2033 }
2034 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2035 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2036 intent.setComponent(globalSearchActivity);
2037 // Make sure that we have a Bundle to put source in
2038 if (appSearchData == null) {
2039 appSearchData = new Bundle();
2040 } else {
2041 appSearchData = new Bundle(appSearchData);
2042 }
2043 // Set source to package name of app that starts global search, if not set already.
2044 if (!appSearchData.containsKey("source")) {
2045 appSearchData.putString("source", getPackageName());
2046 }
2047 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2048 if (!TextUtils.isEmpty(initialQuery)) {
2049 intent.putExtra(SearchManager.QUERY, initialQuery);
2050 }
2051 if (selectInitialQuery) {
2052 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2053 }
2054 intent.setSourceBounds(sourceBounds);
2055 try {
2056 startActivity(intent);
2057 } catch (ActivityNotFoundException ex) {
2058 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2059 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 }
2061
Yura4f93ec62014-02-04 14:15:21 +00002062 public boolean isOnCustomContent() {
2063 return mWorkspace.isOnOrMovingToCustomContent();
2064 }
2065
Winson Chung70d72102011-08-12 11:24:35 -07002066 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002067 public boolean onPrepareOptionsMenu(Menu menu) {
2068 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002069 if (!isOnCustomContent()) {
2070 // Close any open folders
2071 closeFolder();
2072 // Stop resizing any widgets
2073 mWorkspace.exitWidgetResizeMode();
2074 if (!mWorkspace.isInOverviewMode()) {
2075 // Show the overview mode
2076 showOverviewMode(true);
2077 } else {
2078 showWorkspace(true);
2079 }
Winson Chunge0298742014-01-17 12:03:00 -08002080 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002081 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002082 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002084 @Override
2085 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002086 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002087 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002088 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002089 }
2090
Joe Onorato9c1289c2009-08-17 11:03:03 -04002091 public boolean isWorkspaceLocked() {
2092 return mWorkspaceLoading || mWaitingForResult;
2093 }
2094
Adam Cohen517a7f52014-03-01 12:12:59 -08002095 public boolean isWorkspaceLoading() {
2096 return mWorkspaceLoading;
2097 }
2098
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002099 private void setWorkspaceLoading(boolean value) {
2100 boolean isLocked = isWorkspaceLocked();
2101 mWorkspaceLoading = value;
2102 if (isLocked != isWorkspaceLocked()) {
2103 onWorkspaceLockedChanged();
2104 }
2105 }
2106
2107 private void setWaitingForResult(boolean value) {
2108 boolean isLocked = isWorkspaceLocked();
2109 mWaitingForResult = value;
2110 if (isLocked != isWorkspaceLocked()) {
2111 onWorkspaceLockedChanged();
2112 }
2113 }
2114
2115 protected void onWorkspaceLockedChanged() { }
2116
Michael Jurka0280c3b2010-09-17 15:00:07 -07002117 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002118 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002119 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002120 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2121 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002122 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002123 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002124 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002125
Adam Cohenad4e15c2013-10-17 16:21:35 -07002126 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2127 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2128 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2129 }
2130
2131 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2132 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2133 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002134 if (appWidgetInfo.configure != null) {
2135 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002136 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002137
Bjorn Bringert7984c942009-12-09 15:38:25 +00002138 // Launch over to configure widget, if needed
2139 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002140 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002141 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002142 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002144 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002145 Runnable onComplete = new Runnable() {
2146 @Override
2147 public void run() {
2148 // Exit spring loaded mode if necessary after adding the widget
2149 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2150 null);
2151 }
2152 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002153 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002154 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002155 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002156 }
2157 }
Romain Guycbb89e42009-06-08 15:52:54 -07002158
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002159 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002160 // Close any folders that may be open.
2161 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002162 mWorkspace.moveToCustomContentScreen(animate);
2163 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002164 /**
2165 * Process a shortcut drop.
2166 *
2167 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002168 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002169 * @param cell The cell it should be added to, optional
2170 * @param position The location on the screen where it was dropped, optional
2171 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002172 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002173 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002174 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002175 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002176 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002177 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002178
2179 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002180 mPendingAddInfo.cellX = cell[0];
2181 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002182 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002183
2184 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2185 createShortcutIntent.setComponent(componentName);
2186 processShortcut(createShortcutIntent);
2187 }
2188
Adam Cohenfbba09b2011-07-18 21:43:05 -07002189 /**
2190 * Process a widget drop.
2191 *
2192 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002193 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002194 * @param cell The cell it should be added to, optional
2195 * @param position The location on the screen where it was dropped, optional
2196 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002197 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002198 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002199 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002200 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002201 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002202 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002203 mPendingAddInfo.minSpanX = info.minSpanX;
2204 mPendingAddInfo.minSpanY = info.minSpanY;
2205
Adam Cohenfbba09b2011-07-18 21:43:05 -07002206 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002207 mPendingAddInfo.cellX = cell[0];
2208 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002209 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002210 if (span != null) {
2211 mPendingAddInfo.spanX = span[0];
2212 mPendingAddInfo.spanY = span[1];
2213 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002214
Adam Cohened66b2b2012-01-23 17:28:51 -08002215 AppWidgetHostView hostView = info.boundWidget;
2216 int appWidgetId;
2217 if (hostView != null) {
2218 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002219 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002220 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002221 // In this case, we either need to start an activity to get permission to bind
2222 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002223 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002224 Bundle options = info.bindOptions;
2225
2226 boolean success = false;
2227 if (options != null) {
2228 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2229 info.componentName, options);
2230 } else {
2231 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2232 info.componentName);
2233 }
2234 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002235 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002236 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002237 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002238 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2239 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2240 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002241 // TODO: we need to make sure that this accounts for the options bundle.
2242 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002243 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2244 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002245 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002246 }
2247
Joe Onoratodeb98af2010-02-19 14:59:39 -08002248 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002249 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002250 }
2251
Winson Chung24ab2f12010-09-16 14:10:47 -07002252 void processWallpaper(Intent intent) {
2253 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2254 }
2255
Adam Cohendcd297f2013-06-18 13:13:40 -07002256 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002257 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002258 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002259 folderInfo.title = getText(R.string.folder_name);
2260
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002261 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002262 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002263 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002264 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002265
2266 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002267 FolderIcon newFolder =
2268 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002269 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002270 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002271 // Force measure the new folder icon
2272 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2273 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002274 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002275 }
Romain Guycbb89e42009-06-08 15:52:54 -07002276
Joe Onorato9c1289c2009-08-17 11:03:03 -04002277 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002278 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002279 }
2280
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002281 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002282 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002283 }
2284
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002285 /**
2286 * Registers various content observers. The current implementation registers
2287 * only a favorites observer to keep track of the favorites applications.
2288 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002289 private void registerContentObservers() {
2290 ContentResolver resolver = getContentResolver();
2291 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2292 true, mWidgetObserver);
2293 }
2294
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002295 @Override
2296 public boolean dispatchKeyEvent(KeyEvent event) {
2297 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2298 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002299 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002300 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002301 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002302 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002303 dumpState();
2304 return true;
2305 }
2306 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002307 }
2308 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2309 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002310 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311 return true;
2312 }
2313 }
2314
2315 return super.dispatchKeyEvent(event);
2316 }
2317
Joe Onorato88ec0992009-11-19 13:16:06 -08002318 @Override
2319 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002320 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002321 if (mAppsCustomizeContent.getContentType() ==
2322 AppsCustomizePagedView.ContentType.Applications) {
2323 showWorkspace(true);
2324 } else {
2325 showOverviewMode(true);
2326 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002327 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002328 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002329 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002330 Folder openFolder = mWorkspace.getOpenFolder();
2331 if (openFolder.isEditingName()) {
2332 openFolder.dismissEditingName();
2333 } else {
2334 closeFolder();
2335 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002336 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002337 mWorkspace.exitWidgetResizeMode();
2338
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002339 // Back button is a no-op here, but give at least some feedback for the button press
2340 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002341 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002342 }
2343
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002344 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002345 * Re-listen when widgets are reset.
2346 */
2347 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002348 if (mAppWidgetHost != null) {
2349 mAppWidgetHost.startListening();
2350 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002351 }
2352
2353 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002354 * Launches the intent referred by the clicked shortcut.
2355 *
2356 * @param v The view representing the clicked shortcut.
2357 */
2358 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002359 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2360 // view has detached (it's possible for this to happen if the view is removed mid touch).
2361 if (v.getWindowToken() == null) {
2362 return;
2363 }
2364
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002365 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002366 return;
2367 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002368
Adam Cohen1697b792013-09-17 19:08:21 -07002369 if (v instanceof Workspace) {
2370 if (mWorkspace.isInOverviewMode()) {
2371 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002372 }
2373 return;
2374 }
2375
2376 if (v instanceof CellLayout) {
2377 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002378 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002379 }
2380 }
2381
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002383 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002384 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002386 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002387 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002388 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002389 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002390 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002391 }
2392 }
2393
Michael Jurka0e260592010-06-30 17:07:39 -07002394 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002395 return false;
2396 }
2397
Michael Jurkaaf442092010-06-10 17:01:57 -07002398 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002399 * Event handler for the search button
2400 *
2401 * @param v The view that was clicked.
2402 */
2403 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002404 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2405
Amith Yamasania135ba82011-08-09 17:42:01 -07002406 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002407 }
2408
2409 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002410 * Event handler for the voice button
2411 *
2412 * @param v The view that was clicked.
2413 */
2414 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002415 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002416
Bjorn Bringertc459e522013-06-07 19:36:01 +01002417 startVoice();
2418 }
2419
2420 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002421 try {
2422 final SearchManager searchManager =
2423 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2424 ComponentName activityName = searchManager.getGlobalSearchActivity();
2425 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002426 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002427 if (activityName != null) {
2428 intent.setPackage(activityName.getPackageName());
2429 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002430 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002431 } catch (ActivityNotFoundException e) {
2432 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002433 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002434 startActivitySafely(null, intent, "onClickVoiceButton");
2435 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002436 }
2437
2438 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002439 * Event handler for the "grid" button that appears on the home screen, which
2440 * enters all apps mode.
2441 *
2442 * @param v The view that was clicked.
2443 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002444 protected void onClickAllAppsButton(View v) {
2445 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2446 if (isAllAppsVisible()) {
2447 showWorkspace(true);
2448 } else {
2449 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2450 }
2451 }
2452
2453 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002454 * Event handler for a paged view icon click.
2455 * @param v The view that was clicked.
2456 * @param appInfo The {link AppInfo} of the view.
2457 */
2458 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2459 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2460 startActivitySafely(v, appInfo.intent, appInfo);
2461 getStats().recordLaunch(appInfo.intent);
2462 }
2463
2464 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002465 * Event handler for an app shortcut click.
2466 *
2467 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2468 */
2469 protected void onClickAppShortcut(View v) {
2470 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2471 Object tag = v.getTag();
2472 if (!(tag instanceof ShortcutInfo)) {
2473 throw new IllegalArgumentException("Input must be a Shortcut");
2474 }
2475
2476 // Open shortcut
2477 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2478 final Intent intent = shortcut.intent;
2479
2480 // Check for special shortcuts
2481 if (intent.getComponent() != null) {
2482 final String shortcutClass = intent.getComponent().getClassName();
2483
2484 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2485 MemoryDumpActivity.startDump(this);
2486 return;
2487 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2488 toggleShowWeightWatcher();
2489 return;
2490 }
2491 }
2492
2493 // Start activities
2494 int[] pos = new int[2];
2495 v.getLocationOnScreen(pos);
2496 intent.setSourceBounds(new Rect(pos[0], pos[1],
2497 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2498
2499 boolean success = startActivitySafely(v, intent, tag);
2500
2501 mStats.recordLaunch(intent, shortcut);
2502
2503 if (success && v instanceof BubbleTextView) {
2504 mWaitingForResume = (BubbleTextView) v;
2505 mWaitingForResume.setStayPressed(true);
2506 }
2507 }
2508
2509 /**
2510 * Event handler for a folder icon click.
2511 *
2512 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2513 */
2514 protected void onClickFolderIcon(View v) {
2515 if (LOGD) Log.d(TAG, "onClickFolder");
2516 if (!(v instanceof FolderIcon)){
2517 throw new IllegalArgumentException("Input must be a FolderIcon");
2518 }
2519
2520 FolderIcon folderIcon = (FolderIcon) v;
2521 final FolderInfo info = folderIcon.getFolderInfo();
2522 Folder openFolder = mWorkspace.getFolderForTag(info);
2523
2524 // If the folder info reports that the associated folder is open, then verify that
2525 // it is actually opened. There have been a few instances where this gets out of sync.
2526 if (info.opened && openFolder == null) {
2527 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2528 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2529 info.opened = false;
2530 }
2531
2532 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2533 // Close any open folder
2534 closeFolder();
2535 // Open the requested folder
2536 openFolder(folderIcon);
2537 } else {
2538 // Find the open folder...
2539 int folderScreen;
2540 if (openFolder != null) {
2541 folderScreen = mWorkspace.getPageForView(openFolder);
2542 // .. and close it
2543 closeFolder(openFolder);
2544 if (folderScreen != mWorkspace.getCurrentPage()) {
2545 // Close any folder open on the current screen
2546 closeFolder();
2547 // Pull the folder onto this screen
2548 openFolder(folderIcon);
2549 }
2550 }
2551 }
Michael Jurka5130e402011-10-13 04:55:35 -07002552 }
2553
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002554 /**
2555 * Event handler for the (Add) Widgets button that appears after a long press
2556 * on the home screen.
2557 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002558 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002559 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002560 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2561 }
2562
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002563 /**
2564 * Event handler for the wallpaper picker button that appears after a long press
2565 * on the home screen.
2566 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002567 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002568 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2569 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2570 pickWallpaper.setComponent(getWallpaperPickerComponent());
2571 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2572 }
2573
2574 /**
2575 * Event handler for a click on the settings button that appears after a long press
2576 * on the home screen.
2577 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002578 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002579 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2580 }
2581
Michael Jurka5130e402011-10-13 04:55:35 -07002582 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002583 // Provide the same haptic feedback that the system offers for virtual keys.
2584 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002585 }
2586
Adam Cohen61f560d2013-09-30 15:58:20 -07002587 public void performHapticFeedbackOnTouchDown(View v) {
2588 // Provide the same haptic feedback that the system offers for virtual keys.
2589 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2590 }
2591
2592 public View.OnTouchListener getHapticFeedbackTouchListener() {
2593 if (mHapticFeedbackTouchListener == null) {
2594 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2595 @Override
2596 public boolean onTouch(View v, MotionEvent event) {
2597 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2598 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2599 }
2600 return false;
2601 }
2602 };
2603 }
2604 return mHapticFeedbackTouchListener;
2605 }
2606
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002607 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002608 if (!DISABLE_MARKET_BUTTON) {
2609 if (mAppMarketIntent != null) {
2610 startActivitySafely(v, mAppMarketIntent, "app market");
2611 } else {
2612 Log.e(TAG, "Invalid app market intent.");
2613 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002614 }
2615 }
2616
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002617 public void onDragStarted(View view) {}
2618
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002619 /**
2620 * Called when the user stops interacting with the launcher.
2621 * This implies that the user is now on the homescreen and is not doing housekeeping.
2622 */
2623 protected void onInteractionEnd() {}
2624
2625 /**
2626 * Called when the user starts interacting with the launcher.
2627 * The possible interactions are:
2628 * - open all apps
2629 * - reorder an app shortcut, or a widget
2630 * - open the overview mode.
2631 * This is a good time to stop doing things that only make sense
2632 * when the user is on the homescreen and not doing housekeeping.
2633 */
2634 protected void onInteractionBegin() {}
2635
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002636 void startApplicationDetailsActivity(ComponentName componentName) {
2637 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002638 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2639 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002640 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2641 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002642 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002643 }
2644
Michael Jurka1e2f4652013-07-08 18:03:46 -07002645 // returns true if the activity was started
2646 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002647 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002648 // System applications cannot be installed. For now, show a toast explaining that.
2649 // We may give them the option of disabling apps this way.
2650 int messageId = R.string.uninstall_system_app_text;
2651 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002652 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002653 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002654 String packageName = componentName.getPackageName();
2655 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002656 Intent intent = new Intent(
2657 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002658 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2659 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002660 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002661 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002662 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002663 }
2664
Michael Jurka86a720e2012-05-09 11:23:23 -07002665 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002666 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002667 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002668 // Only launch using the new animation if the shortcut has not opted out (this is a
2669 // private contract between launcher and may be ignored in the future).
2670 boolean useLaunchAnimation = (v != null) &&
2671 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002672 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2673 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002674
Kenny Guy1317e2d2014-05-08 18:52:50 +01002675 UserHandleCompat user = null;
2676 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2677 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2678 user = userManager.getUserForSerialNumber(serialNumber);
2679 }
2680
2681 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002682 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002683 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2684 v.getMeasuredWidth(), v.getMeasuredHeight());
Kenny Guy1317e2d2014-05-08 18:52:50 +01002685 optsBundle = opts.toBundle();
2686 }
2687
2688 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2689 // Could be launching some bookkeeping activity
2690 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002691 } else {
Kenny Guy1317e2d2014-05-08 18:52:50 +01002692 launcherApps.startActivityForProfile(intent.getComponent(),
2693 intent.getSourceBounds(), optsBundle, user);
Winson Chungc7450e32012-04-17 17:34:08 -07002694 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002695 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002696 } catch (SecurityException e) {
2697 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002698 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002699 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002700 "or use the exported attribute for this activity. "
2701 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002702 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002703 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002704 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002705
Michael Jurka86a720e2012-05-09 11:23:23 -07002706 boolean startActivitySafely(View v, Intent intent, Object tag) {
2707 boolean success = false;
2708 try {
2709 success = startActivity(v, intent, tag);
2710 } catch (ActivityNotFoundException e) {
2711 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2712 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2713 }
2714 return success;
2715 }
2716
Adam Cohen268c4752012-06-06 17:47:33 -07002717 /**
2718 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2719 * in the DragLayer in the exact absolute location of the original FolderIcon.
2720 */
2721 private void copyFolderIconToImage(FolderIcon fi) {
2722 final int width = fi.getMeasuredWidth();
2723 final int height = fi.getMeasuredHeight();
2724
2725 // Lazy load ImageView, Bitmap and Canvas
2726 if (mFolderIconImageView == null) {
2727 mFolderIconImageView = new ImageView(this);
2728 }
2729 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2730 mFolderIconBitmap.getHeight() != height) {
2731 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2732 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2733 }
2734
2735 DragLayer.LayoutParams lp;
2736 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2737 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2738 } else {
2739 lp = new DragLayer.LayoutParams(width, height);
2740 }
2741
Adam Cohen307fe232012-08-16 17:55:58 -07002742 // The layout from which the folder is being opened may be scaled, adjust the starting
2743 // view size by this scale factor.
2744 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002745 lp.customPosition = true;
2746 lp.x = mRectForFolderAnimation.left;
2747 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002748 lp.width = (int) (scale * width);
2749 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002750
2751 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2752 fi.draw(mFolderIconCanvas);
2753 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002754 if (fi.getFolder() != null) {
2755 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2756 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002757 }
Adam Cohen268c4752012-06-06 17:47:33 -07002758 // Just in case this image view is still in the drag layer from a previous animation,
2759 // we remove it and re-add it.
2760 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2761 mDragLayer.removeView(mFolderIconImageView);
2762 }
2763 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002764 if (fi.getFolder() != null) {
2765 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002766 }
Adam Cohen268c4752012-06-06 17:47:33 -07002767 }
2768
Adam Cohen2801caf2011-05-13 20:57:39 -07002769 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002770 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002771 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2772 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2773 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2774
Adam Cohenc51934b2011-07-26 21:07:43 -07002775 FolderInfo info = (FolderInfo) fi.getTag();
2776 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2777 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002778 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2779 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002780 }
2781
Adam Cohen268c4752012-06-06 17:47:33 -07002782 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2783 copyFolderIconToImage(fi);
2784 fi.setVisibility(View.INVISIBLE);
2785
Michael Jurka2ecf9952012-06-18 12:52:28 -07002786 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002787 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002788 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2789 oa.start();
2790 }
2791
Adam Cohen268c4752012-06-06 17:47:33 -07002792 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002793 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002794 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2795 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2796 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2797
Adam Cohen268c4752012-06-06 17:47:33 -07002798 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002799
Adam Cohen268c4752012-06-06 17:47:33 -07002800 // We remove and re-draw the FolderIcon in-case it has changed
2801 mDragLayer.removeView(mFolderIconImageView);
2802 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002803 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002804 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002805 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002806 oa.addListener(new AnimatorListenerAdapter() {
2807 @Override
2808 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002809 if (cl != null) {
2810 cl.clearFolderLeaveBehind();
2811 // Remove the ImageView copy of the FolderIcon and make the original visible.
2812 mDragLayer.removeView(mFolderIconImageView);
2813 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002814 }
2815 }
2816 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002817 oa.start();
2818 }
2819
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002820 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002821 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002822 * is animated relative to the specified View. If the View is null, no animation
2823 * is played.
2824 *
2825 * @param folderInfo The FolderInfo describing the folder to open.
2826 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002827 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002828 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002829 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002830
Adam Cohena9cf38f2011-05-02 15:36:58 -07002831 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002832
Adam Cohen4554ee12011-08-03 16:13:21 -07002833 // Just verify that the folder hasn't already been added to the DragLayer.
2834 // There was a one-off crash where the folder had a parent already.
2835 if (folder.getParent() == null) {
2836 mDragLayer.addView(folder);
2837 mDragController.addDropTarget((DropTarget) folder);
2838 } else {
2839 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2840 folder.getParent() + ").");
2841 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002842 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002843 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002844
2845 // Notify the accessibility manager that this folder "window" has appeared and occluded
2846 // the workspace items
2847 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2848 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002849 }
2850
2851 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002852 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002853 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002854 if (folder.isEditingName()) {
2855 folder.dismissEditingName();
2856 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002857 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002858
2859 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002860 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002861 }
2862 }
2863
2864 void closeFolder(Folder folder) {
2865 folder.getInfo().opened = false;
2866
2867 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2868 if (parent != null) {
2869 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2870 shrinkAndFadeInFolderIcon(fi);
2871 }
2872 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002873
2874 // Notify the accessibility manager that this folder "window" has disappeard and no
2875 // longer occludeds the workspace items
2876 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002877 }
2878
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002879 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002880 if (!isDraggingEnabled()) return false;
2881 if (isWorkspaceLocked()) return false;
2882 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002883
Adam Cohen1697b792013-09-17 19:08:21 -07002884 if (v instanceof Workspace) {
2885 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002886 if (mWorkspace.enterOverviewMode()) {
2887 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2888 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2889 return true;
2890 } else {
2891 return false;
2892 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07002893 } else {
2894 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07002895 }
Adam Cohen1697b792013-09-17 19:08:21 -07002896 }
2897
Adam Cohene0aaa0d2014-05-12 12:44:22 -07002898 CellLayout.CellInfo longClickCellInfo = null;
2899 View itemUnderLongClick = null;
2900 if (v.getTag() instanceof ItemInfo) {
2901 ItemInfo info = (ItemInfo) v.getTag();
2902 longClickCellInfo = new CellLayout.CellInfo(v, info);;
2903 itemUnderLongClick = longClickCellInfo.cell;
2904 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002905 }
2906
Winson Chung3d503fb2011-07-13 17:25:49 -07002907 // The hotseat touch handling does not go through Workspace, and we always allow long press
2908 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05002909 final boolean inHotseat = isHotseatLayout(v);
2910 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002911 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002912 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002913 // User long pressed on empty space
2914 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2915 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07002916 if (mWorkspace.isInOverviewMode()) {
2917 mWorkspace.startReordering(v);
2918 } else {
2919 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002920 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002921 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002922 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2923 mHotseat.getOrderInHotseat(
2924 longClickCellInfo.cellX,
2925 longClickCellInfo.cellY));
2926 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002927 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002928 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002929 }
2930 }
2931 }
2932 return true;
2933 }
2934
Winson Chung3d503fb2011-07-13 17:25:49 -07002935 boolean isHotseatLayout(View layout) {
2936 return mHotseat != null && layout != null &&
2937 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2938 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002939
Winson Chung3d503fb2011-07-13 17:25:49 -07002940 /**
2941 * Returns the CellLayout of the specified container at the specified screen.
2942 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002943 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002944 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2945 if (mHotseat != null) {
2946 return mHotseat.getLayout();
2947 } else {
2948 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002949 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002950 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002951 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002952 }
2953 }
2954
Daniel Sandler843e8602010-06-07 14:59:01 -04002955 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002956 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002957 }
2958
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002959 /**
2960 * Helper method for the cameraZoomIn/cameraZoomOut animations
2961 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002962 * @param scaleFactor The scale factor used for the zoom
2963 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002964 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002965 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002966 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002967 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002968
Craig Mautner360310b2012-10-26 15:13:08 -07002969 private void setWorkspaceBackground(boolean workspace) {
2970 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002971 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002972 }
2973
Selim Cinek3a8a8f72014-01-16 10:38:38 -08002974 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002975 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2976 int curflags = getWindow().getAttributes().flags
2977 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2978 if (wpflags != curflags) {
2979 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2980 }
Craig Mautner360310b2012-10-26 15:13:08 -07002981 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002982 }
2983
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002984 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2985 if (v instanceof LauncherTransitionable) {
2986 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2987 }
2988 }
2989
Michael Jurkabed61d22012-02-14 22:51:29 -08002990 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2991 if (v instanceof LauncherTransitionable) {
2992 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2993 }
Winson Chung70442722012-02-10 15:43:22 -08002994
2995 // Update the workspace transition step as well
2996 dispatchOnLauncherTransitionStep(v, 0f);
2997 }
2998
2999 private void dispatchOnLauncherTransitionStep(View v, float t) {
3000 if (v instanceof LauncherTransitionable) {
3001 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3002 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003003 }
3004
3005 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3006 if (v instanceof LauncherTransitionable) {
3007 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3008 }
Winson Chung70442722012-02-10 15:43:22 -08003009
3010 // Update the workspace transition step as well
3011 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003012 }
3013
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003014 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003015 * Things to test when changing the following seven functions.
3016 * - Home from workspace
3017 * - from center screen
3018 * - from other screens
3019 * - Home from all apps
3020 * - from center screen
3021 * - from other screens
3022 * - Back from all apps
3023 * - from center screen
3024 * - from other screens
3025 * - Launch app from workspace and quit
3026 * - with back
3027 * - with home
3028 * - Launch app from all apps and quit
3029 * - with back
3030 * - with home
3031 * - Go to a screen that's not the default, then all
3032 * apps, and launch and app, and go back
3033 * - with back
3034 * -with home
3035 * - On workspace, long press power and go back
3036 * - with back
3037 * - with home
3038 * - On all apps, long press power and go back
3039 * - with back
3040 * - with home
3041 * - On workspace, power off
3042 * - On all apps, power off
3043 * - Launch an app and turn off the screen while in that app
3044 * - Go back with home key
3045 * - Go back with back key TODO: make this not go to workspace
3046 * - From all apps
3047 * - From workspace
3048 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3049 * - From all apps
3050 * - From the center workspace
3051 * - From another workspace
3052 */
3053
3054 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003055 * Zoom the camera out from the workspace to reveal 'toView'.
3056 * Assumes that the view to show is anchored at either the very top or very bottom
3057 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003058 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003059 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003060 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3061 showAppsCustomizeHelper(animated, springLoaded, contentType);
3062 }
3063 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3064 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003065 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003066 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003067 mStateAnimation.cancel();
3068 mStateAnimation = null;
3069 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003070 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003071
Winson Chungf0ea4d32011-06-06 14:27:16 -07003072 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3073 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3074 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003075 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003076 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003077 final int startDelay =
3078 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003079
Michael Jurkab3e22d92011-10-31 15:58:33 -07003080 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003081
Michael Jurkad74c9842011-07-10 12:44:21 -07003082 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003083 Animator workspaceAnim =
3084 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003085 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003086 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3087 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003088 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3089 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003090
3091 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003092 toView.setScaleX(scale);
3093 toView.setScaleY(scale);
3094 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3095 scaleAnim.
3096 scaleX(1f).scaleY(1f).
3097 setDuration(duration).
3098 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003099
Winson Chungf0ea4d32011-06-06 14:27:16 -07003100 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003101 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003102 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003103 .ofFloat(toView, "alpha", 0f, 1f)
3104 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003105 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003106 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3107 @Override
3108 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003109 if (animation == null) {
3110 throw new RuntimeException("animation is null");
3111 }
Winson Chung70442722012-02-10 15:43:22 -08003112 float t = (Float) animation.getAnimatedValue();
3113 dispatchOnLauncherTransitionStep(fromView, t);
3114 dispatchOnLauncherTransitionStep(toView, t);
3115 }
3116 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003117
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003118 // toView should appear right at the end of the workspace shrink
3119 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003120 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003121 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003122 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003123
3124 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003125 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003126 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003127 // Prepare the position
3128 toView.setTranslationX(0.0f);
3129 toView.setTranslationY(0.0f);
3130 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003131 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003132 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003133 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003134 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003135 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3136 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003137
Winson Chungc7d2b602012-05-16 17:02:20 -07003138 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003139 if (mSearchDropTargetBar != null) {
3140 mSearchDropTargetBar.hideSearchBar(false);
3141 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003142 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003143 });
3144
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003145 if (workspaceAnim != null) {
3146 mStateAnimation.play(workspaceAnim);
3147 }
Michael Jurka1899a362011-11-03 13:50:45 -07003148
3149 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003150
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003151 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3152 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003153
3154 // If any of the objects being animated haven't been measured/laid out
3155 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003156 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003157 (mWorkspace.getMeasuredWidth() == 0) ||
3158 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003159 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003160 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003161
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003162 final AnimatorSet stateAnimation = mStateAnimation;
3163 final Runnable startAnimRunnable = new Runnable() {
3164 public void run() {
3165 // Check that mStateAnimation hasn't changed while
3166 // we waited for a layout/draw pass
3167 if (mStateAnimation != stateAnimation)
3168 return;
3169 setPivotsForZoom(toView, scale);
3170 dispatchOnLauncherTransitionStart(fromView, animated, false);
3171 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003172 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003173 }
3174 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003175 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003176 final ViewTreeObserver observer = toView.getViewTreeObserver();
3177 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3178 public void onGlobalLayout() {
3179 startAnimRunnable.run();
3180 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3181 }
3182 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003183 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003184 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003185 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003186 } else {
3187 toView.setTranslationX(0.0f);
3188 toView.setTranslationY(0.0f);
3189 toView.setScaleX(1.0f);
3190 toView.setScaleY(1.0f);
3191 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003192 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003193
Daniel Sandlere4f98912013-06-25 15:13:26 -04003194 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003195 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003196 if (mSearchDropTargetBar != null) {
3197 mSearchDropTargetBar.hideSearchBar(false);
3198 }
Michael Jurkaabded662011-03-04 12:06:57 -08003199 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003200 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003201 dispatchOnLauncherTransitionStart(fromView, animated, false);
3202 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003203 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003204 dispatchOnLauncherTransitionStart(toView, animated, false);
3205 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003206 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003207 }
3208
3209 /**
3210 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003211 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003212 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003213 */
Adam Cohened307df2013-10-02 09:37:31 -07003214 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003215 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003216
Michael Jurkab3e22d92011-10-31 15:58:33 -07003217 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003218 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003219 mStateAnimation.cancel();
3220 mStateAnimation = null;
3221 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003222 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003223
Winson Chungf0ea4d32011-06-06 14:27:16 -07003224 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003225 final int fadeOutDuration =
3226 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003227 final float scaleFactor = (float)
3228 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3229 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003230 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003231 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003232 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003233 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3234 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003235 toState, animated, stagger, -1);
3236 } else if (toState == Workspace.State.SPRING_LOADED ||
3237 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003238 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003239 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003240 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003241
Michael Jurkab3e22d92011-10-31 15:58:33 -07003242 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003243 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003244 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003245 final LauncherViewPropertyAnimator scaleAnim =
3246 new LauncherViewPropertyAnimator(fromView);
3247 scaleAnim.
3248 scaleX(scaleFactor).scaleY(scaleFactor).
3249 setDuration(duration).
3250 setInterpolator(new Workspace.ZoomInInterpolator());
3251
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003252 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003253 .ofFloat(fromView, "alpha", 1f, 0f)
3254 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003255 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003256 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3257 @Override
3258 public void onAnimationUpdate(ValueAnimator animation) {
3259 float t = 1f - (Float) animation.getAnimatedValue();
3260 dispatchOnLauncherTransitionStep(fromView, t);
3261 dispatchOnLauncherTransitionStep(toView, t);
3262 }
3263 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003264
Michael Jurka2ecf9952012-06-18 12:52:28 -07003265 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003266
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003267 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3268 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003269 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003270
3271 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003272 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003273 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003274 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003275 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3276 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003277 if (onCompleteRunnable != null) {
3278 onCompleteRunnable.run();
3279 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003280 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003281 }
3282 });
3283
Winson Chungf0ea4d32011-06-06 14:27:16 -07003284 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003285 if (workspaceAnim != null) {
3286 mStateAnimation.play(workspaceAnim);
3287 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003288 dispatchOnLauncherTransitionStart(fromView, animated, true);
3289 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003290 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003291 } else {
3292 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003293 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003294 dispatchOnLauncherTransitionStart(fromView, animated, true);
3295 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003296 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003297 dispatchOnLauncherTransitionStart(toView, animated, true);
3298 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003299 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003300 }
3301
Michael Jurkae326f182011-11-21 14:05:46 -08003302 @Override
3303 public void onTrimMemory(int level) {
3304 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003305 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003306 mAppsCustomizeTabHost.onTrimMemory();
3307 }
3308 }
3309
Adam Cohened307df2013-10-02 09:37:31 -07003310 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003311 showWorkspace(animated, null);
3312 }
3313
Adam Cohened307df2013-10-02 09:37:31 -07003314 protected void showWorkspace() {
3315 showWorkspace(true);
3316 }
3317
Adam Cohened66b2b2012-01-23 17:28:51 -08003318 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003319 if (mWorkspace.isInOverviewMode()) {
3320 mWorkspace.exitOverviewMode(animated);
3321 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003322 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003323 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003324 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003325 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003326
Winson Chungc7d2b602012-05-16 17:02:20 -07003327 // Show the search bar (only animate if we were showing the drop target bar in spring
3328 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003329 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003330 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003331 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003332
Michael Jurkab3e22d92011-10-31 15:58:33 -07003333 // Set focus to the AppsCustomize button
3334 if (mAllAppsButton != null) {
3335 mAllAppsButton.requestFocus();
3336 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003337 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003338
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003339 // Change the state *after* we've called all the transition code
3340 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003341
Winson Chung5fb63472011-02-02 17:03:37 -08003342 // Resume the auto-advance of widgets
3343 mUserPresent = true;
3344 updateRunning();
3345
alanv1d4fde62012-10-17 13:15:47 -07003346 // Send an accessibility event to announce the context change
3347 getWindow().getDecorView()
3348 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003349
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003350 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003351 }
3352
Adam Cohened307df2013-10-02 09:37:31 -07003353 void showOverviewMode(boolean animated) {
3354 mWorkspace.setVisibility(View.VISIBLE);
3355 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3356 mState = State.WORKSPACE;
3357 onWorkspaceShown(animated);
3358 }
3359
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003360 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003361 }
3362
Winson Chung82963d52013-10-09 11:20:57 -07003363 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3364 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003365 if (mState != State.WORKSPACE) return;
3366
Winson Chung82963d52013-10-09 11:20:57 -07003367 if (resetPageToZero) {
3368 mAppsCustomizeTabHost.reset();
3369 }
Winson Chungc58497e2013-09-03 17:48:37 -07003370 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003371 mAppsCustomizeTabHost.requestFocus();
3372
Michael Jurkab3e22d92011-10-31 15:58:33 -07003373 // Change the state *after* we've called all the transition code
3374 mState = State.APPS_CUSTOMIZE;
3375
3376 // Pause the auto-advance of widgets until we are out of AllApps
3377 mUserPresent = false;
3378 updateRunning();
3379 closeFolder();
3380
3381 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003382 getWindow().getDecorView()
3383 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003384 }
3385
Adam Cohen7777d962011-08-18 18:58:38 -07003386 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003387 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003388 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003389 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003390 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003391 }
Adam Cohen7777d962011-08-18 18:58:38 -07003392
Adam Cohenad4e15c2013-10-17 16:21:35 -07003393 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003394 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003395 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3396
Winson Chunge7a03942011-08-05 15:05:12 -07003397 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003398 @Override
3399 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003400 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003401 // Before we show workspace, hide all apps again because
3402 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3403 // clean up our state transition functions
3404 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003405 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003406 } else {
3407 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003408 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003409 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003410 }, delay);
3411
Winson Chung557d6ed2011-07-08 15:34:52 -07003412 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003413
Michael Jurkad3ef3062010-11-23 16:23:58 -08003414 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003415 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003416 final boolean animated = true;
3417 final boolean springLoaded = true;
3418 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003419 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003420 }
3421 // Otherwise, we are not in spring loaded mode, so don't do anything.
3422 }
3423
Michael Jurkab3e22d92011-10-31 15:58:33 -07003424 void lockAllApps() {
3425 // TODO
3426 }
3427
3428 void unlockAllApps() {
3429 // TODO
3430 }
3431
Winson Chungf0ea4d32011-06-06 14:27:16 -07003432 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003433 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003434 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003435 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003436 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003437 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003438 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003439 int duration = 0;
3440 if (mSearchDropTargetBar != null) {
3441 duration = mSearchDropTargetBar.getTransitionInDuration();
3442 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003443 mHotseat.animate().alpha(1f).setDuration(duration);
3444 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003445 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003446 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003447 }
3448 }
3449 }
3450
3451 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003452 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003453 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003454 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003455 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003456 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003457 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003458 int duration = 0;
3459 if (mSearchDropTargetBar != null) {
3460 duration = mSearchDropTargetBar.getTransitionOutDuration();
3461 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003462 mHotseat.animate().alpha(0f).setDuration(duration);
3463 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003464 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003465 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003466 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003467 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003468 }
3469
Patrick Dubroy5f445422011-02-18 14:35:21 -08003470 /**
3471 * Add an item from all apps or customize onto the given workspace screen.
3472 * If layout is null, add to the current screen.
3473 */
3474 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003475 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003476 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003477 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003478 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003479
Winson Chungdff8ebb2011-09-08 17:25:31 -07003480 /** Maps the current orientation to an index for referencing orientation correct global icons */
3481 private int getCurrentOrientationIndexForGlobalIcons() {
3482 // default - 0, landscape - 1
3483 switch (getResources().getConfiguration().orientation) {
3484 case Configuration.ORIENTATION_LANDSCAPE:
3485 return 1;
3486 default:
3487 return 0;
3488 }
3489 }
3490
Michael Jurkaae65ee32012-04-30 11:45:54 -07003491 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003492 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003493 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003494 // Look for the toolbar icon specified in the activity meta-data
3495 Bundle metaData = packageManager.getActivityInfo(
3496 activityName, PackageManager.GET_META_DATA).metaData;
3497 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003498 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003499 if (iconResId != 0) {
3500 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003501 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003502 }
3503 }
3504 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003505 // This can happen if the activity defines an invalid drawable
3506 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3507 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003508 } catch (Resources.NotFoundException nfe) {
3509 // This can happen if the activity defines an invalid drawable
3510 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3511 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003512 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003513 return null;
3514 }
3515
3516 // if successful in getting icon, return it; otherwise, set button to use default drawable
3517 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003518 int buttonId, ComponentName activityName, int fallbackDrawableId,
3519 String toolbarResourceName) {
3520 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003521 Resources r = getResources();
3522 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3523 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003524
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003525 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003526 // If we were unable to find the icon via the meta-data, use a generic one
3527 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003528 toolbarIcon = r.getDrawable(fallbackDrawableId);
3529 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003530 if (button != null) {
3531 button.setCompoundDrawables(toolbarIcon, null, null, null);
3532 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003533 return null;
3534 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003535 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003536 if (button != null) {
3537 button.setCompoundDrawables(toolbarIcon, null, null, null);
3538 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003539 return toolbarIcon.getConstantState();
3540 }
3541 }
3542
3543 // if successful in getting icon, return it; otherwise, set button to use default drawable
3544 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003545 int buttonId, ComponentName activityName, int fallbackDrawableId,
3546 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003547 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003548 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003549
Michael Jurka19e0fc52011-07-22 18:00:21 -07003550 if (button != null) {
3551 // If we were unable to find the icon via the meta-data, use a
3552 // generic one
3553 if (toolbarIcon == null) {
3554 button.setImageResource(fallbackDrawableId);
3555 } else {
3556 button.setImageDrawable(toolbarIcon);
3557 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003558 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003559
3560 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3561
Michael Jurka0423dcf2010-10-05 14:56:18 -07003562 }
3563
Winson Chung1b884092012-06-08 17:13:02 -07003564 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003565 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003566 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003567 }
3568
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003569 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003570 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003571 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003572 }
3573
Winson Chungbb185bd2011-11-21 12:31:42 -08003574 private void invalidatePressedFocusedStates(View container, View button) {
3575 if (container instanceof HolographicLinearLayout) {
3576 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3577 layout.invalidatePressedFocusedStates();
3578 } else if (button instanceof HolographicImageView) {
3579 HolographicImageView view = (HolographicImageView) button;
3580 view.invalidatePressedFocusedStates();
3581 }
3582 }
3583
Cristina Stancu476493b2013-08-07 17:20:14 +01003584 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003585 if (mQsb == null) {
3586 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3587 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003588 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003589 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003590 }
3591
3592 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003593 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003594 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003595 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003596 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003597
Winson Chung1cad91e2011-05-25 17:41:01 -07003598 final SearchManager searchManager =
3599 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3600 ComponentName activityName = searchManager.getGlobalSearchActivity();
3601 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003602 int coi = getCurrentOrientationIndexForGlobalIcons();
3603 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003604 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3605 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3606 if (sGlobalSearchIcon[coi] == null) {
3607 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3608 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3609 TOOLBAR_ICON_METADATA_NAME);
3610 }
3611
Winson Chungc51db6a2011-10-05 11:44:49 -07003612 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3613 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003614 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003615 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003616 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003617 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003618 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3619 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003620 if (searchButton != null) searchButton.setVisibility(View.GONE);
3621 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003622 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003623 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003624 }
3625 }
3626
Cristina Stancu476493b2013-08-07 17:20:14 +01003627 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003628 final View searchButtonContainer = findViewById(R.id.search_button_container);
3629 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003630 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003631 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003632 }
3633
Cristina Stancu476493b2013-08-07 17:20:14 +01003634 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003635 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003636 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003637
Winson Chungc51db6a2011-10-05 11:44:49 -07003638 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003639 final SearchManager searchManager =
3640 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3641 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3642
3643 ComponentName activityName = null;
3644 if (globalSearchActivity != null) {
3645 // Check if the global search activity handles voice search
3646 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3647 intent.setPackage(globalSearchActivity.getPackageName());
3648 activityName = intent.resolveActivity(getPackageManager());
3649 }
3650
3651 if (activityName == null) {
3652 // Fallback: check if an activity other than the global search activity
3653 // resolves this
3654 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3655 activityName = intent.resolveActivity(getPackageManager());
3656 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003657 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003658 int coi = getCurrentOrientationIndexForGlobalIcons();
3659 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003660 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3661 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3662 if (sVoiceSearchIcon[coi] == null) {
3663 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3664 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3665 TOOLBAR_ICON_METADATA_NAME);
3666 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003667 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003668 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003669 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003670 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003671 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003672 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003673 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003674 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003675 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003676 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003677 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003678 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003679
Cristina Stancu476493b2013-08-07 17:20:14 +01003680 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003681 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3682 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003683 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003684 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003685 }
3686
Winson Chung5841efa2013-09-30 18:06:44 -07003687 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003688 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3689 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003690 boolean visible = !forceDisableVoiceButtonProxy &&
3691 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003692 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003693 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003694 }
3695 }
Winson Chung5841efa2013-09-30 18:06:44 -07003696
3697 /**
3698 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3699 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3700 */
3701 public void disableVoiceButtonProxy(boolean disabled) {
3702 updateVoiceButtonProxyVisible(disabled);
3703 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003704 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003705 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003706 */
3707 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003708 if (!DISABLE_MARKET_BUTTON) {
3709 final View marketButton = findViewById(R.id.market_button);
3710 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3711 // Find the app market activity by resolving an intent.
3712 // (If multiple app markets are installed, it will return the ResolverActivity.)
3713 ComponentName activityName = intent.resolveActivity(getPackageManager());
3714 if (activityName != null) {
3715 int coi = getCurrentOrientationIndexForGlobalIcons();
3716 mAppMarketIntent = intent;
3717 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3718 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3719 TOOLBAR_ICON_METADATA_NAME);
3720 marketButton.setVisibility(View.VISIBLE);
3721 } else {
3722 // We should hide and disable the view so that we don't try and restore the visibility
3723 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3724 marketButton.setVisibility(View.GONE);
3725 marketButton.setEnabled(false);
3726 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003727 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003728 }
3729
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003730 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003731 if (!DISABLE_MARKET_BUTTON) {
3732 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3733 Resources r = getResources();
3734 Drawable marketIconDrawable = d.newDrawable(r);
3735 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3736 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3737 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003738
Winson Chungd64a6662013-09-30 11:06:59 -07003739 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3740 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003741 }
3742
Michael Jurkad7c28052012-04-27 15:43:36 -07003743 @Override
3744 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003745 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003746 final List<CharSequence> text = event.getText();
3747 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003748 // Populate event with a fake title based on the current state.
3749 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003750 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003751 } else {
3752 text.add(getString(R.string.all_apps_home_button_label));
3753 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003754 return result;
3755 }
3756
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003757 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003758 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003759 */
3760 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3761 @Override
3762 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003763 closeSystemDialogs();
3764 }
3765 }
3766
3767 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003768 * Receives notifications whenever the appwidgets are reset.
3769 */
3770 private class AppWidgetResetObserver extends ContentObserver {
3771 public AppWidgetResetObserver() {
3772 super(new Handler());
3773 }
3774
3775 @Override
3776 public void onChange(boolean selfChange) {
3777 onAppWidgetReset();
3778 }
3779 }
3780
3781 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003782 * If the activity is currently paused, signal that we need to run the passed Runnable
3783 * in onResume.
3784 *
3785 * This needs to be called from incoming places where resources might have been loaded
3786 * while we are paused. That is becaues the Configuration might be wrong
3787 * when we're not running, and if it comes back to what it was when we
3788 * were paused, we are not restarted.
3789 *
3790 * Implementation of the method from LauncherModel.Callbacks.
3791 *
3792 * @return true if we are currently paused. The caller might be able to
3793 * skip some work in that case since we will come back again.
3794 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003795 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003796 if (mPaused) {
3797 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003798 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003799 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003800 }
3801 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003802 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003803 return true;
3804 } else {
3805 return false;
3806 }
3807 }
3808
Michael Jurkac402cd92013-05-20 15:49:32 +02003809 private boolean waitUntilResume(Runnable run) {
3810 return waitUntilResume(run, false);
3811 }
3812
Michael Jurka1e2f4652013-07-08 18:03:46 -07003813 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003814 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003815 }
3816
Michael Jurka7607c2f2013-04-03 14:33:19 -07003817 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003818 * If the activity is currently paused, signal that we need to re-run the loader
3819 * in onResume.
3820 *
3821 * This needs to be called from incoming places where resources might have been loaded
3822 * while we are paused. That is becaues the Configuration might be wrong
3823 * when we're not running, and if it comes back to what it was when we
3824 * were paused, we are not restarted.
3825 *
3826 * Implementation of the method from LauncherModel.Callbacks.
3827 *
3828 * @return true if we are currently paused. The caller might be able to
3829 * skip some work in that case since we will come back again.
3830 */
3831 public boolean setLoadOnResume() {
3832 if (mPaused) {
3833 Log.i(TAG, "setLoadOnResume");
3834 mOnResumeNeedsLoad = true;
3835 return true;
3836 } else {
3837 return false;
3838 }
3839 }
3840
3841 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003842 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003843 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003844 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003845 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003846 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003847 } else {
3848 return SCREEN_COUNT / 2;
3849 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003850 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003851
Joe Onorato9c1289c2009-08-17 11:03:03 -04003852 /**
3853 * Refreshes the shortcuts shown on the workspace.
3854 *
3855 * Implementation of the method from LauncherModel.Callbacks.
3856 */
3857 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003858 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003859
Michael Jurka7607c2f2013-04-03 14:33:19 -07003860 // If we're starting binding all over again, clear any bind calls we'd postponed in
3861 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3862 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003863 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003864
Winson Chungd64d1762013-08-20 14:37:16 -07003865 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003866 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003867 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003868
Michael Jurka05bf6442011-11-30 20:28:53 -08003869 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003870 if (mHotseat != null) {
3871 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003872 }
3873 }
3874
Adam Cohendcd297f2013-06-18 13:13:40 -07003875 @Override
3876 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003877 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003878
Adam Cohen5084cba2013-09-03 12:01:16 -07003879 // If there are no screens, we need to have an empty screen
3880 if (orderedScreenIds.size() == 0) {
3881 mWorkspace.addExtraEmptyScreen();
3882 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003883
3884 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003885 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003886 if (hasCustomContentToLeft()) {
3887 mWorkspace.createCustomContentContainer();
3888 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003889 }
Winson Chung64359a52013-07-08 17:17:08 -07003890 }
3891
3892 @Override
3893 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003894 // Log to disk
3895 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3896 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3897 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003898 int count = orderedScreenIds.size();
3899 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003900 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003901 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003902 }
3903
Adam Cohen39a06042013-07-19 14:30:12 -07003904 private boolean shouldShowWeightWatcher() {
3905 String spKey = LauncherAppState.getSharedPreferencesKey();
3906 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003907 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003908
3909 return show;
3910 }
3911
3912 private void toggleShowWeightWatcher() {
3913 String spKey = LauncherAppState.getSharedPreferencesKey();
3914 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3915 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3916
3917 show = !show;
3918
3919 SharedPreferences.Editor editor = sp.edit();
3920 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3921 editor.commit();
3922
3923 if (mWeightWatcher != null) {
3924 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3925 }
3926 }
3927
Winson Chungd64d1762013-08-20 14:37:16 -07003928 public void bindAppsAdded(final ArrayList<Long> newScreens,
3929 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003930 final ArrayList<ItemInfo> addAnimated,
3931 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003932 Runnable r = new Runnable() {
3933 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003934 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003935 }
3936 };
3937 if (waitUntilResume(r)) {
3938 return;
3939 }
3940
Winson Chungd64d1762013-08-20 14:37:16 -07003941 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003942 if (newScreens != null) {
3943 bindAddScreens(newScreens);
3944 }
Winson Chungd64d1762013-08-20 14:37:16 -07003945
3946 // We add the items without animation on non-visible pages, and with
3947 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003948 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003949 bindItems(addNotAnimated, 0,
3950 addNotAnimated.size(), false);
3951 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003952 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003953 bindItems(addAnimated, 0,
3954 addAnimated.size(), true);
3955 }
Winson Chungc58497e2013-09-03 17:48:37 -07003956
Winson Chung87412982013-10-03 18:34:14 -07003957 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003958 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003959
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003960 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003961 addedApps != null && mAppsCustomizeContent != null) {
3962 mAppsCustomizeContent.addApps(addedApps);
3963 }
Winson Chungd64d1762013-08-20 14:37:16 -07003964 }
3965
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003966 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003967 * Bind the items start-end from the list.
3968 *
3969 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003970 */
Winson Chung64359a52013-07-08 17:17:08 -07003971 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3972 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003973 Runnable r = new Runnable() {
3974 public void run() {
3975 bindItems(shortcuts, start, end, forceAnimateIcons);
3976 }
3977 };
3978 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003979 return;
3980 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003981
Winson Chungf0c6ae02012-03-21 16:10:31 -07003982 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003983 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3984 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003985 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003986 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003987 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003988 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003989 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003990
3991 // Short circuit if we are loading dock items for a configuration which has no dock
3992 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3993 mHotseat == null) {
3994 continue;
3995 }
3996
Joe Onorato9c1289c2009-08-17 11:03:03 -04003997 switch (item.itemType) {
3998 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3999 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004000 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004001 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004002
Winson Chung64359a52013-07-08 17:17:08 -07004003 /*
4004 * TODO: FIX collision case
4005 */
Winson Chungce376632013-07-11 16:12:41 -07004006 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4007 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4008 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004009 View v = cl.getChildAt(item.cellX, item.cellY);
4010 Object tag = v.getTag();
4011 String desc = "Collision while binding workspace item: " + item
4012 + ". Collides with " + tag;
4013 if (LauncherAppState.isDogfoodBuild()) {
4014 throw (new RuntimeException(desc));
4015 } else {
4016 Log.d(TAG, desc);
4017 }
Winson Chungce376632013-07-11 16:12:41 -07004018 }
Winson Chung64359a52013-07-08 17:17:08 -07004019 }
4020
Adam Cohendcd297f2013-06-18 13:13:40 -07004021 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4022 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004023 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004024 // Animate all the applications up now
4025 shortcut.setAlpha(0f);
4026 shortcut.setScaleX(0f);
4027 shortcut.setScaleY(0f);
4028 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004029 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004030 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004031 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004032 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004033 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004034 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004035 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004036 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4037 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004038 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004039 default:
4040 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004041 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004042 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004043
Winson Chung997a9232013-07-24 15:33:46 -07004044 if (animateIcons) {
4045 // Animate to the correct page
4046 if (newShortcutsScreenId > -1) {
4047 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004048 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004049 final Runnable startBounceAnimRunnable = new Runnable() {
4050 public void run() {
4051 anim.playTogether(bounceAnims);
4052 anim.start();
4053 }
4054 };
Winson Chung997a9232013-07-24 15:33:46 -07004055 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004056 // We post the animation slightly delayed to prevent slowdowns
4057 // when we are loading right after we return to launcher.
4058 mWorkspace.postDelayed(new Runnable() {
4059 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004060 if (mWorkspace != null) {
4061 mWorkspace.snapToPage(newScreenIndex);
4062 mWorkspace.postDelayed(startBounceAnimRunnable,
4063 NEW_APPS_ANIMATION_DELAY);
4064 }
Winson Chung94d67682013-09-25 16:29:40 -07004065 }
4066 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004067 } else {
4068 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004069 }
4070 }
Winson Chung64359a52013-07-08 17:17:08 -07004071 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004072 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004073 }
4074
Joe Onorato9c1289c2009-08-17 11:03:03 -04004075 /**
4076 * Implementation of the method from LauncherModel.Callbacks.
4077 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004078 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004079 Runnable r = new Runnable() {
4080 public void run() {
4081 bindFolders(folders);
4082 }
4083 };
4084 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004085 return;
4086 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004087 sFolders.clear();
4088 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004089 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004090
4091 /**
4092 * Add the views for a widget to the workspace.
4093 *
4094 * Implementation of the method from LauncherModel.Callbacks.
4095 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004096 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004097 Runnable r = new Runnable() {
4098 public void run() {
4099 bindAppWidget(item);
4100 }
4101 };
4102 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004103 return;
4104 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004105
Daniel Sandler843e8602010-06-07 14:59:01 -04004106 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4107 if (DEBUG_WIDGETS) {
4108 Log.d(TAG, "bindAppWidget: " + item);
4109 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004110 final Workspace workspace = mWorkspace;
4111
4112 final int appWidgetId = item.appWidgetId;
4113 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004114 if (DEBUG_WIDGETS) {
4115 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4116 }
4117
Joe Onorato9c1289c2009-08-17 11:03:03 -04004118 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4119
Joe Onorato9c1289c2009-08-17 11:03:03 -04004120 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004121 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004122
Adam Cohendcd297f2013-06-18 13:13:40 -07004123 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004124 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004125 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4126
Joe Onorato9c1289c2009-08-17 11:03:03 -04004127 workspace.requestLayout();
4128
Daniel Sandler843e8602010-06-07 14:59:01 -04004129 if (DEBUG_WIDGETS) {
4130 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4131 + (SystemClock.uptimeMillis()-start) + "ms");
4132 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004133 }
4134
Adam Cohen1462de32012-07-24 22:34:36 -07004135 public void onPageBoundSynchronously(int page) {
4136 mSynchronouslyBoundPages.add(page);
4137 }
4138
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139 /**
4140 * Callback saying that there aren't any more items to bind.
4141 *
4142 * Implementation of the method from LauncherModel.Callbacks.
4143 */
Adam Cohene25af792013-06-06 23:08:25 -07004144 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004145 Runnable r = new Runnable() {
4146 public void run() {
4147 finishBindingItems(upgradePath);
4148 }
4149 };
4150 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004151 return;
4152 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004153 if (mSavedState != null) {
4154 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004155 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004156 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004157 mSavedState = null;
4158 }
4159
Adam Cohen1462de32012-07-24 22:34:36 -07004160 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004161
Winson Chungc51db6a2011-10-05 11:44:49 -07004162 // Update the market app icon as necessary (the other icons will be managed in response to
4163 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004164 if (!DISABLE_MARKET_BUTTON) {
4165 updateAppMarketIcon();
4166 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004167
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004168 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07004169
4170 // If we received the result of any pending adds while the loader was running (e.g. the
4171 // widget configuration forced an orientation change), process them now.
4172 if (sPendingAddItem != null) {
4173 final long screenId = completeAdd(sPendingAddItem);
4174
4175 // TODO: this moves the user to the page where the pending item was added. Ideally,
4176 // the screen would be guaranteed to exist after bind, and the page would be set through
4177 // the workspace restore process.
4178 mWorkspace.post(new Runnable() {
4179 @Override
4180 public void run() {
4181 mWorkspace.snapToScreenId(screenId);
4182 }
4183 });
4184 sPendingAddItem = null;
4185 }
4186
Adam Cohene25af792013-06-06 23:08:25 -07004187 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004188 mWorkspace.getUniqueComponents(true, null);
4189 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004190 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004191 }
4192
Winson Chunga0b7e862013-09-05 16:03:15 -07004193 public boolean isAllAppsButtonRank(int rank) {
4194 if (mHotseat != null) {
4195 return mHotseat.isAllAppsButtonRank(rank);
4196 }
4197 return false;
4198 }
4199
Winson Chunga2413752012-04-03 14:22:34 -07004200 private boolean canRunNewAppsAnimation() {
4201 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4202 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4203 }
4204
Winson Chungc9168342013-06-26 14:54:55 -07004205 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4206 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4207 PropertyValuesHolder.ofFloat("alpha", 1f),
4208 PropertyValuesHolder.ofFloat("scaleX", 1f),
4209 PropertyValuesHolder.ofFloat("scaleY", 1f));
4210 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4211 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4212 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4213 return bounceAnim;
4214 }
4215
Adam Cohen27772732013-11-11 14:00:56 +00004216 public boolean useVerticalBarLayout() {
4217 return LauncherAppState.getInstance().getDynamicGrid().
4218 getDeviceProfile().isVerticalBarLayout();
4219 }
4220
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004221 protected Rect getSearchBarBounds() {
4222 return LauncherAppState.getInstance().getDynamicGrid().
4223 getDeviceProfile().getSearchBarBounds();
4224 }
4225
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004226 @Override
4227 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004228 boolean searchVisible = updateGlobalSearchIcon();
4229 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004230 if (mSearchDropTargetBar != null) {
4231 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4232 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004233 }
4234
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004235 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004236 * Add the icons for all apps.
4237 *
4238 * Implementation of the method from LauncherModel.Callbacks.
4239 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004240 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004241 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004242 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4243 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4244 getHotseat().addAllAppsFolder(mIconCache, apps,
4245 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4246 }
4247 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004248 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004249 if (mAppsCustomizeContent != null) {
4250 mAppsCustomizeContent.onPackagesUpdated(
4251 LauncherModel.getSortedWidgetsAndShortcuts(this));
4252 }
Winson Chungc58497e2013-09-03 17:48:37 -07004253 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004254 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004255 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004256 mAppsCustomizeContent.onPackagesUpdated(
4257 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004258 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004259 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004260 }
4261
4262 /**
4263 * A package was updated.
4264 *
4265 * Implementation of the method from LauncherModel.Callbacks.
4266 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004267 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004268 Runnable r = new Runnable() {
4269 public void run() {
4270 bindAppsUpdated(apps);
4271 }
4272 };
4273 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004274 return;
4275 }
4276
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004277 if (mWorkspace != null) {
4278 mWorkspace.updateShortcuts(apps);
4279 }
Winson Chungc58497e2013-09-03 17:48:37 -07004280
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004281 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004282 mAppsCustomizeContent != null) {
4283 mAppsCustomizeContent.updateApps(apps);
4284 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004285 }
4286
4287 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004288 * Update the state of a package, typically related to install state.
4289 *
4290 * Implementation of the method from LauncherModel.Callbacks.
4291 */
4292 public void updatePackageState(String pkgName, int state) {
4293 if (mWorkspace != null) {
4294 mWorkspace.updatePackageState(pkgName, state);
4295 }
4296 }
4297
4298 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004299 * A package was uninstalled. We take both the super set of packageNames
4300 * in addition to specific applications to remove, the reason being that
4301 * this can be called when a package is updated as well. In that scenario,
4302 * we only remove specific components from the workspace, where as
4303 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004304 *
4305 * Implementation of the method from LauncherModel.Callbacks.
4306 */
Winson Chung83892cc2013-05-01 16:53:33 -07004307 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004308 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004309 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004310 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004311 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004312 }
Winson Chungd64d1762013-08-20 14:37:16 -07004313 };
4314 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004315 return;
4316 }
4317
Winson Chungdf95eb12013-10-16 14:57:07 -07004318 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004319 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004320 }
4321 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004322 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004323 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004324
Winson Chunga1820962011-10-03 16:31:06 -07004325 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004326 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004327
Winson Chungdf95eb12013-10-16 14:57:07 -07004328 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004329 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004330 mAppsCustomizeContent != null) {
4331 mAppsCustomizeContent.removeApps(appInfos);
4332 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004333 }
Joe Onoratobe386092009-11-17 17:32:16 -08004334
4335 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004336 * A number of packages were updated.
4337 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004338 private ArrayList<Object> mWidgetsAndShortcuts;
4339 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004340 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004341 bindPackagesUpdated(mWidgetsAndShortcuts);
4342 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004343 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004344 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004345 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4346 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4347 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004348 return;
4349 }
4350
Winson Chung64359a52013-07-08 17:17:08 -07004351 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004352 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004353 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004354 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004355 }
4356
Winson Chung400438b2011-01-16 17:53:48 -08004357 private int mapConfigurationOriActivityInfoOri(int configOri) {
4358 final Display d = getWindowManager().getDefaultDisplay();
4359 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4360 switch (d.getRotation()) {
4361 case Surface.ROTATION_0:
4362 case Surface.ROTATION_180:
4363 // We are currently in the same basic orientation as the natural orientation
4364 naturalOri = configOri;
4365 break;
4366 case Surface.ROTATION_90:
4367 case Surface.ROTATION_270:
4368 // We are currently in the other basic orientation to the natural orientation
4369 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4370 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4371 break;
4372 }
4373
4374 int[] oriMap = {
4375 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4376 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4377 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4378 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4379 };
4380 // Since the map starts at portrait, we need to offset if this device's natural orientation
4381 // is landscape.
4382 int indexOffset = 0;
4383 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4384 indexOffset = 1;
4385 }
4386 return oriMap[(d.getRotation() + indexOffset) % 4];
4387 }
Adam Cohen446e9402011-09-15 18:21:21 -07004388
Winson Chung4b919f82012-05-01 10:44:08 -07004389 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004390 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004391 getResources().getBoolean(R.bool.allow_rotation);
4392 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004393 }
Winson Chung4b919f82012-05-01 10:44:08 -07004394 public void lockScreenOrientation() {
4395 if (isRotationEnabled()) {
4396 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4397 .getConfiguration().orientation));
4398 }
4399 }
4400 public void unlockScreenOrientation(boolean immediate) {
4401 if (isRotationEnabled()) {
4402 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004403 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004404 } else {
4405 mHandler.postDelayed(new Runnable() {
4406 public void run() {
4407 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4408 }
4409 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004410 }
Winson Chung4b919f82012-05-01 10:44:08 -07004411 }
Winson Chung400438b2011-01-16 17:53:48 -08004412 }
4413
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004414 /**
4415 * Called when the SearchBar hint should be changed.
4416 *
4417 * @param hint the hint to be displayed in the search bar.
4418 */
4419 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004420 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004421 }
4422
Winson Chunge43a1e72014-01-15 10:33:02 -08004423 protected boolean isLauncherPreinstalled() {
4424 PackageManager pm = getPackageManager();
4425 try {
4426 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4427 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4428 return true;
4429 } else {
4430 return false;
4431 }
4432 } catch (NameNotFoundException e) {
4433 e.printStackTrace();
4434 return false;
4435 }
4436 }
4437
Adam Cohenea90f832014-05-21 15:03:34 -07004438 /**
4439 * This method indicates whether or not we should suggest default wallpaper dimensions
4440 * when our wallpaper cropper was not yet used to set a wallpaper.
4441 */
4442 protected boolean overrideWallpaperDimensions() {
4443 return true;
4444 }
4445
Adam Cohen5eed5d82014-05-19 13:12:13 -07004446 protected boolean shouldClingFocusHotseatApp() {
4447 return false;
4448 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004449 protected String getFirstRunClingSearchBarHint() {
4450 return "";
4451 }
4452 protected String getFirstRunCustomContentHint() {
4453 return "";
4454 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004455 protected int getFirstRunFocusedHotseatAppDrawableId() {
4456 return -1;
4457 }
4458 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4459 return null;
4460 }
4461 protected int getFirstRunFocusedHotseatAppRank() {
4462 return -1;
4463 }
4464 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4465 return "";
4466 }
4467 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4468 return "";
4469 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004470
Winson Chungaf40f202013-09-18 18:26:31 -07004471 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004472 mLauncherClings.dismissFirstRunCling(v);
4473 }
4474 public void dismissMigrationClingCopyApps(View v) {
4475 mLauncherClings.dismissMigrationClingCopyApps(v);
4476 }
4477 public void dismissMigrationClingUseDefault(View v) {
4478 mLauncherClings.dismissMigrationClingUseDefault(v);
4479 }
4480 public void dismissMigrationWorkspaceCling(View v) {
4481 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004482 }
Winson Chung82f55532011-08-09 14:14:23 -07004483 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004484 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004485 }
4486 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004487 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004488 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004489 public void markFolderClingDismissedIfNecessary() {
4490 mLauncherClings.markFolderClingDismissedIfNecessary();
4491 }
Adam Cohen432609a2014-03-13 17:03:22 -07004492
4493 /**
4494 * To be overridden by subclasses to indicate that there is an activity to launch
4495 * before showing the standard launcher experience.
4496 */
4497 protected boolean hasFirstRunActivity() {
4498 return false;
4499 }
4500
4501 /**
4502 * To be overridden by subclasses to launch any first run activity
4503 */
4504 protected Intent getFirstRunActivity() {
4505 return null;
4506 }
4507
Winson Chunga6945242014-01-08 14:04:34 -08004508 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004509 return !ActivityManager.isRunningInTestHarness() &&
4510 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004511 }
4512
Adam Cohen4a9423d2014-03-28 14:22:31 -07004513 protected boolean hasRunFirstRunActivity() {
4514 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4515 }
4516
Adam Cohen432609a2014-03-13 17:03:22 -07004517 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004518 if (shouldRunFirstRunActivity() &&
4519 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004520 Intent firstRunIntent = getFirstRunActivity();
4521 if (firstRunIntent != null) {
4522 startActivity(firstRunIntent);
4523 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004524 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004525 }
4526 }
Adam Cohen432609a2014-03-13 17:03:22 -07004527 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004528 }
4529
4530 private void markFirstRunActivityShown() {
4531 SharedPreferences.Editor editor = mSharedPrefs.edit();
4532 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4533 editor.apply();
4534 }
4535
Adam Cohen432609a2014-03-13 17:03:22 -07004536 /**
4537 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4538 * screen that must be displayed and dismissed.
4539 */
4540 protected boolean hasDismissableIntroScreen() {
4541 return false;
4542 }
4543
4544 /**
4545 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4546 */
4547 protected View getIntroScreen() {
4548 return null;
4549 }
4550
4551 /**
4552 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4553 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4554 */
4555 private boolean shouldShowIntroScreen() {
4556 return hasDismissableIntroScreen() &&
4557 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4558 }
4559
4560 protected void showIntroScreen() {
4561 View introScreen = getIntroScreen();
4562 changeWallpaperVisiblity(false);
4563 if (introScreen != null) {
4564 mDragLayer.showOverlayView(introScreen);
4565 }
4566 }
4567
4568 public void dismissIntroScreen() {
4569 markIntroScreenDismissed();
4570 if (showFirstRunActivity()) {
4571 // We delay hiding the intro view until the first run activity is showing. This
4572 // avoids a blip.
4573 mWorkspace.postDelayed(new Runnable() {
4574 @Override
4575 public void run() {
4576 mDragLayer.dismissOverlayView();
4577 }
4578 }, ACTIVITY_START_DELAY);
4579 } else {
4580 mDragLayer.dismissOverlayView();
4581 }
4582 changeWallpaperVisiblity(true);
4583 }
4584
4585 private void markIntroScreenDismissed() {
4586 SharedPreferences.Editor editor = mSharedPrefs.edit();
4587 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4588 editor.apply();
4589 }
4590
Winson Chunga6945242014-01-08 14:04:34 -08004591 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004592 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4593 if (mHotseat != null) mHotseat.setAlpha(1f);
4594 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4595 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004596 }
4597
4598 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004599 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4600 if (mHotseat != null) mHotseat.setAlpha(0f);
4601 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4602 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004603 }
4604
Mathew Inwood72fbec12013-11-19 15:45:07 +00004605 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004606 // Called from search suggestion, not supported in other profiles.
4607 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4608 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4609 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4610 myUser);
4611 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004612 return null;
4613 }
Kenny Guyed131872014-04-30 03:02:21 +01004614 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004615 }
4616
4617 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4618 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004619 // Called from search suggestion, not supported in other profiles.
4620 return createShortcutDragInfo(shortcutIntent, caption, icon,
4621 UserHandleCompat.myUserHandle());
4622 }
4623
4624 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4625 Bitmap icon, UserHandleCompat user) {
4626 return new ShortcutInfo(shortcutIntent, caption, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004627 }
4628
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004629 protected void moveWorkspaceToDefaultScreen() {
4630 mWorkspace.moveToDefaultScreen(false);
4631 }
4632
Mathew Inwood72fbec12013-11-19 15:45:07 +00004633 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4634 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004635 mWorkspace.onExternalDragStartedWithItem(dragView);
4636 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004637 }
4638
Anjali Koppalf5d29132014-02-28 13:33:27 -08004639 @Override
4640 public void onPageSwitch(View newPage, int newPageIndex) {
4641 }
4642
Winson Chung80baf5a2010-08-09 16:03:15 -07004643 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004644 * Prints out out state for debugging.
4645 */
4646 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004647 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004648 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004649 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4650 Log.d(TAG, "mRestoring=" + mRestoring);
4651 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4652 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004653 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004654 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004655
Winson Chung785d2eb2011-04-14 16:08:02 -07004656 if (mAppsCustomizeContent != null) {
4657 mAppsCustomizeContent.dumpState();
4658 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004659 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004660 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004661
4662 @Override
4663 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4664 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004665 synchronized (sDumpLogs) {
4666 writer.println(" ");
4667 writer.println("Debug logs: ");
4668 for (int i = 0; i < sDumpLogs.size(); i++) {
4669 writer.println(" " + sDumpLogs.get(i));
4670 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004671 }
4672 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004673
4674 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004675 if (DEBUG_DUMP_LOG) {
4676 synchronized (sDumpLogs) {
4677 Log.d(TAG, "");
4678 Log.d(TAG, "*********************");
4679 Log.d(TAG, "Launcher debug logs: ");
4680 for (int i = 0; i < sDumpLogs.size(); i++) {
4681 Log.d(TAG, " " + sDumpLogs.get(i));
4682 }
4683 Log.d(TAG, "*********************");
4684 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004685 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004686 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004687 }
4688
4689 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004690 addDumpLog(tag, log, null, debugLog);
4691 }
4692
4693 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004694 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004695 if (e != null) {
4696 Log.d(tag, log, e);
4697 } else {
4698 Log.d(tag, log);
4699 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004700 }
Winson Chungede41292013-09-19 16:27:36 -07004701 if (DEBUG_DUMP_LOG) {
4702 sDateStamp.setTime(System.currentTimeMillis());
4703 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004704 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4705 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004706 }
Winson Chungede41292013-09-19 16:27:36 -07004707 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004708 }
4709
Winson Chungede41292013-09-19 16:27:36 -07004710 public void dumpLogsToLocalData() {
4711 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004712 new AsyncTask<Void, Void, Void>() {
4713 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004714 boolean success = false;
4715 sDateStamp.setTime(sRunStart);
4716 String FILENAME = sDateStamp.getMonth() + "-"
4717 + sDateStamp.getDay() + "_"
4718 + sDateStamp.getHours() + "-"
4719 + sDateStamp.getMinutes() + "_"
4720 + sDateStamp.getSeconds() + ".txt";
4721
4722 FileOutputStream fos = null;
4723 File outFile = null;
4724 try {
4725 outFile = new File(getFilesDir(), FILENAME);
4726 outFile.createNewFile();
4727 fos = new FileOutputStream(outFile);
4728 } catch (Exception e) {
4729 e.printStackTrace();
4730 }
4731 if (fos != null) {
4732 PrintWriter writer = new PrintWriter(fos);
4733
4734 writer.println(" ");
4735 writer.println("Debug logs: ");
4736 synchronized (sDumpLogs) {
4737 for (int i = 0; i < sDumpLogs.size(); i++) {
4738 writer.println(" " + sDumpLogs.get(i));
4739 }
4740 }
4741 writer.close();
4742 }
4743 try {
4744 if (fos != null) {
4745 fos.close();
4746 success = true;
4747 }
4748 } catch (IOException e) {
4749 e.printStackTrace();
4750 }
Michael Jurka43467462013-11-14 12:03:58 +01004751 return null;
Winson Chungede41292013-09-19 16:27:36 -07004752 }
Michael Jurka43467462013-11-14 12:03:58 +01004753 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004754 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004755 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004756}
Michael Jurka2763be32011-02-24 11:19:57 -08004757
Michael Jurkaabded662011-03-04 12:06:57 -08004758interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004759 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004760 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004761 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004762 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004763 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004764}
Dan Sandlerd5024042014-01-09 15:01:33 -05004765
4766interface DebugIntents {
4767 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4768 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004769}