blob: 72cad5138d2b7217c309a717e0c1211b7ff4e746 [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;
Mathew Inwood72fbec12013-11-19 15:45:07 +000047import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070053import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070083import android.view.Window;
Adam Cohenf358a4b2013-07-23 16:47:31 -070084import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewGroup;
87import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080088import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080090import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070091import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Kenny Guyed131872014-04-30 03:02:21 +0100100import com.android.launcher3.compat.LauncherActivityInfoCompat;
101import com.android.launcher3.compat.LauncherAppsCompat;
102import com.android.launcher3.compat.UserHandleCompat;
103import com.android.launcher3.compat.UserManagerCompat;
Daniel Sandler325dc232013-06-05 22:57:57 -0400104import com.android.launcher3.DropTarget.DragObject;
Anjali Koppalf5d29132014-02-28 13:33:27 -0800105import com.android.launcher3.PagedView.PageSwitchListener;
Romain Guyedcce092010-03-04 13:03:17 -0800106
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.DataInputStream;
108import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700109import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700110import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700114import java.io.PrintWriter;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -0700115import java.lang.reflect.Field;
116import java.lang.reflect.InvocationTargetException;
117import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700118import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700120import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700121import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700122import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700123import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000124import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125
Winson Chunga6945242014-01-08 14:04:34 -0800126
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127/**
128 * Default launcher application.
129 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100130public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700131 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700132 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800133 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700134 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135
Daniel Sandlerf061f822013-06-27 13:59:36 -0400136 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400137 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700138 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400139 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700140 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700141
Dan Sandlerd5024042014-01-09 15:01:33 -0500142 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
143
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700145 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700147 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700148 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
Michael Jurka8b805b12012-04-18 14:23:14 -0700150 private static final int REQUEST_BIND_APPWIDGET = 11;
151
Mathew Inwood876a8462013-06-14 14:12:41 +0100152 /**
153 * IntentStarter uses request codes starting with this. This must be greater than all activity
154 * request codes used internally.
155 */
156 protected static final int REQUEST_LAST = 100;
157
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
159
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800160 static final int SCREEN_COUNT = 5;
161 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162
Romain Guy98d01652009-06-30 16:21:04 -0700163 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800164 // To turn on these properties, type
165 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
166 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
167 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800168 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169
Winson Chung2672ff92012-05-04 16:22:30 -0700170 // The Intent extra that defines whether to ignore the launch animation
171 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400172 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700173
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 // Type: int
175 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700176 // Type: int
177 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700179 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
180 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
182 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700183 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700185 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 // Type: boolean
187 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
188 // Type: long
189 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700190 // Type: int
191 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
192 // Type: int
193 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
194 // Type: parcelable
195 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000196 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800197 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000198 // Type: int[]
199 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800200
Adam Cohenb54a5982014-01-08 15:21:04 -0800201
Adam Cohen432609a2014-03-13 17:03:22 -0700202 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800203 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
204
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100205 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700206 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100207 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700208 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100209 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700210
Adam Cohen39a06042013-07-19 14:30:12 -0700211 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700212 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700213
Winson Chunga6945242014-01-08 14:04:34 -0800214 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
215
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700216 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700217 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700218 private State mState = State.WORKSPACE;
219 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700220
Joe Onorato9c1289c2009-08-17 11:03:03 -0400221 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700222 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
223 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700224 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800227 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000229 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
230 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
231
Winson Chunga2413752012-04-03 14:22:34 -0700232 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700233 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
234 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700235 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700236
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800237 private final BroadcastReceiver mCloseSystemDialogsReceiver
238 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800239 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
240
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241 private LayoutInflater mInflater;
242
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800243 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700244 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800245 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800246 private DragLayer mDragLayer;
247 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700248 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800249 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700250
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700251 private AppWidgetManager mAppWidgetManager;
252 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700253
Michael Jurkac9d95c52011-08-29 14:03:34 -0700254 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700255 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800256 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700257
Michael Jurka0280c3b2010-09-17 15:00:07 -0700258 private int[] mTmpAddItemCellCoordinates = new int[2];
259
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 private FolderInfo mFolderInfo;
261
Winson Chung3d503fb2011-07-13 17:25:49 -0700262 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800263 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700264
Michael Jurka838a4ca2011-02-07 13:33:06 -0800265 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700266
Winson Chungc51db6a2011-10-05 11:44:49 -0700267 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700268 private AppsCustomizeTabHost mAppsCustomizeTabHost;
269 private AppsCustomizePagedView mAppsCustomizeContent;
270 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800271 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700274 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
275 // scroll issues (because the workspace may not have been measured yet) and extra work.
276 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
277 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278
279 private SpannableStringBuilder mDefaultKeySsb = null;
280
Joe Onorato9c1289c2009-08-17 11:03:03 -0400281 private boolean mWorkspaceLoading = true;
282
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800283 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284 private boolean mRestoring;
285 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700286 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287
Michael Jurka1e2f4652013-07-08 18:03:46 -0700288 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700289 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
290
Winson Chung4a2afa32012-07-19 14:53:05 -0700291 // Keep track of whether the user has left launcher
292 private static boolean sPausedFromUserAction = false;
293
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 private Bundle mSavedInstanceState;
295
Joe Onorato9c1289c2009-08-17 11:03:03 -0400296 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800297 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800298 private boolean mUserPresent = true;
299 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700300 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800301 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400302
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700303 private static LocaleConfiguration sLocaleConfiguration = null;
304
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700305 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700306
Adam Cohen61f560d2013-09-30 15:58:20 -0700307 private View.OnTouchListener mHapticFeedbackTouchListener;
308
Adam Cohended9f8d2010-11-03 13:25:16 -0700309 // Related to the auto-advancing of widgets
310 private final int ADVANCE_MSG = 1;
311 private final int mAdvanceInterval = 20000;
312 private final int mAdvanceStagger = 250;
313 private long mAutoAdvanceSentTime;
314 private long mAutoAdvanceTimeLeft = -1;
315 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
316 new HashMap<View, AppWidgetProviderInfo>();
317
Winson Chung400438b2011-01-16 17:53:48 -0800318 // Determines how long to wait after a rotation before restoring the screen orientation to
319 // match the sensor state.
320 private final int mRestoreScreenOrientationDelay = 500;
321
Michael Jurka4ef207b2010-11-29 17:05:45 -0800322 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700323 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
324 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
325 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800326
Winson Chungd64a6662013-09-30 11:06:59 -0700327 private Intent mAppMarketIntent = null;
328 private static final boolean DISABLE_MARKET_BUTTON = true;
329
Craig Mautner360310b2012-10-26 15:13:08 -0700330 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700331
Adam Cohen1462de32012-07-24 22:34:36 -0700332 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700333 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700334
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700335 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700336 static Date sDateStamp = new Date();
337 static DateFormat sDateFormat =
338 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
339 static long sRunStart = System.currentTimeMillis();
340 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700341
Winson Chung46353de2012-02-16 14:05:10 -0800342 // We only want to get the SharedPreferences once since it does an FS stat each time we get
343 // it from the context.
344 private SharedPreferences mSharedPrefs;
345
Adam Cohene25af792013-06-06 23:08:25 -0700346 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
347
Winson Chungf0c6ae02012-03-21 16:10:31 -0700348 // Holds the page that we need to animate to, and the icon views that we need to animate up
349 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700350 private ImageView mFolderIconImageView;
351 private Bitmap mFolderIconBitmap;
352 private Canvas mFolderIconCanvas;
353 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700354
Michael Jurkaddd62e92011-02-16 17:49:14 -0800355 private BubbleTextView mWaitingForResume;
356
Michael Jurkac1f5d262011-09-30 19:32:27 -0700357 private Runnable mBuildLayersRunnable = new Runnable() {
358 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700359 if (mWorkspace != null) {
360 mWorkspace.buildPageHardwareLayers();
361 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700362 }
363 };
364
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800365 private static ArrayList<PendingAddArguments> sPendingAddList
366 = new ArrayList<PendingAddArguments>();
367
Michael Jurka7267fa52013-09-26 15:29:57 -0700368 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800369
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800370 private static class PendingAddArguments {
371 int requestCode;
372 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700373 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700374 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800375 int cellX;
376 int cellY;
377 }
378
Daniel Sandlerff02d492013-08-05 02:12:05 -0400379 private Stats mStats;
380
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800381 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800382 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700383 }
384
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 @Override
386 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700387 if (DEBUG_STRICT_MODE) {
388 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
389 .detectDiskReads()
390 .detectDiskWrites()
391 .detectNetwork() // or .detectAll() for all detectable problems
392 .penaltyLog()
393 .build());
394 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
395 .detectLeakedSqlLiteObjects()
396 .detectLeakedClosableObjects()
397 .penaltyLog()
398 .penaltyDeath()
399 .build());
400 }
401
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800402 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400403
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400404 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400405 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700406 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700407 // Determine the dynamic grid properties
408 Point smallestSize = new Point();
409 Point largestSize = new Point();
410 Point realSize = new Point();
411 Display display = getWindowManager().getDefaultDisplay();
412 display.getCurrentSizeRange(smallestSize, largestSize);
413 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700414 DisplayMetrics dm = new DisplayMetrics();
415 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700416
Winson Chung5f8afe62013-08-12 16:19:28 -0700417 // Lazy-initialize the dynamic grid
418 DeviceProfile grid = app.initDynamicGrid(this,
419 Math.min(smallestSize.x, smallestSize.y),
420 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700421 realSize.x, realSize.y,
422 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700423
424 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400425 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700426 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800427 mModel = app.setLauncher(this);
428 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700429 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400430 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800431 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700433
Daniel Sandlerff02d492013-08-05 02:12:05 -0400434 mStats = new Stats(this);
435
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700436 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700437
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700438 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
439 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700440
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700441 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
442 // this also ensures that any synchronous binding below doesn't re-trigger another
443 // LauncherModel load.
444 mPaused = false;
445
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200447 android.os.Debug.startMethodTracing(
448 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 }
450
Adam Cohen53805212013-10-01 10:39:23 -0700451
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700454
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100456 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800458 registerContentObservers();
459
Joe Onorato7c312c12009-08-13 21:36:53 -0700460 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700461
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 mSavedState = savedInstanceState;
463 restoreState(mSavedState);
464
465 if (PROFILE_STARTUP) {
466 android.os.Debug.stopMethodTracing();
467 }
468
469 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700470 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700471 // If the user leaves launcher, then we should just load items asynchronously when
472 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500473 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700474 } else {
475 // We only load the page synchronously if the user rotates (or triggers a
476 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800477 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700478 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800479 }
480
481 // For handling default keys
482 mDefaultKeySsb = new SpannableStringBuilder();
483 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800484
485 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
486 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800487
Adam Cohenf9426d52012-06-04 17:26:21 -0700488 updateGlobalIcons();
489
490 // On large interfaces, we want the screen to auto-rotate based on the current orientation
491 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700492
Adam Cohen432609a2014-03-13 17:03:22 -0700493 if (shouldShowIntroScreen()) {
494 showIntroScreen();
495 } else {
496 showFirstRunActivity();
497 }
498
Winson Chunge43a1e72014-01-15 10:33:02 -0800499 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
500 // on the device, then we always show the first run cling experience (or if there is no
501 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800502 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
503 if (mModel.canMigrateFromOldLauncherDb(this)) {
504 mLauncherClings.showMigrationCling();
505 } else {
506 mLauncherClings.showFirstRunCling();
507 }
Winson Chunga6945242014-01-08 14:04:34 -0800508 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800509 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800510 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700511 }
512
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700513 @Override
514 public void onLauncherProviderChange() { }
515
Winson Chung4a2afa32012-07-19 14:53:05 -0700516 protected void onUserLeaveHint() {
517 super.onUserLeaveHint();
518 sPausedFromUserAction = true;
519 }
520
Winson Chung98ca0f72013-07-29 12:58:51 -0700521 /** To be overriden by subclasses to hint to Launcher that we have custom content */
522 protected boolean hasCustomContentToLeft() {
523 return false;
524 }
525
Dave Hawkeya8881582013-09-17 15:55:33 -0600526 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500527 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 * {@link #addToCustomContentPage}. This will only be invoked if
529 * {@link #hasCustomContentToLeft()} is {@code true}.
530 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500531 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600532 }
533
534 /**
535 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
536 * ensure the custom content page is added or removed if necessary.
537 */
538 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600539 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600540 // Not bound yet, wait for bindScreens to be called.
541 return;
542 }
543
544 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
545 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500546 mWorkspace.createCustomContentContainer();
547 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600548 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
549 mWorkspace.removeCustomContentPage();
550 }
551 }
552
Adam Cohenf9426d52012-06-04 17:26:21 -0700553 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700554 boolean searchVisible = false;
555 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800556 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700557 int coi = getCurrentOrientationIndexForGlobalIcons();
558 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
559 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700560 if (!DISABLE_MARKET_BUTTON) {
561 updateAppMarketIcon();
562 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700563 searchVisible = updateGlobalSearchIcon();
564 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700565 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700566 if (sGlobalSearchIcon[coi] != null) {
567 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700568 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700569 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700570 if (sVoiceSearchIcon[coi] != null) {
571 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700572 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700573 }
Winson Chungd64a6662013-09-30 11:06:59 -0700574 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700575 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800576 }
Winson Chungadf0c182012-08-23 14:59:07 -0700577 if (mSearchDropTargetBar != null) {
578 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
579 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800580 }
Romain Guycbb89e42009-06-08 15:52:54 -0700581
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700583 if (sLocaleConfiguration == null) {
584 new AsyncTask<Void, Void, LocaleConfiguration>() {
585 @Override
586 protected LocaleConfiguration doInBackground(Void... unused) {
587 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
588 readConfiguration(Launcher.this, localeConfiguration);
589 return localeConfiguration;
590 }
591
592 @Override
593 protected void onPostExecute(LocaleConfiguration result) {
594 sLocaleConfiguration = result;
595 checkForLocaleChange(); // recursive, but now with a locale configuration
596 }
597 }.execute();
598 return;
599 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700600
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 final Configuration configuration = getResources().getConfiguration();
602
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700603 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800604 final String locale = configuration.locale.toString();
605
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800607 final int mcc = configuration.mcc;
608
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700609 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800610 final int mnc = configuration.mnc;
611
Romain Guy84f296c2009-11-04 15:00:44 -0800612 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800613
Romain Guy84f296c2009-11-04 15:00:44 -0800614 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700615 sLocaleConfiguration.locale = locale;
616 sLocaleConfiguration.mcc = mcc;
617 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700618
Joe Onorato0589f0f2010-02-08 13:44:00 -0800619 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700620
621 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100622 new AsyncTask<Void, Void, Void>() {
623 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700624 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100625 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700626 }
Michael Jurka43467462013-11-14 12:03:58 +0100627 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700628 }
629 }
630
631 private static class LocaleConfiguration {
632 public String locale;
633 public int mcc = -1;
634 public int mnc = -1;
635 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700636
Romain Guy98d01652009-06-30 16:21:04 -0700637 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
638 DataInputStream in = null;
639 try {
640 in = new DataInputStream(context.openFileInput(PREFERENCES));
641 configuration.locale = in.readUTF();
642 configuration.mcc = in.readInt();
643 configuration.mnc = in.readInt();
644 } catch (FileNotFoundException e) {
645 // Ignore
646 } catch (IOException e) {
647 // Ignore
648 } finally {
649 if (in != null) {
650 try {
651 in.close();
652 } catch (IOException e) {
653 // Ignore
654 }
655 }
656 }
657 }
658
659 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
660 DataOutputStream out = null;
661 try {
662 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
663 out.writeUTF(configuration.locale);
664 out.writeInt(configuration.mcc);
665 out.writeInt(configuration.mnc);
666 out.flush();
667 } catch (FileNotFoundException e) {
668 // Ignore
669 } catch (IOException e) {
670 //noinspection ResultOfMethodCallIgnored
671 context.getFileStreamPath(PREFERENCES).delete();
672 } finally {
673 if (out != null) {
674 try {
675 out.close();
676 } catch (IOException e) {
677 // Ignore
678 }
679 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800680 }
681 }
682
Anton Hanssona2f665f2013-09-26 12:18:32 +0100683 public Stats getStats() {
684 return mStats;
685 }
686
Bjorn Bringertc459e522013-06-07 19:36:01 +0100687 public LayoutInflater getInflater() {
688 return mInflater;
689 }
690
Winson Chung36a62fe2012-05-06 18:04:42 -0700691 boolean isDraggingEnabled() {
692 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
693 // that is subsequently removed from the workspace in startBinding().
694 return !mModel.isLoadingWorkspace();
695 }
696
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800697 static int getScreen() {
698 synchronized (sLock) {
699 return sScreen;
700 }
701 }
702
703 static void setScreen(int screen) {
704 synchronized (sLock) {
705 sScreen = screen;
706 }
707 }
708
Winson Chung557d6ed2011-07-08 15:34:52 -0700709 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000710 * Copied from View -- the View version of the method isn't called
711 * anywhere else in our process and only exists for API level 17+,
712 * so it's ok to keep our own version with no API requirement.
713 */
714 public static int generateViewId() {
715 for (;;) {
716 final int result = sNextGeneratedId.get();
717 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
718 int newValue = result + 1;
719 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
720 if (sNextGeneratedId.compareAndSet(result, newValue)) {
721 return result;
722 }
723 }
724 }
725
726 public int getViewIdForItem(ItemInfo info) {
727 // This cast is safe given the > 2B range for int.
728 int itemId = (int) info.id;
729 if (mItemIdToViewId.containsKey(itemId)) {
730 return mItemIdToViewId.get(itemId);
731 }
732 int viewId = generateViewId();
733 mItemIdToViewId.put(itemId, viewId);
734 return viewId;
735 }
736
737 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700738 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
739 * a configuration step, this allows the proper animations to run after other transitions.
740 */
741 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700742 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800743 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800744 case REQUEST_PICK_SHORTCUT:
745 processShortcut(args.intent);
746 break;
747 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700748 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700749 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700750 result = true;
751 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 case REQUEST_CREATE_APPWIDGET:
753 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700754 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700755 result = true;
756 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800757 }
Michael Jurka27614d22012-04-02 06:40:22 -0700758 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
759 // if you turned the screen off and then back while in All Apps, Launcher would not
760 // return to the workspace. Clearing mAddInfo.container here fixes this issue
761 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700762 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800763 }
764
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 protected void onActivityResult(
767 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700768 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700769 setWaitingForResult(false);
Adam Cohen4637b5a2013-11-04 18:21:24 -0800770 int pendingAddWidgetId = mPendingAddWidgetId;
771 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700772
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 Runnable exitSpringLoaded = new Runnable() {
774 @Override
775 public void run() {
776 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
777 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
778 }
779 };
780
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700783 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
784 if (resultCode == RESULT_CANCELED) {
785 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700786 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700787 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700788 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700789 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
790 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700791 }
792 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200793 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
794 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
795 mWorkspace.exitOverviewMode(false);
796 }
797 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700798 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200799
Adam Cohened66b2b2012-01-23 17:28:51 -0800800 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
801 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700802
Adam Cohened66b2b2012-01-23 17:28:51 -0800803 // We have special handling for widgets
804 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800805 final int appWidgetId;
806 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
807 : -1;
808 if (widgetId < 0) {
809 appWidgetId = pendingAddWidgetId;
810 } else {
811 appWidgetId = widgetId;
812 }
813
Adam Cohenad4e15c2013-10-17 16:21:35 -0700814 final int result;
815 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800816 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700817 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
818 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700819 result = RESULT_CANCELED;
820 completeTwoStageWidgetDrop(result, appWidgetId);
821 onComplete = new Runnable() {
822 @Override
823 public void run() {
824 exitSpringLoadedDragModeDelayed(false, 0, null);
825 }
826 };
Winson Chung5aaab772012-04-27 15:24:02 -0700827 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700828 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700829 final CellLayout dropLayout =
830 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
831 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700832 onComplete = new Runnable() {
833 @Override
834 public void run() {
835 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700836 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700837 }
838 };
Winson Chung5aaab772012-04-27 15:24:02 -0700839 }
Adam Cohen689ff162014-05-08 17:27:56 -0700840 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700841 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800842 return;
843 }
844
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 // The pattern used here is that a user PICKs a specific application,
846 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700847
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800848 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
849 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700850 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800851 final PendingAddArguments args = new PendingAddArguments();
852 args.requestCode = requestCode;
853 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700854 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700855 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700856 args.cellX = mPendingAddInfo.cellX;
857 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800858 if (isWorkspaceLocked()) {
859 sPendingAddList.add(args);
860 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700861 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800862 }
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);
Adam Cohen00074722013-10-11 17:46:09 -0700865 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700866 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700867 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800869 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800870 }
871
872 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700873 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700874 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800875 Runnable onCompleteRunnable = null;
876 int animationType = 0;
877
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700878 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800879 if (resultCode == RESULT_OK) {
880 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
881 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700882 mPendingAddWidgetInfo);
883 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 onCompleteRunnable = new Runnable() {
885 @Override
886 public void run() {
887 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700888 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700889 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
890 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800891 }
892 };
893 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800894 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800895 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800896 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700897 if (mDragLayer.getAnimatedView() != null) {
898 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
899 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
900 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700901 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700902 // The animated view may be null in the case of a rotation during widget configuration
903 onCompleteRunnable.run();
904 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905 }
906
907 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700908 protected void onStop() {
909 super.onStop();
910 FirstFrameAnimatorHelper.setIsVisible(false);
911 }
912
913 @Override
914 protected void onStart() {
915 super.onStart();
916 FirstFrameAnimatorHelper.setIsVisible(true);
917 }
918
919 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800920 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200921 long startTime = 0;
922 if (DEBUG_RESUME_TIME) {
923 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400924 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200925 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800926 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700927
Winson Chung4a2afa32012-07-19 14:53:05 -0700928 // Restore the previous launcher state
929 if (mOnResumeState == State.WORKSPACE) {
930 showWorkspace(false);
931 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800932 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700933 }
934 mOnResumeState = State.NONE;
935
Craig Mautner360310b2012-10-26 15:13:08 -0700936 // Background was set to gradient in onPause(), restore to black if in all apps.
937 setWorkspaceBackground(mState == State.WORKSPACE);
938
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800939 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700940 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700941 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700942 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500943 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400944 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700945 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700947 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200948 // We might have postponed some bind calls until onResume (see waitUntilResume) --
949 // execute them here
950 long startTimeCallbacks = 0;
951 if (DEBUG_RESUME_TIME) {
952 startTimeCallbacks = System.currentTimeMillis();
953 }
954
955 if (mAppsCustomizeContent != null) {
956 mAppsCustomizeContent.setBulkBind(true);
957 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700958 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
959 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200960 }
961 if (mAppsCustomizeContent != null) {
962 mAppsCustomizeContent.setBulkBind(false);
963 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700964 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200965 if (DEBUG_RESUME_TIME) {
966 Log.d(TAG, "Time spent processing callbacks in onResume: " +
967 (System.currentTimeMillis() - startTimeCallbacks));
968 }
Michael Jurka447bf842013-05-15 14:52:15 +0200969 }
Michael Jurka54554252013-08-01 12:52:23 +0200970 if (mOnResumeCallbacks.size() > 0) {
971 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
972 mOnResumeCallbacks.get(i).run();
973 }
974 mOnResumeCallbacks.clear();
975 }
Winson Chunge4e50662012-01-23 14:45:13 -0800976
977 // Reset the pressed state of icons that were locked in the press state while activities
978 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800979 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800980 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800981 mWaitingForResume.setStayPressed(false);
982 }
Winson Chunge4e50662012-01-23 14:45:13 -0800983 if (mAppsCustomizeContent != null) {
984 // Resets the previous all apps icon press state
985 mAppsCustomizeContent.resetDrawableState();
986 }
Winson Chung82963d52013-10-09 11:20:57 -0700987
Adam Cohen06dff352012-06-01 17:17:08 -0700988 // It is possible that widgets can receive updates while launcher is not in the foreground.
989 // Consequently, the widgets will be inflated in the orientation of the foreground activity
990 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
991 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700992 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700993
Winson Chung780fe592013-09-26 14:48:44 -0700994 // Process any items that were added while Launcher was away.
995 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
996
Winson Chung5841efa2013-09-30 18:06:44 -0700997 // Update the voice search button proxy
998 updateVoiceButtonProxyVisible(false);
999
Adam Cohenf9426d52012-06-04 17:26:21 -07001000 // Again, as with the above scenario, it's possible that one or more of the global icons
1001 // were updated in the wrong orientation.
1002 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001003 if (DEBUG_RESUME_TIME) {
1004 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1005 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001006
1007 if (mWorkspace.getCustomContentCallbacks() != null) {
1008 // If we are resuming and the custom content is the current page, we call onShow().
1009 // It is also poassible that onShow will instead be called slightly after first layout
1010 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1011 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001012 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001013 }
1014 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001015 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001016 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001017 }
1018
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001020 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001021 // Ensure that items added to Launcher are queued until Launcher returns
1022 InstallShortcutReceiver.enableInstallQueue();
1023
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001024 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001025 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001026 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001027 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001028
1029 // We call onHide() aggressively. The custom content callbacks should be able to
1030 // debounce excess onHide calls.
1031 if (mWorkspace.getCustomContentCallbacks() != null) {
1032 mWorkspace.getCustomContentCallbacks().onHide();
1033 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001034 }
Romain Guycbb89e42009-06-08 15:52:54 -07001035
Adam Cohenbffe7452013-07-22 18:21:45 -07001036 QSBScroller mQsbScroller = new QSBScroller() {
1037 int scrollY = 0;
1038
1039 @Override
1040 public void setScrollY(int scroll) {
1041 scrollY = scroll;
1042
1043 if (mWorkspace.isOnOrMovingToCustomContent()) {
1044 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001045 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001046 }
1047 }
1048 };
1049
1050 public void resetQSBScroll() {
1051 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001052 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001053 }
1054
1055 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001056 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1057 // by a onResume or by scrolling otherwise.
1058 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001059
1060 // Custom content is completely hidden
1061 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001062
1063 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1064 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001065 }
1066
Jorim Jaggid017f882014-01-14 17:08:48 -08001067 protected boolean hasSettings() {
1068 return false;
1069 }
1070
Adam Cohenbffe7452013-07-22 18:21:45 -07001071 public interface QSBScroller {
1072 public void setScrollY(int scrollY);
1073 }
1074
Winson Chung98ca0f72013-07-29 12:58:51 -07001075 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001076 CustomContentCallbacks callbacks, String description) {
1077 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001078 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001079 }
1080
Adam Cohenedb40762013-07-18 16:45:45 -07001081 // The custom content needs to offset its content to account for the QSB
1082 public int getTopOffsetForCustomContent() {
1083 return mWorkspace.getPaddingTop();
1084 }
1085
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001086 @Override
1087 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001088 // Flag the loader to stop early before switching
1089 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001090 if (mAppsCustomizeContent != null) {
1091 mAppsCustomizeContent.surrender();
1092 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001093 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001094 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001095
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001096 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001097 @Override
1098 public void onWindowFocusChanged(boolean hasFocus) {
1099 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001100 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001101 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001102
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001103 private boolean acceptFilter() {
1104 final InputMethodManager inputManager = (InputMethodManager)
1105 getSystemService(Context.INPUT_METHOD_SERVICE);
1106 return !inputManager.isFullscreenMode();
1107 }
1108
1109 @Override
1110 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001111 final int uniChar = event.getUnicodeChar();
1112 final boolean handled = super.onKeyDown(keyCode, event);
1113 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1114 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1116 keyCode, event);
1117 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001118 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001119 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001120 // showSearchDialog()
1121 // If there are multiple keystrokes before the search dialog takes focus,
1122 // onSearchRequested() will be called for every keystroke,
1123 // but it is idempotent, so it's fine.
1124 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125 }
1126 }
1127
Joe Onorato8a9625e2010-01-28 15:55:35 -08001128 // Eat the long press event so the keyboard doesn't come up.
1129 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1130 return true;
1131 }
1132
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133 return handled;
1134 }
1135
Karl Rosaen138a0412009-04-23 19:00:21 -07001136 private String getTypedText() {
1137 return mDefaultKeySsb.toString();
1138 }
1139
1140 private void clearTypedText() {
1141 mDefaultKeySsb.clear();
1142 mDefaultKeySsb.clearSpans();
1143 Selection.setSelection(mDefaultKeySsb, 0);
1144 }
1145
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001146 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001147 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1148 * State
1149 */
1150 private static State intToState(int stateOrdinal) {
1151 State state = State.WORKSPACE;
1152 final State[] stateValues = State.values();
1153 for (int i = 0; i < stateValues.length; i++) {
1154 if (stateValues[i].ordinal() == stateOrdinal) {
1155 state = stateValues[i];
1156 break;
1157 }
1158 }
1159 return state;
1160 }
1161
1162 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 * Restores the previous state, if it exists.
1164 *
1165 * @param savedState The previous state.
1166 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001167 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168 private void restoreState(Bundle savedState) {
1169 if (savedState == null) {
1170 return;
1171 }
1172
Michael Jurka883f55b2010-10-21 15:47:14 -07001173 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001174 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001175 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001176 }
1177
Adam Cohen21cd0022013-10-09 18:57:02 -07001178 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1179 PagedView.INVALID_RESTORE_PAGE);
1180 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001181 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001182 }
1183
Winson Chung3d503fb2011-07-13 17:25:49 -07001184 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001185 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001186
Winson Chung3d503fb2011-07-13 17:25:49 -07001187 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1188 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001189 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001190 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1191 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001192 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1193 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1194 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001195 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001196 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001197 mRestoring = true;
1198 }
1199
1200 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1201 if (renameFolder) {
1202 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001203 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001204 mRestoring = true;
1205 }
Winson Chunga12a2502010-12-20 14:41:35 -08001206
Winson Chung785d2eb2011-04-14 16:08:02 -07001207 // Restore the AppsCustomize tab
1208 if (mAppsCustomizeTabHost != null) {
1209 String curTab = savedState.getString("apps_customize_currentTab");
1210 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001211 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001212 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001213 mAppsCustomizeContent.loadAssociatedPages(
1214 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001215 }
1216
Winson Chung5afbf7b2011-07-25 11:53:08 -07001217 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1218 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001219 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001220 mItemIdToViewId = (HashMap<Integer, Integer>)
1221 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 }
1223
1224 /**
1225 * Finds all the views we need and configure them properly.
1226 */
1227 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001228 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001229
Craig Mautner360310b2012-10-26 15:13:08 -07001230 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001231 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1232 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001233 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001234 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001235
John Spurlock77e1f472013-09-11 10:09:51 -04001236 mLauncherView.setSystemUiVisibility(
1237 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001238 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239
Winson Chung4c98d922011-05-31 16:50:48 -07001240 // Setup the drag layer
1241 mDragLayer.setup(this, dragController);
1242
Winson Chung3d503fb2011-07-13 17:25:49 -07001243 // Setup the hotseat
1244 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1245 if (mHotseat != null) {
1246 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001247 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001248 }
1249
Jorim Jaggid017f882014-01-14 17:08:48 -08001250 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001251 View widgetButton = findViewById(R.id.widget_button);
1252 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001253 @Override
1254 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001255 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001256 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001257 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001258 }
1259 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001260 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1261
1262 View wallpaperButton = findViewById(R.id.wallpaper_button);
1263 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001264 @Override
1265 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001266 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001267 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001268 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001269 }
1270 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001271 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1272
1273 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001274 if (hasSettings()) {
1275 settingsButton.setOnClickListener(new OnClickListener() {
1276 @Override
1277 public void onClick(View arg0) {
1278 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001279 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001280 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001281 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001282 });
1283 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1284 } else {
1285 settingsButton.setVisibility(View.GONE);
1286 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1287 lp.gravity = Gravity.END | Gravity.TOP;
1288 widgetButton.requestLayout();
1289 }
1290
Adam Cohendbdff6b2013-09-18 19:09:15 -07001291 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001292
Winson Chung4c98d922011-05-31 16:50:48 -07001293 // Setup the workspace
1294 mWorkspace.setHapticFeedbackEnabled(false);
1295 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001296 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001297 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001298
Winson Chungf0ea4d32011-06-06 14:27:16 -07001299 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001300 mSearchDropTargetBar = (SearchDropTargetBar)
1301 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001302
Winson Chungf0ea4d32011-06-06 14:27:16 -07001303 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001304 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001305 mAppsCustomizeContent = (AppsCustomizePagedView)
1306 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1307 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001308
Winson Chung3d503fb2011-07-13 17:25:49 -07001309 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001310 dragController.setDragScoller(mWorkspace);
1311 dragController.setScrollView(mDragLayer);
1312 dragController.setMoveTarget(mWorkspace);
1313 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001314 if (mSearchDropTargetBar != null) {
1315 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001316 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001317
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001318 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001319 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001320 mWeightWatcher = new WeightWatcher(this);
1321 mWeightWatcher.setAlpha(0.5f);
1322 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001323 new FrameLayout.LayoutParams(
1324 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001325 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001326 Gravity.BOTTOM)
1327 );
Adam Cohen39a06042013-07-19 14:30:12 -07001328
1329 boolean show = shouldShowWeightWatcher();
1330 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001331 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332 }
1333
1334 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001335 * Sets the all apps button. This method is called from {@link Hotseat}.
1336 */
1337 public void setAllAppsButton(View allAppsButton) {
1338 mAllAppsButton = allAppsButton;
1339 }
1340
1341 public View getAllAppsButton() {
1342 return mAllAppsButton;
1343 }
1344
1345 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346 * Creates a view representing a shortcut.
1347 *
1348 * @param info The data structure describing the shortcut.
1349 *
1350 * @return A View inflated from R.layout.application.
1351 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001352 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001354 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 }
1356
1357 /**
1358 * Creates a view representing a shortcut inflated from the specified resource.
1359 *
1360 * @param layoutResId The id of the XML layout used to create the shortcut.
1361 * @param parent The group the shortcut belongs to.
1362 * @param info The data structure describing the shortcut.
1363 *
1364 * @return A View inflated from layoutResId.
1365 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001366 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001367 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1368 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 return favorite;
1371 }
1372
1373 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 * Add a shortcut to the workspace.
1375 *
1376 * @param data The intent describing the shortcut.
1377 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001379 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001380 int cellY) {
1381 int[] cellXY = mTmpAddItemCellCoordinates;
1382 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001383 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001384
Michael Jurkad3ef3062010-11-23 16:23:58 -08001385 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001386
Adam Cohen558baaf2011-08-15 15:22:57 -07001387 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001388 if (info == null) {
1389 return;
1390 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001391 final View view = createShortcut(info);
1392
Adam Cohenfbba09b2011-07-18 21:43:05 -07001393 // First we check if we already know the exact location where we want to add this item.
1394 if (cellX >= 0 && cellY >= 0) {
1395 cellXY[0] = cellX;
1396 cellXY[1] = cellY;
1397 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001398
1399 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001400 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001401 true, null,null)) {
1402 return;
1403 }
1404 DragObject dragObject = new DragObject();
1405 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001406 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1407 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001408 return;
1409 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001410 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001411 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001412 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001413 foundCellSpan = (result != null);
1414 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001415 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001416 }
1417
1418 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001419 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001420 return;
1421 }
1422
Adam Cohendcd297f2013-06-18 13:13:40 -07001423 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424
1425 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001426 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001427 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001428 }
1429 }
1430
Adam Cohen2f093b62012-04-30 18:59:53 -07001431 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1432 int minHeight) {
1433 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001434 // We want to account for the extra amount of padding that we are adding to the widget
1435 // to ensure that it gets the full amount of space that it has requested
1436 int requiredWidth = minWidth + padding.left + padding.right;
1437 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001438 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001439 }
1440
Adam Cohen2f093b62012-04-30 18:59:53 -07001441 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1442 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001443 }
1444
Adam Cohen2f093b62012-04-30 18:59:53 -07001445 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1446 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001447 }
1448
Adam Cohen2f093b62012-04-30 18:59:53 -07001449 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1450 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001451 }
1452
Adam Cohen2f093b62012-04-30 18:59:53 -07001453 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1454 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001455 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001456 }
1457
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001459 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001461 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001462 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001463 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001464 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001465 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1466 if (appWidgetInfo == null) {
1467 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1468 }
Romain Guycbb89e42009-06-08 15:52:54 -07001469
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001470 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001471 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001472
Adam Cohen2f093b62012-04-30 18:59:53 -07001473 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1474 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001475
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001477 // We have saved the position to which the widget was dragged-- this really only matters
1478 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001479 int[] cellXY = mTmpAddItemCellCoordinates;
1480 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001481 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001482 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001483 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1484 cellXY[0] = mPendingAddInfo.cellX;
1485 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001486 spanXY[0] = mPendingAddInfo.spanX;
1487 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001488 foundCellSpan = true;
1489 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001490 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001491 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001492 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1493 spanXY[1], cellXY, finalSpan);
1494 spanXY[0] = finalSpan[0];
1495 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001496 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001497 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001498 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001499 }
1500
Michael Jurka0280c3b2010-09-17 15:00:07 -07001501 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001502 if (appWidgetId != -1) {
1503 // Deleting an app widget ID is a void call but writes to disk before returning
1504 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001505 new AsyncTask<Void, Void, Void>() {
1506 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001507 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001508 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001509 }
Michael Jurka43467462013-11-14 12:03:58 +01001510 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001511 }
Winson Chung93eef082012-03-23 15:59:27 -07001512 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001513 return;
1514 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001515
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001516 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001517 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1518 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001519 launcherInfo.spanX = spanXY[0];
1520 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001521 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1522 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001523
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001525 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001526
1527 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001528 if (hostView == null) {
1529 // Perform actual inflation because we're live
1530 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1531 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1532 } else {
1533 // The AppWidgetHostView has already been inflated and instantiated
1534 launcherInfo.hostView = hostView;
1535 }
Romain Guycbb89e42009-06-08 15:52:54 -07001536
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001538 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001539 launcherInfo.notifyWidgetSizeChanged(this);
1540
Adam Cohendcd297f2013-06-18 13:13:40 -07001541 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001542 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001543
1544 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001546 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 }
Romain Guycbb89e42009-06-08 15:52:54 -07001548
Adam Cohended9f8d2010-11-03 13:25:16 -07001549 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1550 @Override
1551 public void onReceive(Context context, Intent intent) {
1552 final String action = intent.getAction();
1553 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1554 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001555 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001556 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001557
Winson Chungc100e8e2011-08-09 16:02:43 -07001558 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001559 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001560 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001561 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001562 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001563 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1564 mUserPresent = true;
1565 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001566 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1567 mModel.resetLoadedState(false, true);
1568 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1569 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1570 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1571 mModel.resetLoadedState(false, true);
1572 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1573 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1574 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001575 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1576 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1577 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001578 }
1579 }
1580 };
1581
1582 @Override
1583 public void onAttachedToWindow() {
1584 super.onAttachedToWindow();
1585
1586 // Listen for broadcasts related to user-presence
1587 final IntentFilter filter = new IntentFilter();
1588 filter.addAction(Intent.ACTION_SCREEN_OFF);
1589 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001590 // For handling managed profiles
1591 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1592 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001593 if (ENABLE_DEBUG_INTENTS) {
1594 filter.addAction(DebugIntents.DELETE_DATABASE);
1595 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1596 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001597 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001598 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001599 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001600 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001601 mVisible = true;
1602 }
1603
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001604 /**
1605 * Sets up transparent navigation and status bars in LMP.
1606 * This method is a no-op for other platform versions.
1607 */
1608 private void setupTransparentSystemBarsForLmp() {
1609 // TODO(sansid): use the APIs directly when compiling against L sdk.
1610 // Currently we use reflection to access the flags and the API to set the transparency
1611 // on the System bars.
1612 if (Utilities.isLmp()) {
1613 try {
1614 getWindow().getAttributes().systemUiVisibility |=
1615 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1616 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1617 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1618 Field translucentStatusField =
1619 WindowManager.LayoutParams.class.getField("FLAG_TRANSLUCENT_STATUS");
1620 Field translucentNavigationField =
1621 WindowManager.LayoutParams.class.getField("FLAG_TRANSLUCENT_NAVIGATION");
1622 getWindow().clearFlags(translucentStatusField.getInt(null)
1623 | translucentNavigationField.getInt(null));
1624 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1625 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1626 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1627
1628 Method setStatusBarColorMethod =
1629 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1630 Method setNavigationBarColorMethod =
1631 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1632 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1633 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1634 } catch (NoSuchFieldException e) {
1635 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1636 } catch (NoSuchMethodException ex) {
1637 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1638 } catch (IllegalAccessException e) {
1639 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1640 } catch (IllegalArgumentException e) {
1641 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1642 } catch (InvocationTargetException e) {
1643 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1644 } finally {}
1645 }
1646 }
1647
Adam Cohended9f8d2010-11-03 13:25:16 -07001648 @Override
1649 public void onDetachedFromWindow() {
1650 super.onDetachedFromWindow();
1651 mVisible = false;
1652
Adam Cohend113e0c2010-11-11 10:48:05 -08001653 if (mAttached) {
1654 unregisterReceiver(mReceiver);
1655 mAttached = false;
1656 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001657 updateRunning();
1658 }
1659
1660 public void onWindowVisibilityChanged(int visibility) {
1661 mVisible = visibility == View.VISIBLE;
1662 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001663 // The following code used to be in onResume, but it turns out onResume is called when
1664 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1665 // is a more appropriate event to handle
1666 if (mVisible) {
1667 mAppsCustomizeTabHost.onWindowVisible();
1668 if (!mWorkspaceLoading) {
1669 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001670 // We want to let Launcher draw itself at least once before we force it to build
1671 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001672 // apps is nice and speedy.
1673 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001674 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001675 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001676 if (mStarted) return;
1677 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001678 // We delay the layer building a bit in order to give
1679 // other message processing a time to run. In particular
1680 // this avoids a delay in hiding the IME if it was
1681 // currently shown, because doing that may involve
1682 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001683 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001684 final ViewTreeObserver.OnDrawListener listener = this;
1685 mWorkspace.post(new Runnable() {
1686 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001687 if (mWorkspace != null &&
1688 mWorkspace.getViewTreeObserver() != null) {
1689 mWorkspace.getViewTreeObserver().
1690 removeOnDrawListener(listener);
1691 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001692 }
1693 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001694 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001695 }
1696 });
1697 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001698 // When Launcher comes back to foreground, a different Activity might be responsible for
1699 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001700 if (!DISABLE_MARKET_BUTTON) {
1701 updateAppMarketIcon();
1702 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001703 clearTypedText();
1704 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001705 }
1706
1707 private void sendAdvanceMessage(long delay) {
1708 mHandler.removeMessages(ADVANCE_MSG);
1709 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1710 mHandler.sendMessageDelayed(msg, delay);
1711 mAutoAdvanceSentTime = System.currentTimeMillis();
1712 }
1713
1714 private void updateRunning() {
1715 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1716 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1717 mAutoAdvanceRunning = autoAdvanceRunning;
1718 if (autoAdvanceRunning) {
1719 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1720 sendAdvanceMessage(delay);
1721 } else {
1722 if (!mWidgetsToAdvance.isEmpty()) {
1723 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1724 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1725 }
1726 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001727 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001728 }
1729 }
1730 }
1731
1732 private final Handler mHandler = new Handler() {
1733 @Override
1734 public void handleMessage(Message msg) {
1735 if (msg.what == ADVANCE_MSG) {
1736 int i = 0;
1737 for (View key: mWidgetsToAdvance.keySet()) {
1738 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1739 final int delay = mAdvanceStagger * i;
1740 if (v instanceof Advanceable) {
1741 postDelayed(new Runnable() {
1742 public void run() {
1743 ((Advanceable) v).advance();
1744 }
1745 }, delay);
1746 }
1747 i++;
1748 }
1749 sendAdvanceMessage(mAdvanceInterval);
1750 }
1751 }
1752 };
1753
1754 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001755 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001756 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1757 if (v instanceof Advanceable) {
1758 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001759 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001760 updateRunning();
1761 }
1762 }
1763
1764 void removeWidgetToAutoAdvance(View hostView) {
1765 if (mWidgetsToAdvance.containsKey(hostView)) {
1766 mWidgetsToAdvance.remove(hostView);
1767 updateRunning();
1768 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001769 }
1770
Joe Onorato9c1289c2009-08-17 11:03:03 -04001771 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001772 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001773 launcherInfo.hostView = null;
1774 }
1775
Winson Chung93eef082012-03-23 15:59:27 -07001776 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1777 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1778 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001779 }
1780
Winson Chunga6945242014-01-08 14:04:34 -08001781 public DragLayer getDragLayer() {
1782 return mDragLayer;
1783 }
1784
1785 public Workspace getWorkspace() {
1786 return mWorkspace;
1787 }
1788
1789 public Hotseat getHotseat() {
1790 return mHotseat;
1791 }
1792
Jorim Jaggid017f882014-01-14 17:08:48 -08001793 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001794 return mOverviewPanel;
1795 }
1796
1797 public SearchDropTargetBar getSearchBar() {
1798 return mSearchDropTargetBar;
1799 }
1800
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001801 public LauncherAppWidgetHost getAppWidgetHost() {
1802 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803 }
Romain Guycbb89e42009-06-08 15:52:54 -07001804
Winson Chunga9abd0e2010-10-27 17:18:37 -07001805 public LauncherModel getModel() {
1806 return mModel;
1807 }
1808
Winson Chunga6945242014-01-08 14:04:34 -08001809 public LauncherClings getLauncherClings() {
1810 return mLauncherClings;
1811 }
1812
1813 protected SharedPreferences getSharedPrefs() {
1814 return mSharedPrefs;
1815 }
1816
Bjorn Bringertc459e522013-06-07 19:36:01 +01001817 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001818 getWindow().closeAllPanels();
1819
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001820 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001821 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001822 }
1823
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 @Override
1825 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001826 long startTime = 0;
1827 if (DEBUG_RESUME_TIME) {
1828 startTime = System.currentTimeMillis();
1829 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 super.onNewIntent(intent);
1831
1832 // Close the menu
1833 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001834 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001835 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001836
Adam Cohened307df2013-10-02 09:37:31 -07001837 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1838 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1839 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001840
Adam Cohen6fecd412013-10-02 17:41:50 -07001841 if (mWorkspace == null) {
1842 // Can be cases where mWorkspace is null, this prevents a NPE
1843 return;
1844 }
1845 Folder openFolder = mWorkspace.getOpenFolder();
1846 // In all these cases, only animate if we're already on home
1847 mWorkspace.exitWidgetResizeMode();
1848 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001849 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001850 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001851 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001852
Adam Cohen6fecd412013-10-02 17:41:50 -07001853 closeFolder();
1854 exitSpringLoadedDragMode();
1855
1856 // If we are already on home, then just animate back to the workspace,
1857 // otherwise, just wait until onResume to set the state back to Workspace
1858 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001859 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001860 } else {
1861 mOnResumeState = State.WORKSPACE;
1862 }
1863
1864 final View v = getWindow().peekDecorView();
1865 if (v != null && v.getWindowToken() != null) {
1866 InputMethodManager imm = (InputMethodManager)getSystemService(
1867 INPUT_METHOD_SERVICE);
1868 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1869 }
1870
1871 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001872 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001873 mAppsCustomizeTabHost.reset();
1874 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001875
1876 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 }
Adam Cohened307df2013-10-02 09:37:31 -07001878
Michael Jurka447bf842013-05-15 14:52:15 +02001879 if (DEBUG_RESUME_TIME) {
1880 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1881 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 }
1883
Adam Coppa120b8e2013-11-12 16:26:04 +00001884 /**
1885 * Override point for subclasses to prevent movement to the default screen when the home
1886 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1887 */
1888 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1889 return true;
1890 }
1891
1892 /**
1893 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1894 */
1895 protected void onHomeIntent() {
1896 // Do nothing
1897 }
1898
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001900 public void onRestoreInstanceState(Bundle state) {
1901 super.onRestoreInstanceState(state);
1902 for (int page: mSynchronouslyBoundPages) {
1903 mWorkspace.restoreInstanceStateForChild(page);
1904 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905 }
1906
1907 @Override
1908 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001909 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001910 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1911 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001912 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001913 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914
Michael Jurka883f55b2010-10-21 15:47:14 -07001915 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001916 // We close any open folder since it will not be re-opened, and we need to make sure
1917 // this state is reflected.
1918 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919
Adam Cohendcd297f2013-06-18 13:13:40 -07001920 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001921 mWaitingForResult) {
1922 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001923 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001924 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1925 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001926 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1927 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1928 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001929 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 }
1931
1932 if (mFolderInfo != null && mWaitingForResult) {
1933 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1934 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1935 }
Michael Jurka946ad472010-07-09 18:05:18 -07001936
Winson Chung785d2eb2011-04-14 16:08:02 -07001937 // Save the current AppsCustomize tab
1938 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001939 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1940 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001941 if (currentTabTag != null) {
1942 outState.putString("apps_customize_currentTab", currentTabTag);
1943 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001944 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1945 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001946 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001947 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 }
1949
1950 @Override
1951 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001953
Winson Chunge7a03942011-08-05 15:05:12 -07001954 // Remove all pending runnables
1955 mHandler.removeMessages(ADVANCE_MSG);
1956 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001957 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001958
Winson Chungcd2b0142011-06-08 16:02:26 -07001959 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001960 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001961 mModel.stopLoader();
1962 app.setLauncher(null);
1963
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001965 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001967 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001968 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001969 mAppWidgetHost = null;
1970
1971 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972
1973 TextKeyListener.getInstance().release();
1974
Winson Chung81b52252012-08-27 15:34:29 -07001975 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1976 // to prevent leaking Launcher activities on orientation change.
1977 if (mModel != null) {
1978 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1979 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001980
1981 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001982 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001983
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001984 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001985 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001986 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001987 mWorkspace = null;
1988 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001989
Michael Jurka2ecf9952012-06-18 12:52:28 -07001990 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 }
1992
Adam Cohena9cf38f2011-05-02 15:36:58 -07001993 public DragController getDragController() {
1994 return mDragController;
1995 }
1996
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 @Override
1998 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001999 if (requestCode >= 0) {
2000 setWaitingForResult(true);
2001 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002 super.startActivityForResult(intent, requestCode);
2003 }
2004
Winson Chung70d72102011-08-12 11:24:35 -07002005 /**
2006 * Indicates that we want global search for this activity by setting the globalSearch
2007 * argument for {@link #startSearch} to true.
2008 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002010 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002012
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002013 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002014
Karl Rosaen138a0412009-04-23 19:00:21 -07002015 if (initialQuery == null) {
2016 // Use any text typed in the launcher as the initial query
2017 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002018 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 if (appSearchData == null) {
2020 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002021 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 }
Winson Chungadf0c182012-08-23 14:59:07 -07002023 Rect sourceBounds = new Rect();
2024 if (mSearchDropTargetBar != null) {
2025 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2026 }
Romain Guycbb89e42009-06-08 15:52:54 -07002027
Bjorn Bringertc459e522013-06-07 19:36:01 +01002028 startSearch(initialQuery, selectInitialQuery,
2029 appSearchData, sourceBounds);
2030 }
2031
2032 public void startSearch(String initialQuery,
2033 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002034 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002035 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002036 }
2037
2038 /**
2039 * Starts the global search activity. This code is a copied from SearchManager
2040 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002041 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002042 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002043 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002044 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2045 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2046 if (globalSearchActivity == null) {
2047 Log.w(TAG, "No global search activity found.");
2048 return;
2049 }
2050 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2051 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2052 intent.setComponent(globalSearchActivity);
2053 // Make sure that we have a Bundle to put source in
2054 if (appSearchData == null) {
2055 appSearchData = new Bundle();
2056 } else {
2057 appSearchData = new Bundle(appSearchData);
2058 }
2059 // Set source to package name of app that starts global search, if not set already.
2060 if (!appSearchData.containsKey("source")) {
2061 appSearchData.putString("source", getPackageName());
2062 }
2063 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2064 if (!TextUtils.isEmpty(initialQuery)) {
2065 intent.putExtra(SearchManager.QUERY, initialQuery);
2066 }
2067 if (selectInitialQuery) {
2068 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2069 }
2070 intent.setSourceBounds(sourceBounds);
2071 try {
2072 startActivity(intent);
2073 } catch (ActivityNotFoundException ex) {
2074 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2075 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 }
2077
Yura4f93ec62014-02-04 14:15:21 +00002078 public boolean isOnCustomContent() {
2079 return mWorkspace.isOnOrMovingToCustomContent();
2080 }
2081
Winson Chung70d72102011-08-12 11:24:35 -07002082 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002083 public boolean onPrepareOptionsMenu(Menu menu) {
2084 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002085 if (!isOnCustomContent()) {
2086 // Close any open folders
2087 closeFolder();
2088 // Stop resizing any widgets
2089 mWorkspace.exitWidgetResizeMode();
2090 if (!mWorkspace.isInOverviewMode()) {
2091 // Show the overview mode
2092 showOverviewMode(true);
2093 } else {
2094 showWorkspace(true);
2095 }
Winson Chunge0298742014-01-17 12:03:00 -08002096 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002097 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002098 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002100 @Override
2101 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002102 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002103 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002104 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002105 }
2106
Joe Onorato9c1289c2009-08-17 11:03:03 -04002107 public boolean isWorkspaceLocked() {
2108 return mWorkspaceLoading || mWaitingForResult;
2109 }
2110
Adam Cohen517a7f52014-03-01 12:12:59 -08002111 public boolean isWorkspaceLoading() {
2112 return mWorkspaceLoading;
2113 }
2114
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002115 private void setWorkspaceLoading(boolean value) {
2116 boolean isLocked = isWorkspaceLocked();
2117 mWorkspaceLoading = value;
2118 if (isLocked != isWorkspaceLocked()) {
2119 onWorkspaceLockedChanged();
2120 }
2121 }
2122
2123 private void setWaitingForResult(boolean value) {
2124 boolean isLocked = isWorkspaceLocked();
2125 mWaitingForResult = value;
2126 if (isLocked != isWorkspaceLocked()) {
2127 onWorkspaceLockedChanged();
2128 }
2129 }
2130
2131 protected void onWorkspaceLockedChanged() { }
2132
Michael Jurka0280c3b2010-09-17 15:00:07 -07002133 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002134 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002135 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002136 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2137 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002138 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002139 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002140 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002141
Adam Cohenad4e15c2013-10-17 16:21:35 -07002142 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2143 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2144 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2145 }
2146
2147 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2148 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2149 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002150 if (appWidgetInfo.configure != null) {
2151 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002152 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002153
Bjorn Bringert7984c942009-12-09 15:38:25 +00002154 // Launch over to configure widget, if needed
2155 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002156 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002157 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002158 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002160 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002161 Runnable onComplete = new Runnable() {
2162 @Override
2163 public void run() {
2164 // Exit spring loaded mode if necessary after adding the widget
2165 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2166 null);
2167 }
2168 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002169 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002170 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002171 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002172 }
2173 }
Romain Guycbb89e42009-06-08 15:52:54 -07002174
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002175 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002176 // Close any folders that may be open.
2177 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002178 mWorkspace.moveToCustomContentScreen(animate);
2179 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002180 /**
2181 * Process a shortcut drop.
2182 *
2183 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002184 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002185 * @param cell The cell it should be added to, optional
2186 * @param position The location on the screen where it was dropped, optional
2187 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002188 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002189 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002190 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002191 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002192 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002193 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002194
2195 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002196 mPendingAddInfo.cellX = cell[0];
2197 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002198 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002199
2200 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2201 createShortcutIntent.setComponent(componentName);
2202 processShortcut(createShortcutIntent);
2203 }
2204
Adam Cohenfbba09b2011-07-18 21:43:05 -07002205 /**
2206 * Process a widget drop.
2207 *
2208 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002209 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002210 * @param cell The cell it should be added to, optional
2211 * @param position The location on the screen where it was dropped, optional
2212 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002213 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002214 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002215 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002216 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002217 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002218 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002219 mPendingAddInfo.minSpanX = info.minSpanX;
2220 mPendingAddInfo.minSpanY = info.minSpanY;
2221
Adam Cohenfbba09b2011-07-18 21:43:05 -07002222 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002223 mPendingAddInfo.cellX = cell[0];
2224 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002225 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002226 if (span != null) {
2227 mPendingAddInfo.spanX = span[0];
2228 mPendingAddInfo.spanY = span[1];
2229 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002230
Adam Cohened66b2b2012-01-23 17:28:51 -08002231 AppWidgetHostView hostView = info.boundWidget;
2232 int appWidgetId;
2233 if (hostView != null) {
2234 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002235 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002236 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002237 // In this case, we either need to start an activity to get permission to bind
2238 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002239 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002240 Bundle options = info.bindOptions;
2241
2242 boolean success = false;
2243 if (options != null) {
2244 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2245 info.componentName, options);
2246 } else {
2247 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2248 info.componentName);
2249 }
2250 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002251 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002252 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002253 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002254 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2255 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2256 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002257 // TODO: we need to make sure that this accounts for the options bundle.
2258 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002259 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2260 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002261 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002262 }
2263
Joe Onoratodeb98af2010-02-19 14:59:39 -08002264 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002265 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002266 }
2267
Winson Chung24ab2f12010-09-16 14:10:47 -07002268 void processWallpaper(Intent intent) {
2269 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2270 }
2271
Adam Cohendcd297f2013-06-18 13:13:40 -07002272 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002273 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002274 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002275 folderInfo.title = getText(R.string.folder_name);
2276
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002277 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002278 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002279 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002280 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002281
2282 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002283 FolderIcon newFolder =
2284 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002285 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002286 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002287 // Force measure the new folder icon
2288 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2289 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002290 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002291 }
Romain Guycbb89e42009-06-08 15:52:54 -07002292
Joe Onorato9c1289c2009-08-17 11:03:03 -04002293 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002294 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002295 }
2296
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002297 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002298 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002299 }
2300
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002301 /**
2302 * Registers various content observers. The current implementation registers
2303 * only a favorites observer to keep track of the favorites applications.
2304 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002305 private void registerContentObservers() {
2306 ContentResolver resolver = getContentResolver();
2307 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2308 true, mWidgetObserver);
2309 }
2310
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311 @Override
2312 public boolean dispatchKeyEvent(KeyEvent event) {
2313 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2314 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002315 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002316 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002317 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002318 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002319 dumpState();
2320 return true;
2321 }
2322 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002323 }
2324 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2325 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002326 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002327 return true;
2328 }
2329 }
2330
2331 return super.dispatchKeyEvent(event);
2332 }
2333
Joe Onorato88ec0992009-11-19 13:16:06 -08002334 @Override
2335 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002336 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002337 if (mAppsCustomizeContent.getContentType() ==
2338 AppsCustomizePagedView.ContentType.Applications) {
2339 showWorkspace(true);
2340 } else {
2341 showOverviewMode(true);
2342 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002343 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002344 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002345 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002346 Folder openFolder = mWorkspace.getOpenFolder();
2347 if (openFolder.isEditingName()) {
2348 openFolder.dismissEditingName();
2349 } else {
2350 closeFolder();
2351 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002352 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002353 mWorkspace.exitWidgetResizeMode();
2354
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002355 // Back button is a no-op here, but give at least some feedback for the button press
2356 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002357 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002358 }
2359
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002360 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002361 * Re-listen when widgets are reset.
2362 */
2363 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002364 if (mAppWidgetHost != null) {
2365 mAppWidgetHost.startListening();
2366 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002367 }
2368
2369 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 * Launches the intent referred by the clicked shortcut.
2371 *
2372 * @param v The view representing the clicked shortcut.
2373 */
2374 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002375 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2376 // view has detached (it's possible for this to happen if the view is removed mid touch).
2377 if (v.getWindowToken() == null) {
2378 return;
2379 }
2380
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002381 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002382 return;
2383 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002384
Adam Cohen1697b792013-09-17 19:08:21 -07002385 if (v instanceof Workspace) {
2386 if (mWorkspace.isInOverviewMode()) {
2387 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002388 }
2389 return;
2390 }
2391
2392 if (v instanceof CellLayout) {
2393 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002394 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002395 }
2396 }
2397
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002398 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002399 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002400 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002401 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002402 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002403 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002404 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002405 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002406 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002407 }
2408 }
2409
Michael Jurka0e260592010-06-30 17:07:39 -07002410 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002411 return false;
2412 }
2413
Michael Jurkaaf442092010-06-10 17:01:57 -07002414 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002415 * Event handler for the search button
2416 *
2417 * @param v The view that was clicked.
2418 */
2419 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002420 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2421
Amith Yamasania135ba82011-08-09 17:42:01 -07002422 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002423 }
2424
2425 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002426 * Event handler for the voice button
2427 *
2428 * @param v The view that was clicked.
2429 */
2430 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002431 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002432
Bjorn Bringertc459e522013-06-07 19:36:01 +01002433 startVoice();
2434 }
2435
2436 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002437 try {
2438 final SearchManager searchManager =
2439 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2440 ComponentName activityName = searchManager.getGlobalSearchActivity();
2441 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002442 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002443 if (activityName != null) {
2444 intent.setPackage(activityName.getPackageName());
2445 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002446 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002447 } catch (ActivityNotFoundException e) {
2448 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002449 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002450 startActivitySafely(null, intent, "onClickVoiceButton");
2451 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002452 }
2453
2454 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002455 * Event handler for the "grid" button that appears on the home screen, which
2456 * enters all apps mode.
2457 *
2458 * @param v The view that was clicked.
2459 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002460 protected void onClickAllAppsButton(View v) {
2461 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2462 if (isAllAppsVisible()) {
2463 showWorkspace(true);
2464 } else {
2465 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2466 }
2467 }
2468
2469 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002470 * Event handler for a paged view icon click.
2471 * @param v The view that was clicked.
2472 * @param appInfo The {link AppInfo} of the view.
2473 */
2474 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2475 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2476 startActivitySafely(v, appInfo.intent, appInfo);
2477 getStats().recordLaunch(appInfo.intent);
2478 }
2479
2480 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002481 * Event handler for an app shortcut click.
2482 *
2483 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2484 */
2485 protected void onClickAppShortcut(View v) {
2486 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2487 Object tag = v.getTag();
2488 if (!(tag instanceof ShortcutInfo)) {
2489 throw new IllegalArgumentException("Input must be a Shortcut");
2490 }
2491
2492 // Open shortcut
2493 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2494 final Intent intent = shortcut.intent;
2495
2496 // Check for special shortcuts
2497 if (intent.getComponent() != null) {
2498 final String shortcutClass = intent.getComponent().getClassName();
2499
2500 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2501 MemoryDumpActivity.startDump(this);
2502 return;
2503 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2504 toggleShowWeightWatcher();
2505 return;
2506 }
2507 }
2508
2509 // Start activities
2510 int[] pos = new int[2];
2511 v.getLocationOnScreen(pos);
2512 intent.setSourceBounds(new Rect(pos[0], pos[1],
2513 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2514
2515 boolean success = startActivitySafely(v, intent, tag);
2516
2517 mStats.recordLaunch(intent, shortcut);
2518
2519 if (success && v instanceof BubbleTextView) {
2520 mWaitingForResume = (BubbleTextView) v;
2521 mWaitingForResume.setStayPressed(true);
2522 }
2523 }
2524
2525 /**
2526 * Event handler for a folder icon click.
2527 *
2528 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2529 */
2530 protected void onClickFolderIcon(View v) {
2531 if (LOGD) Log.d(TAG, "onClickFolder");
2532 if (!(v instanceof FolderIcon)){
2533 throw new IllegalArgumentException("Input must be a FolderIcon");
2534 }
2535
2536 FolderIcon folderIcon = (FolderIcon) v;
2537 final FolderInfo info = folderIcon.getFolderInfo();
2538 Folder openFolder = mWorkspace.getFolderForTag(info);
2539
2540 // If the folder info reports that the associated folder is open, then verify that
2541 // it is actually opened. There have been a few instances where this gets out of sync.
2542 if (info.opened && openFolder == null) {
2543 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2544 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2545 info.opened = false;
2546 }
2547
2548 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2549 // Close any open folder
2550 closeFolder();
2551 // Open the requested folder
2552 openFolder(folderIcon);
2553 } else {
2554 // Find the open folder...
2555 int folderScreen;
2556 if (openFolder != null) {
2557 folderScreen = mWorkspace.getPageForView(openFolder);
2558 // .. and close it
2559 closeFolder(openFolder);
2560 if (folderScreen != mWorkspace.getCurrentPage()) {
2561 // Close any folder open on the current screen
2562 closeFolder();
2563 // Pull the folder onto this screen
2564 openFolder(folderIcon);
2565 }
2566 }
2567 }
Michael Jurka5130e402011-10-13 04:55:35 -07002568 }
2569
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002570 /**
2571 * Event handler for the (Add) Widgets button that appears after a long press
2572 * on the home screen.
2573 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002574 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002575 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002576 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2577 }
2578
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002579 /**
2580 * Event handler for the wallpaper picker button that appears after a long press
2581 * on the home screen.
2582 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002583 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002584 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2585 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2586 pickWallpaper.setComponent(getWallpaperPickerComponent());
2587 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2588 }
2589
2590 /**
2591 * Event handler for a click on the settings button that appears after a long press
2592 * on the home screen.
2593 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002594 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002595 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2596 }
2597
Michael Jurka5130e402011-10-13 04:55:35 -07002598 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002599 // Provide the same haptic feedback that the system offers for virtual keys.
2600 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002601 }
2602
Adam Cohen61f560d2013-09-30 15:58:20 -07002603 public void performHapticFeedbackOnTouchDown(View v) {
2604 // Provide the same haptic feedback that the system offers for virtual keys.
2605 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2606 }
2607
2608 public View.OnTouchListener getHapticFeedbackTouchListener() {
2609 if (mHapticFeedbackTouchListener == null) {
2610 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2611 @Override
2612 public boolean onTouch(View v, MotionEvent event) {
2613 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2614 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2615 }
2616 return false;
2617 }
2618 };
2619 }
2620 return mHapticFeedbackTouchListener;
2621 }
2622
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002623 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002624 if (!DISABLE_MARKET_BUTTON) {
2625 if (mAppMarketIntent != null) {
2626 startActivitySafely(v, mAppMarketIntent, "app market");
2627 } else {
2628 Log.e(TAG, "Invalid app market intent.");
2629 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002630 }
2631 }
2632
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002633 public void onDragStarted(View view) {}
2634
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002635 /**
2636 * Called when the user stops interacting with the launcher.
2637 * This implies that the user is now on the homescreen and is not doing housekeeping.
2638 */
2639 protected void onInteractionEnd() {}
2640
2641 /**
2642 * Called when the user starts interacting with the launcher.
2643 * The possible interactions are:
2644 * - open all apps
2645 * - reorder an app shortcut, or a widget
2646 * - open the overview mode.
2647 * This is a good time to stop doing things that only make sense
2648 * when the user is on the homescreen and not doing housekeeping.
2649 */
2650 protected void onInteractionBegin() {}
2651
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002652 void startApplicationDetailsActivity(ComponentName componentName) {
2653 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002654 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2655 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002656 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2657 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002658 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002659 }
2660
Michael Jurka1e2f4652013-07-08 18:03:46 -07002661 // returns true if the activity was started
2662 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002663 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002664 // System applications cannot be installed. For now, show a toast explaining that.
2665 // We may give them the option of disabling apps this way.
2666 int messageId = R.string.uninstall_system_app_text;
2667 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002668 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002669 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002670 String packageName = componentName.getPackageName();
2671 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002672 Intent intent = new Intent(
2673 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002674 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2675 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002676 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002677 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002678 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002679 }
2680
Michael Jurka86a720e2012-05-09 11:23:23 -07002681 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002682 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002683 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002684 // Only launch using the new animation if the shortcut has not opted out (this is a
2685 // private contract between launcher and may be ignored in the future).
2686 boolean useLaunchAnimation = (v != null) &&
2687 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002688 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2689 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002690
Kenny Guy1317e2d2014-05-08 18:52:50 +01002691 UserHandleCompat user = null;
2692 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2693 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2694 user = userManager.getUserForSerialNumber(serialNumber);
2695 }
2696
2697 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002698 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002699 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2700 v.getMeasuredWidth(), v.getMeasuredHeight());
Kenny Guy1317e2d2014-05-08 18:52:50 +01002701 optsBundle = opts.toBundle();
2702 }
2703
2704 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2705 // Could be launching some bookkeeping activity
2706 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002707 } else {
Kenny Guy1317e2d2014-05-08 18:52:50 +01002708 launcherApps.startActivityForProfile(intent.getComponent(),
2709 intent.getSourceBounds(), optsBundle, user);
Winson Chungc7450e32012-04-17 17:34:08 -07002710 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002711 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002712 } catch (SecurityException e) {
2713 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002714 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002715 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002716 "or use the exported attribute for this activity. "
2717 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002718 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002719 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002720 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002721
Michael Jurka86a720e2012-05-09 11:23:23 -07002722 boolean startActivitySafely(View v, Intent intent, Object tag) {
2723 boolean success = false;
2724 try {
2725 success = startActivity(v, intent, tag);
2726 } catch (ActivityNotFoundException e) {
2727 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2728 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2729 }
2730 return success;
2731 }
2732
Adam Cohen268c4752012-06-06 17:47:33 -07002733 /**
2734 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2735 * in the DragLayer in the exact absolute location of the original FolderIcon.
2736 */
2737 private void copyFolderIconToImage(FolderIcon fi) {
2738 final int width = fi.getMeasuredWidth();
2739 final int height = fi.getMeasuredHeight();
2740
2741 // Lazy load ImageView, Bitmap and Canvas
2742 if (mFolderIconImageView == null) {
2743 mFolderIconImageView = new ImageView(this);
2744 }
2745 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2746 mFolderIconBitmap.getHeight() != height) {
2747 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2748 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2749 }
2750
2751 DragLayer.LayoutParams lp;
2752 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2753 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2754 } else {
2755 lp = new DragLayer.LayoutParams(width, height);
2756 }
2757
Adam Cohen307fe232012-08-16 17:55:58 -07002758 // The layout from which the folder is being opened may be scaled, adjust the starting
2759 // view size by this scale factor.
2760 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002761 lp.customPosition = true;
2762 lp.x = mRectForFolderAnimation.left;
2763 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002764 lp.width = (int) (scale * width);
2765 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002766
2767 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2768 fi.draw(mFolderIconCanvas);
2769 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002770 if (fi.getFolder() != null) {
2771 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2772 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002773 }
Adam Cohen268c4752012-06-06 17:47:33 -07002774 // Just in case this image view is still in the drag layer from a previous animation,
2775 // we remove it and re-add it.
2776 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2777 mDragLayer.removeView(mFolderIconImageView);
2778 }
2779 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002780 if (fi.getFolder() != null) {
2781 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002782 }
Adam Cohen268c4752012-06-06 17:47:33 -07002783 }
2784
Adam Cohen2801caf2011-05-13 20:57:39 -07002785 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002786 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002787 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2788 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2789 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2790
Adam Cohenc51934b2011-07-26 21:07:43 -07002791 FolderInfo info = (FolderInfo) fi.getTag();
2792 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2793 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002794 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2795 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002796 }
2797
Adam Cohen268c4752012-06-06 17:47:33 -07002798 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2799 copyFolderIconToImage(fi);
2800 fi.setVisibility(View.INVISIBLE);
2801
Michael Jurka2ecf9952012-06-18 12:52:28 -07002802 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002803 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002804 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2805 oa.start();
2806 }
2807
Adam Cohen268c4752012-06-06 17:47:33 -07002808 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002809 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002810 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2811 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2812 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2813
Adam Cohen268c4752012-06-06 17:47:33 -07002814 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002815
Adam Cohen268c4752012-06-06 17:47:33 -07002816 // We remove and re-draw the FolderIcon in-case it has changed
2817 mDragLayer.removeView(mFolderIconImageView);
2818 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002819 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002820 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002821 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002822 oa.addListener(new AnimatorListenerAdapter() {
2823 @Override
2824 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002825 if (cl != null) {
2826 cl.clearFolderLeaveBehind();
2827 // Remove the ImageView copy of the FolderIcon and make the original visible.
2828 mDragLayer.removeView(mFolderIconImageView);
2829 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002830 }
2831 }
2832 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002833 oa.start();
2834 }
2835
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002836 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002837 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002838 * is animated relative to the specified View. If the View is null, no animation
2839 * is played.
2840 *
2841 * @param folderInfo The FolderInfo describing the folder to open.
2842 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002843 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002844 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002845 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002846
Adam Cohena9cf38f2011-05-02 15:36:58 -07002847 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002848
Adam Cohen4554ee12011-08-03 16:13:21 -07002849 // Just verify that the folder hasn't already been added to the DragLayer.
2850 // There was a one-off crash where the folder had a parent already.
2851 if (folder.getParent() == null) {
2852 mDragLayer.addView(folder);
2853 mDragController.addDropTarget((DropTarget) folder);
2854 } else {
2855 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2856 folder.getParent() + ").");
2857 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002858 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002859 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002860
2861 // Notify the accessibility manager that this folder "window" has appeared and occluded
2862 // the workspace items
2863 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2864 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002865 }
2866
2867 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002868 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002869 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002870 if (folder.isEditingName()) {
2871 folder.dismissEditingName();
2872 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002873 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002874
2875 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002876 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002877 }
2878 }
2879
2880 void closeFolder(Folder folder) {
2881 folder.getInfo().opened = false;
2882
2883 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2884 if (parent != null) {
2885 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2886 shrinkAndFadeInFolderIcon(fi);
2887 }
2888 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002889
2890 // Notify the accessibility manager that this folder "window" has disappeard and no
2891 // longer occludeds the workspace items
2892 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002893 }
2894
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002895 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002896 if (!isDraggingEnabled()) return false;
2897 if (isWorkspaceLocked()) return false;
2898 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899
Adam Cohen1697b792013-09-17 19:08:21 -07002900 if (v instanceof Workspace) {
2901 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002902 if (mWorkspace.enterOverviewMode()) {
2903 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2904 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2905 return true;
2906 } else {
2907 return false;
2908 }
Adam Cohen1697b792013-09-17 19:08:21 -07002909 }
Adam Cohen1697b792013-09-17 19:08:21 -07002910 }
2911
Adam Cohene0aaa0d2014-05-12 12:44:22 -07002912 CellLayout.CellInfo longClickCellInfo = null;
2913 View itemUnderLongClick = null;
2914 if (v.getTag() instanceof ItemInfo) {
2915 ItemInfo info = (ItemInfo) v.getTag();
2916 longClickCellInfo = new CellLayout.CellInfo(v, info);;
2917 itemUnderLongClick = longClickCellInfo.cell;
2918 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002919 }
2920
Winson Chung3d503fb2011-07-13 17:25:49 -07002921 // The hotseat touch handling does not go through Workspace, and we always allow long press
2922 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05002923 final boolean inHotseat = isHotseatLayout(v);
2924 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002925 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002926 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002927 // User long pressed on empty space
2928 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2929 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2930 // Disabling reordering until we sort out some issues.
2931 if (mWorkspace.isInOverviewMode()) {
2932 mWorkspace.startReordering(v);
2933 } else {
2934 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002935 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002936 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002937 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2938 mHotseat.getOrderInHotseat(
2939 longClickCellInfo.cellX,
2940 longClickCellInfo.cellY));
2941 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002942 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002943 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002944 }
2945 }
2946 }
2947 return true;
2948 }
2949
Winson Chung3d503fb2011-07-13 17:25:49 -07002950 boolean isHotseatLayout(View layout) {
2951 return mHotseat != null && layout != null &&
2952 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2953 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002954
Winson Chung3d503fb2011-07-13 17:25:49 -07002955 /**
2956 * Returns the CellLayout of the specified container at the specified screen.
2957 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002958 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002959 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2960 if (mHotseat != null) {
2961 return mHotseat.getLayout();
2962 } else {
2963 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002964 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002965 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002966 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002967 }
2968 }
2969
Daniel Sandler843e8602010-06-07 14:59:01 -04002970 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002971 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002972 }
2973
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002974 /**
2975 * Helper method for the cameraZoomIn/cameraZoomOut animations
2976 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002977 * @param scaleFactor The scale factor used for the zoom
2978 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002979 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002980 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002981 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002982 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002983
Craig Mautner360310b2012-10-26 15:13:08 -07002984 private void setWorkspaceBackground(boolean workspace) {
2985 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002986 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002987 }
2988
Selim Cinek3a8a8f72014-01-16 10:38:38 -08002989 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002990 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2991 int curflags = getWindow().getAttributes().flags
2992 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2993 if (wpflags != curflags) {
2994 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2995 }
Craig Mautner360310b2012-10-26 15:13:08 -07002996 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002997 }
2998
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002999 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3000 if (v instanceof LauncherTransitionable) {
3001 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3002 }
3003 }
3004
Michael Jurkabed61d22012-02-14 22:51:29 -08003005 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3006 if (v instanceof LauncherTransitionable) {
3007 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3008 }
Winson Chung70442722012-02-10 15:43:22 -08003009
3010 // Update the workspace transition step as well
3011 dispatchOnLauncherTransitionStep(v, 0f);
3012 }
3013
3014 private void dispatchOnLauncherTransitionStep(View v, float t) {
3015 if (v instanceof LauncherTransitionable) {
3016 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3017 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003018 }
3019
3020 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3021 if (v instanceof LauncherTransitionable) {
3022 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3023 }
Winson Chung70442722012-02-10 15:43:22 -08003024
3025 // Update the workspace transition step as well
3026 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003027 }
3028
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003029 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003030 * Things to test when changing the following seven functions.
3031 * - Home from workspace
3032 * - from center screen
3033 * - from other screens
3034 * - Home from all apps
3035 * - from center screen
3036 * - from other screens
3037 * - Back from all apps
3038 * - from center screen
3039 * - from other screens
3040 * - Launch app from workspace and quit
3041 * - with back
3042 * - with home
3043 * - Launch app from all apps and quit
3044 * - with back
3045 * - with home
3046 * - Go to a screen that's not the default, then all
3047 * apps, and launch and app, and go back
3048 * - with back
3049 * -with home
3050 * - On workspace, long press power and go back
3051 * - with back
3052 * - with home
3053 * - On all apps, long press power and go back
3054 * - with back
3055 * - with home
3056 * - On workspace, power off
3057 * - On all apps, power off
3058 * - Launch an app and turn off the screen while in that app
3059 * - Go back with home key
3060 * - Go back with back key TODO: make this not go to workspace
3061 * - From all apps
3062 * - From workspace
3063 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3064 * - From all apps
3065 * - From the center workspace
3066 * - From another workspace
3067 */
3068
3069 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003070 * Zoom the camera out from the workspace to reveal 'toView'.
3071 * Assumes that the view to show is anchored at either the very top or very bottom
3072 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003073 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003074 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003075 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3076 showAppsCustomizeHelper(animated, springLoaded, contentType);
3077 }
3078 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3079 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003080 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003081 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003082 mStateAnimation.cancel();
3083 mStateAnimation = null;
3084 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003085 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003086
Winson Chungf0ea4d32011-06-06 14:27:16 -07003087 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3088 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3089 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003090 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003091 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003092 final int startDelay =
3093 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003094
Michael Jurkab3e22d92011-10-31 15:58:33 -07003095 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003096
Michael Jurkad74c9842011-07-10 12:44:21 -07003097 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003098 Animator workspaceAnim =
3099 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003100 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003101 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3102 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003103 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3104 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003105
3106 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003107 toView.setScaleX(scale);
3108 toView.setScaleY(scale);
3109 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3110 scaleAnim.
3111 scaleX(1f).scaleY(1f).
3112 setDuration(duration).
3113 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003114
Winson Chungf0ea4d32011-06-06 14:27:16 -07003115 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003116 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003117 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003118 .ofFloat(toView, "alpha", 0f, 1f)
3119 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003120 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003121 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3122 @Override
3123 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003124 if (animation == null) {
3125 throw new RuntimeException("animation is null");
3126 }
Winson Chung70442722012-02-10 15:43:22 -08003127 float t = (Float) animation.getAnimatedValue();
3128 dispatchOnLauncherTransitionStep(fromView, t);
3129 dispatchOnLauncherTransitionStep(toView, t);
3130 }
3131 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003132
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003133 // toView should appear right at the end of the workspace shrink
3134 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003135 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003136 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003137 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003138
3139 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003140 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003141 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003142 // Prepare the position
3143 toView.setTranslationX(0.0f);
3144 toView.setTranslationY(0.0f);
3145 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003146 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003147 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003148 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003149 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003150 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3151 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003152
Winson Chungc7d2b602012-05-16 17:02:20 -07003153 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003154 if (mSearchDropTargetBar != null) {
3155 mSearchDropTargetBar.hideSearchBar(false);
3156 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003157 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003158 });
3159
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003160 if (workspaceAnim != null) {
3161 mStateAnimation.play(workspaceAnim);
3162 }
Michael Jurka1899a362011-11-03 13:50:45 -07003163
3164 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003165
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003166 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3167 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003168
3169 // If any of the objects being animated haven't been measured/laid out
3170 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003171 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003172 (mWorkspace.getMeasuredWidth() == 0) ||
3173 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003174 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003175 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003176
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003177 final AnimatorSet stateAnimation = mStateAnimation;
3178 final Runnable startAnimRunnable = new Runnable() {
3179 public void run() {
3180 // Check that mStateAnimation hasn't changed while
3181 // we waited for a layout/draw pass
3182 if (mStateAnimation != stateAnimation)
3183 return;
3184 setPivotsForZoom(toView, scale);
3185 dispatchOnLauncherTransitionStart(fromView, animated, false);
3186 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003187 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003188 }
3189 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003190 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003191 final ViewTreeObserver observer = toView.getViewTreeObserver();
3192 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3193 public void onGlobalLayout() {
3194 startAnimRunnable.run();
3195 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3196 }
3197 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003198 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003199 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003200 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003201 } else {
3202 toView.setTranslationX(0.0f);
3203 toView.setTranslationY(0.0f);
3204 toView.setScaleX(1.0f);
3205 toView.setScaleY(1.0f);
3206 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003207 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003208
Daniel Sandlere4f98912013-06-25 15:13:26 -04003209 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003210 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003211 if (mSearchDropTargetBar != null) {
3212 mSearchDropTargetBar.hideSearchBar(false);
3213 }
Michael Jurkaabded662011-03-04 12:06:57 -08003214 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003215 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003216 dispatchOnLauncherTransitionStart(fromView, animated, false);
3217 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003218 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003219 dispatchOnLauncherTransitionStart(toView, animated, false);
3220 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003221 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003222 }
3223
3224 /**
3225 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003226 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003227 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003228 */
Adam Cohened307df2013-10-02 09:37:31 -07003229 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003230 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003231
Michael Jurkab3e22d92011-10-31 15:58:33 -07003232 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003233 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003234 mStateAnimation.cancel();
3235 mStateAnimation = null;
3236 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003237 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003238
Winson Chungf0ea4d32011-06-06 14:27:16 -07003239 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003240 final int fadeOutDuration =
3241 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003242 final float scaleFactor = (float)
3243 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3244 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003245 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003246 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003247 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003248 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3249 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003250 toState, animated, stagger, -1);
3251 } else if (toState == Workspace.State.SPRING_LOADED ||
3252 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003253 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003254 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003255 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003256
Michael Jurkab3e22d92011-10-31 15:58:33 -07003257 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003258 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003259 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003260 final LauncherViewPropertyAnimator scaleAnim =
3261 new LauncherViewPropertyAnimator(fromView);
3262 scaleAnim.
3263 scaleX(scaleFactor).scaleY(scaleFactor).
3264 setDuration(duration).
3265 setInterpolator(new Workspace.ZoomInInterpolator());
3266
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003267 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003268 .ofFloat(fromView, "alpha", 1f, 0f)
3269 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003270 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003271 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3272 @Override
3273 public void onAnimationUpdate(ValueAnimator animation) {
3274 float t = 1f - (Float) animation.getAnimatedValue();
3275 dispatchOnLauncherTransitionStep(fromView, t);
3276 dispatchOnLauncherTransitionStep(toView, t);
3277 }
3278 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003279
Michael Jurka2ecf9952012-06-18 12:52:28 -07003280 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003281
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003282 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3283 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003284 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003285
3286 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003287 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003288 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003289 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003290 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3291 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003292 if (onCompleteRunnable != null) {
3293 onCompleteRunnable.run();
3294 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003295 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003296 }
3297 });
3298
Winson Chungf0ea4d32011-06-06 14:27:16 -07003299 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003300 if (workspaceAnim != null) {
3301 mStateAnimation.play(workspaceAnim);
3302 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003303 dispatchOnLauncherTransitionStart(fromView, animated, true);
3304 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003305 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003306 } else {
3307 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003308 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003309 dispatchOnLauncherTransitionStart(fromView, animated, true);
3310 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003311 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003312 dispatchOnLauncherTransitionStart(toView, animated, true);
3313 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003314 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003315 }
3316
Michael Jurkae326f182011-11-21 14:05:46 -08003317 @Override
3318 public void onTrimMemory(int level) {
3319 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003320 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003321 mAppsCustomizeTabHost.onTrimMemory();
3322 }
3323 }
3324
Adam Cohened307df2013-10-02 09:37:31 -07003325 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003326 showWorkspace(animated, null);
3327 }
3328
Adam Cohened307df2013-10-02 09:37:31 -07003329 protected void showWorkspace() {
3330 showWorkspace(true);
3331 }
3332
Adam Cohened66b2b2012-01-23 17:28:51 -08003333 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003334 if (mWorkspace.isInOverviewMode()) {
3335 mWorkspace.exitOverviewMode(animated);
3336 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003337 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003338 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003339 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003340 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003341
Winson Chungc7d2b602012-05-16 17:02:20 -07003342 // Show the search bar (only animate if we were showing the drop target bar in spring
3343 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003344 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003345 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003346 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003347
Michael Jurkab3e22d92011-10-31 15:58:33 -07003348 // Set focus to the AppsCustomize button
3349 if (mAllAppsButton != null) {
3350 mAllAppsButton.requestFocus();
3351 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003352 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003353
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003354 // Change the state *after* we've called all the transition code
3355 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003356
Winson Chung5fb63472011-02-02 17:03:37 -08003357 // Resume the auto-advance of widgets
3358 mUserPresent = true;
3359 updateRunning();
3360
alanv1d4fde62012-10-17 13:15:47 -07003361 // Send an accessibility event to announce the context change
3362 getWindow().getDecorView()
3363 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003364
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003365 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003366 }
3367
Adam Cohened307df2013-10-02 09:37:31 -07003368 void showOverviewMode(boolean animated) {
3369 mWorkspace.setVisibility(View.VISIBLE);
3370 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3371 mState = State.WORKSPACE;
3372 onWorkspaceShown(animated);
3373 }
3374
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003375 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003376 }
3377
Winson Chung82963d52013-10-09 11:20:57 -07003378 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3379 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003380 if (mState != State.WORKSPACE) return;
3381
Winson Chung82963d52013-10-09 11:20:57 -07003382 if (resetPageToZero) {
3383 mAppsCustomizeTabHost.reset();
3384 }
Winson Chungc58497e2013-09-03 17:48:37 -07003385 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003386 mAppsCustomizeTabHost.requestFocus();
3387
Michael Jurkab3e22d92011-10-31 15:58:33 -07003388 // Change the state *after* we've called all the transition code
3389 mState = State.APPS_CUSTOMIZE;
3390
3391 // Pause the auto-advance of widgets until we are out of AllApps
3392 mUserPresent = false;
3393 updateRunning();
3394 closeFolder();
3395
3396 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003397 getWindow().getDecorView()
3398 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003399 }
3400
Adam Cohen7777d962011-08-18 18:58:38 -07003401 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003402 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003403 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003404 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003405 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003406 }
Adam Cohen7777d962011-08-18 18:58:38 -07003407
Adam Cohenad4e15c2013-10-17 16:21:35 -07003408 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003409 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003410 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3411
Winson Chunge7a03942011-08-05 15:05:12 -07003412 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003413 @Override
3414 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003415 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003416 // Before we show workspace, hide all apps again because
3417 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3418 // clean up our state transition functions
3419 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003420 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003421 } else {
3422 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003423 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003424 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003425 }, delay);
3426
Winson Chung557d6ed2011-07-08 15:34:52 -07003427 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003428
Michael Jurkad3ef3062010-11-23 16:23:58 -08003429 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003430 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003431 final boolean animated = true;
3432 final boolean springLoaded = true;
3433 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003434 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003435 }
3436 // Otherwise, we are not in spring loaded mode, so don't do anything.
3437 }
3438
Michael Jurkab3e22d92011-10-31 15:58:33 -07003439 void lockAllApps() {
3440 // TODO
3441 }
3442
3443 void unlockAllApps() {
3444 // TODO
3445 }
3446
Winson Chungf0ea4d32011-06-06 14:27:16 -07003447 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003448 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003449 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003450 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003451 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003452 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003453 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003454 int duration = 0;
3455 if (mSearchDropTargetBar != null) {
3456 duration = mSearchDropTargetBar.getTransitionInDuration();
3457 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003458 mHotseat.animate().alpha(1f).setDuration(duration);
3459 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003460 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003461 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003462 }
3463 }
3464 }
3465
3466 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003467 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003468 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003469 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003470 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003471 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003472 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003473 int duration = 0;
3474 if (mSearchDropTargetBar != null) {
3475 duration = mSearchDropTargetBar.getTransitionOutDuration();
3476 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003477 mHotseat.animate().alpha(0f).setDuration(duration);
3478 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003479 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003480 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003481 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003482 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003483 }
3484
Patrick Dubroy5f445422011-02-18 14:35:21 -08003485 /**
3486 * Add an item from all apps or customize onto the given workspace screen.
3487 * If layout is null, add to the current screen.
3488 */
3489 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003490 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003491 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003492 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003493 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003494
Winson Chungdff8ebb2011-09-08 17:25:31 -07003495 /** Maps the current orientation to an index for referencing orientation correct global icons */
3496 private int getCurrentOrientationIndexForGlobalIcons() {
3497 // default - 0, landscape - 1
3498 switch (getResources().getConfiguration().orientation) {
3499 case Configuration.ORIENTATION_LANDSCAPE:
3500 return 1;
3501 default:
3502 return 0;
3503 }
3504 }
3505
Michael Jurkaae65ee32012-04-30 11:45:54 -07003506 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003507 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003508 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003509 // Look for the toolbar icon specified in the activity meta-data
3510 Bundle metaData = packageManager.getActivityInfo(
3511 activityName, PackageManager.GET_META_DATA).metaData;
3512 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003513 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003514 if (iconResId != 0) {
3515 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003516 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003517 }
3518 }
3519 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003520 // This can happen if the activity defines an invalid drawable
3521 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3522 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003523 } catch (Resources.NotFoundException nfe) {
3524 // This can happen if the activity defines an invalid drawable
3525 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3526 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003527 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003528 return null;
3529 }
3530
3531 // if successful in getting icon, return it; otherwise, set button to use default drawable
3532 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003533 int buttonId, ComponentName activityName, int fallbackDrawableId,
3534 String toolbarResourceName) {
3535 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003536 Resources r = getResources();
3537 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3538 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003539
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003540 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003541 // If we were unable to find the icon via the meta-data, use a generic one
3542 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003543 toolbarIcon = r.getDrawable(fallbackDrawableId);
3544 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003545 if (button != null) {
3546 button.setCompoundDrawables(toolbarIcon, null, null, null);
3547 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003548 return null;
3549 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003550 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003551 if (button != null) {
3552 button.setCompoundDrawables(toolbarIcon, null, null, null);
3553 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003554 return toolbarIcon.getConstantState();
3555 }
3556 }
3557
3558 // if successful in getting icon, return it; otherwise, set button to use default drawable
3559 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003560 int buttonId, ComponentName activityName, int fallbackDrawableId,
3561 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003562 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003563 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003564
Michael Jurka19e0fc52011-07-22 18:00:21 -07003565 if (button != null) {
3566 // If we were unable to find the icon via the meta-data, use a
3567 // generic one
3568 if (toolbarIcon == null) {
3569 button.setImageResource(fallbackDrawableId);
3570 } else {
3571 button.setImageDrawable(toolbarIcon);
3572 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003573 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003574
3575 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3576
Michael Jurka0423dcf2010-10-05 14:56:18 -07003577 }
3578
Winson Chung1b884092012-06-08 17:13:02 -07003579 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003580 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003581 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003582 }
3583
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003584 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003585 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003586 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003587 }
3588
Winson Chungbb185bd2011-11-21 12:31:42 -08003589 private void invalidatePressedFocusedStates(View container, View button) {
3590 if (container instanceof HolographicLinearLayout) {
3591 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3592 layout.invalidatePressedFocusedStates();
3593 } else if (button instanceof HolographicImageView) {
3594 HolographicImageView view = (HolographicImageView) button;
3595 view.invalidatePressedFocusedStates();
3596 }
3597 }
3598
Cristina Stancu476493b2013-08-07 17:20:14 +01003599 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003600 if (mQsb == null) {
3601 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3602 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003603 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003604 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003605 }
3606
3607 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003608 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003609 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003610 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003611 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003612
Winson Chung1cad91e2011-05-25 17:41:01 -07003613 final SearchManager searchManager =
3614 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3615 ComponentName activityName = searchManager.getGlobalSearchActivity();
3616 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003617 int coi = getCurrentOrientationIndexForGlobalIcons();
3618 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003619 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3620 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3621 if (sGlobalSearchIcon[coi] == null) {
3622 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3623 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3624 TOOLBAR_ICON_METADATA_NAME);
3625 }
3626
Winson Chungc51db6a2011-10-05 11:44:49 -07003627 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3628 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003629 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003630 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003631 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003632 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003633 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3634 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003635 if (searchButton != null) searchButton.setVisibility(View.GONE);
3636 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003637 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003638 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003639 }
3640 }
3641
Cristina Stancu476493b2013-08-07 17:20:14 +01003642 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003643 final View searchButtonContainer = findViewById(R.id.search_button_container);
3644 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003645 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003646 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003647 }
3648
Cristina Stancu476493b2013-08-07 17:20:14 +01003649 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003650 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003651 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003652
Winson Chungc51db6a2011-10-05 11:44:49 -07003653 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003654 final SearchManager searchManager =
3655 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3656 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3657
3658 ComponentName activityName = null;
3659 if (globalSearchActivity != null) {
3660 // Check if the global search activity handles voice search
3661 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3662 intent.setPackage(globalSearchActivity.getPackageName());
3663 activityName = intent.resolveActivity(getPackageManager());
3664 }
3665
3666 if (activityName == null) {
3667 // Fallback: check if an activity other than the global search activity
3668 // resolves this
3669 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3670 activityName = intent.resolveActivity(getPackageManager());
3671 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003672 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003673 int coi = getCurrentOrientationIndexForGlobalIcons();
3674 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003675 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3676 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3677 if (sVoiceSearchIcon[coi] == null) {
3678 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3679 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3680 TOOLBAR_ICON_METADATA_NAME);
3681 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003682 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003683 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003684 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003685 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003686 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003687 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003688 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003689 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003690 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003691 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003692 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003693 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003694
Cristina Stancu476493b2013-08-07 17:20:14 +01003695 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003696 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3697 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003698 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003699 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003700 }
3701
Winson Chung5841efa2013-09-30 18:06:44 -07003702 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003703 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3704 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003705 boolean visible = !forceDisableVoiceButtonProxy &&
3706 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003707 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003708 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003709 }
3710 }
Winson Chung5841efa2013-09-30 18:06:44 -07003711
3712 /**
3713 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3714 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3715 */
3716 public void disableVoiceButtonProxy(boolean disabled) {
3717 updateVoiceButtonProxyVisible(disabled);
3718 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003719 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003720 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003721 */
3722 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003723 if (!DISABLE_MARKET_BUTTON) {
3724 final View marketButton = findViewById(R.id.market_button);
3725 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3726 // Find the app market activity by resolving an intent.
3727 // (If multiple app markets are installed, it will return the ResolverActivity.)
3728 ComponentName activityName = intent.resolveActivity(getPackageManager());
3729 if (activityName != null) {
3730 int coi = getCurrentOrientationIndexForGlobalIcons();
3731 mAppMarketIntent = intent;
3732 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3733 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3734 TOOLBAR_ICON_METADATA_NAME);
3735 marketButton.setVisibility(View.VISIBLE);
3736 } else {
3737 // We should hide and disable the view so that we don't try and restore the visibility
3738 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3739 marketButton.setVisibility(View.GONE);
3740 marketButton.setEnabled(false);
3741 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003742 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003743 }
3744
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003745 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003746 if (!DISABLE_MARKET_BUTTON) {
3747 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3748 Resources r = getResources();
3749 Drawable marketIconDrawable = d.newDrawable(r);
3750 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3751 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3752 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003753
Winson Chungd64a6662013-09-30 11:06:59 -07003754 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3755 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003756 }
3757
Michael Jurkad7c28052012-04-27 15:43:36 -07003758 @Override
3759 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003760 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003761 final List<CharSequence> text = event.getText();
3762 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003763 // Populate event with a fake title based on the current state.
3764 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003765 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003766 } else {
3767 text.add(getString(R.string.all_apps_home_button_label));
3768 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003769 return result;
3770 }
3771
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003772 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003773 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003774 */
3775 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3776 @Override
3777 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003778 closeSystemDialogs();
3779 }
3780 }
3781
3782 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003783 * Receives notifications whenever the appwidgets are reset.
3784 */
3785 private class AppWidgetResetObserver extends ContentObserver {
3786 public AppWidgetResetObserver() {
3787 super(new Handler());
3788 }
3789
3790 @Override
3791 public void onChange(boolean selfChange) {
3792 onAppWidgetReset();
3793 }
3794 }
3795
3796 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003797 * If the activity is currently paused, signal that we need to run the passed Runnable
3798 * in onResume.
3799 *
3800 * This needs to be called from incoming places where resources might have been loaded
3801 * while we are paused. That is becaues the Configuration might be wrong
3802 * when we're not running, and if it comes back to what it was when we
3803 * were paused, we are not restarted.
3804 *
3805 * Implementation of the method from LauncherModel.Callbacks.
3806 *
3807 * @return true if we are currently paused. The caller might be able to
3808 * skip some work in that case since we will come back again.
3809 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003810 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003811 if (mPaused) {
3812 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003813 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003814 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003815 }
3816 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003817 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003818 return true;
3819 } else {
3820 return false;
3821 }
3822 }
3823
Michael Jurkac402cd92013-05-20 15:49:32 +02003824 private boolean waitUntilResume(Runnable run) {
3825 return waitUntilResume(run, false);
3826 }
3827
Michael Jurka1e2f4652013-07-08 18:03:46 -07003828 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003829 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003830 }
3831
Michael Jurka7607c2f2013-04-03 14:33:19 -07003832 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003833 * If the activity is currently paused, signal that we need to re-run the loader
3834 * in onResume.
3835 *
3836 * This needs to be called from incoming places where resources might have been loaded
3837 * while we are paused. That is becaues the Configuration might be wrong
3838 * when we're not running, and if it comes back to what it was when we
3839 * were paused, we are not restarted.
3840 *
3841 * Implementation of the method from LauncherModel.Callbacks.
3842 *
3843 * @return true if we are currently paused. The caller might be able to
3844 * skip some work in that case since we will come back again.
3845 */
3846 public boolean setLoadOnResume() {
3847 if (mPaused) {
3848 Log.i(TAG, "setLoadOnResume");
3849 mOnResumeNeedsLoad = true;
3850 return true;
3851 } else {
3852 return false;
3853 }
3854 }
3855
3856 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003857 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003858 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003859 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003860 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003861 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003862 } else {
3863 return SCREEN_COUNT / 2;
3864 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003865 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003866
Joe Onorato9c1289c2009-08-17 11:03:03 -04003867 /**
3868 * Refreshes the shortcuts shown on the workspace.
3869 *
3870 * Implementation of the method from LauncherModel.Callbacks.
3871 */
3872 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003873 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003874
Michael Jurka7607c2f2013-04-03 14:33:19 -07003875 // If we're starting binding all over again, clear any bind calls we'd postponed in
3876 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3877 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003878 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003879
Winson Chungd64d1762013-08-20 14:37:16 -07003880 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003881 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003882 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003883
Michael Jurka05bf644e2011-11-30 20:28:53 -08003884 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003885 if (mHotseat != null) {
3886 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003887 }
3888 }
3889
Adam Cohendcd297f2013-06-18 13:13:40 -07003890 @Override
3891 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003892 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003893
Adam Cohen5084cba2013-09-03 12:01:16 -07003894 // If there are no screens, we need to have an empty screen
3895 if (orderedScreenIds.size() == 0) {
3896 mWorkspace.addExtraEmptyScreen();
3897 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003898
3899 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003900 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003901 if (hasCustomContentToLeft()) {
3902 mWorkspace.createCustomContentContainer();
3903 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003904 }
Winson Chung64359a52013-07-08 17:17:08 -07003905 }
3906
3907 @Override
3908 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003909 // Log to disk
3910 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3911 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3912 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003913 int count = orderedScreenIds.size();
3914 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003915 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003916 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003917 }
3918
Adam Cohen39a06042013-07-19 14:30:12 -07003919 private boolean shouldShowWeightWatcher() {
3920 String spKey = LauncherAppState.getSharedPreferencesKey();
3921 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003922 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003923
3924 return show;
3925 }
3926
3927 private void toggleShowWeightWatcher() {
3928 String spKey = LauncherAppState.getSharedPreferencesKey();
3929 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3930 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3931
3932 show = !show;
3933
3934 SharedPreferences.Editor editor = sp.edit();
3935 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3936 editor.commit();
3937
3938 if (mWeightWatcher != null) {
3939 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3940 }
3941 }
3942
Winson Chungd64d1762013-08-20 14:37:16 -07003943 public void bindAppsAdded(final ArrayList<Long> newScreens,
3944 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003945 final ArrayList<ItemInfo> addAnimated,
3946 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003947 Runnable r = new Runnable() {
3948 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003949 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003950 }
3951 };
3952 if (waitUntilResume(r)) {
3953 return;
3954 }
3955
Winson Chungd64d1762013-08-20 14:37:16 -07003956 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003957 if (newScreens != null) {
3958 bindAddScreens(newScreens);
3959 }
Winson Chungd64d1762013-08-20 14:37:16 -07003960
3961 // We add the items without animation on non-visible pages, and with
3962 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003963 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003964 bindItems(addNotAnimated, 0,
3965 addNotAnimated.size(), false);
3966 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003967 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003968 bindItems(addAnimated, 0,
3969 addAnimated.size(), true);
3970 }
Winson Chungc58497e2013-09-03 17:48:37 -07003971
Winson Chung87412982013-10-03 18:34:14 -07003972 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003973 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003974
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003975 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003976 addedApps != null && mAppsCustomizeContent != null) {
3977 mAppsCustomizeContent.addApps(addedApps);
3978 }
Winson Chungd64d1762013-08-20 14:37:16 -07003979 }
3980
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003981 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003982 * Bind the items start-end from the list.
3983 *
3984 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003985 */
Winson Chung64359a52013-07-08 17:17:08 -07003986 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3987 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003988 Runnable r = new Runnable() {
3989 public void run() {
3990 bindItems(shortcuts, start, end, forceAnimateIcons);
3991 }
3992 };
3993 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003994 return;
3995 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003996
Winson Chungf0c6ae02012-03-21 16:10:31 -07003997 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003998 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3999 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004000 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004001 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004002 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004003 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004004 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004005
4006 // Short circuit if we are loading dock items for a configuration which has no dock
4007 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4008 mHotseat == null) {
4009 continue;
4010 }
4011
Joe Onorato9c1289c2009-08-17 11:03:03 -04004012 switch (item.itemType) {
4013 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4014 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004015 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004016 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004017
Winson Chung64359a52013-07-08 17:17:08 -07004018 /*
4019 * TODO: FIX collision case
4020 */
Winson Chungce376632013-07-11 16:12:41 -07004021 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4022 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4023 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004024 View v = cl.getChildAt(item.cellX, item.cellY);
4025 Object tag = v.getTag();
4026 String desc = "Collision while binding workspace item: " + item
4027 + ". Collides with " + tag;
4028 if (LauncherAppState.isDogfoodBuild()) {
4029 throw (new RuntimeException(desc));
4030 } else {
4031 Log.d(TAG, desc);
4032 }
Winson Chungce376632013-07-11 16:12:41 -07004033 }
Winson Chung64359a52013-07-08 17:17:08 -07004034 }
4035
Adam Cohendcd297f2013-06-18 13:13:40 -07004036 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4037 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004038 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004039 // Animate all the applications up now
4040 shortcut.setAlpha(0f);
4041 shortcut.setScaleX(0f);
4042 shortcut.setScaleY(0f);
4043 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004044 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004045 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004046 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004047 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004048 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004049 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004050 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004051 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4052 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004053 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004054 default:
4055 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004056 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004057 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004058
Winson Chung997a9232013-07-24 15:33:46 -07004059 if (animateIcons) {
4060 // Animate to the correct page
4061 if (newShortcutsScreenId > -1) {
4062 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004063 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004064 final Runnable startBounceAnimRunnable = new Runnable() {
4065 public void run() {
4066 anim.playTogether(bounceAnims);
4067 anim.start();
4068 }
4069 };
Winson Chung997a9232013-07-24 15:33:46 -07004070 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004071 // We post the animation slightly delayed to prevent slowdowns
4072 // when we are loading right after we return to launcher.
4073 mWorkspace.postDelayed(new Runnable() {
4074 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004075 if (mWorkspace != null) {
4076 mWorkspace.snapToPage(newScreenIndex);
4077 mWorkspace.postDelayed(startBounceAnimRunnable,
4078 NEW_APPS_ANIMATION_DELAY);
4079 }
Winson Chung94d67682013-09-25 16:29:40 -07004080 }
4081 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004082 } else {
4083 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004084 }
4085 }
Winson Chung64359a52013-07-08 17:17:08 -07004086 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004087 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004088 }
4089
Joe Onorato9c1289c2009-08-17 11:03:03 -04004090 /**
4091 * Implementation of the method from LauncherModel.Callbacks.
4092 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004093 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004094 Runnable r = new Runnable() {
4095 public void run() {
4096 bindFolders(folders);
4097 }
4098 };
4099 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004100 return;
4101 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004102 sFolders.clear();
4103 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004104 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004105
4106 /**
4107 * Add the views for a widget to the workspace.
4108 *
4109 * Implementation of the method from LauncherModel.Callbacks.
4110 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004111 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004112 Runnable r = new Runnable() {
4113 public void run() {
4114 bindAppWidget(item);
4115 }
4116 };
4117 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004118 return;
4119 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004120
Daniel Sandler843e8602010-06-07 14:59:01 -04004121 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4122 if (DEBUG_WIDGETS) {
4123 Log.d(TAG, "bindAppWidget: " + item);
4124 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004125 final Workspace workspace = mWorkspace;
4126
4127 final int appWidgetId = item.appWidgetId;
4128 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004129 if (DEBUG_WIDGETS) {
4130 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4131 }
4132
Joe Onorato9c1289c2009-08-17 11:03:03 -04004133 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4134
Joe Onorato9c1289c2009-08-17 11:03:03 -04004135 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004136 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004137
Adam Cohendcd297f2013-06-18 13:13:40 -07004138 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004140 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4141
Joe Onorato9c1289c2009-08-17 11:03:03 -04004142 workspace.requestLayout();
4143
Daniel Sandler843e8602010-06-07 14:59:01 -04004144 if (DEBUG_WIDGETS) {
4145 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4146 + (SystemClock.uptimeMillis()-start) + "ms");
4147 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004148 }
4149
Adam Cohen1462de32012-07-24 22:34:36 -07004150 public void onPageBoundSynchronously(int page) {
4151 mSynchronouslyBoundPages.add(page);
4152 }
4153
Joe Onorato9c1289c2009-08-17 11:03:03 -04004154 /**
4155 * Callback saying that there aren't any more items to bind.
4156 *
4157 * Implementation of the method from LauncherModel.Callbacks.
4158 */
Adam Cohene25af792013-06-06 23:08:25 -07004159 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004160 Runnable r = new Runnable() {
4161 public void run() {
4162 finishBindingItems(upgradePath);
4163 }
4164 };
4165 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004166 return;
4167 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004168 if (mSavedState != null) {
4169 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004170 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004171 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004172 mSavedState = null;
4173 }
4174
Adam Cohen1462de32012-07-24 22:34:36 -07004175 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004176
Patrick Dubroy002cbf42011-03-03 16:36:21 -08004177 // If we received the result of any pending adds while the loader was running (e.g. the
4178 // widget configuration forced an orientation change), process them now.
4179 for (int i = 0; i < sPendingAddList.size(); i++) {
4180 completeAdd(sPendingAddList.get(i));
4181 }
4182 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004183
Winson Chungc51db6a2011-10-05 11:44:49 -07004184 // Update the market app icon as necessary (the other icons will be managed in response to
4185 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004186 if (!DISABLE_MARKET_BUTTON) {
4187 updateAppMarketIcon();
4188 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004189
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004190 setWorkspaceLoading(false);
Adam Cohene25af792013-06-06 23:08:25 -07004191 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004192 mWorkspace.getUniqueComponents(true, null);
4193 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004194 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004195 }
4196
Winson Chunga0b7e862013-09-05 16:03:15 -07004197 public boolean isAllAppsButtonRank(int rank) {
4198 if (mHotseat != null) {
4199 return mHotseat.isAllAppsButtonRank(rank);
4200 }
4201 return false;
4202 }
4203
Winson Chunga2413752012-04-03 14:22:34 -07004204 private boolean canRunNewAppsAnimation() {
4205 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4206 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4207 }
4208
Winson Chungc9168342013-06-26 14:54:55 -07004209 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4210 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4211 PropertyValuesHolder.ofFloat("alpha", 1f),
4212 PropertyValuesHolder.ofFloat("scaleX", 1f),
4213 PropertyValuesHolder.ofFloat("scaleY", 1f));
4214 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4215 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4216 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4217 return bounceAnim;
4218 }
4219
Adam Cohen27772732013-11-11 14:00:56 +00004220 public boolean useVerticalBarLayout() {
4221 return LauncherAppState.getInstance().getDynamicGrid().
4222 getDeviceProfile().isVerticalBarLayout();
4223 }
4224
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004225 protected Rect getSearchBarBounds() {
4226 return LauncherAppState.getInstance().getDynamicGrid().
4227 getDeviceProfile().getSearchBarBounds();
4228 }
4229
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004230 @Override
4231 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004232 boolean searchVisible = updateGlobalSearchIcon();
4233 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004234 if (mSearchDropTargetBar != null) {
4235 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4236 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004237 }
4238
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004239 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004240 * Add the icons for all apps.
4241 *
4242 * Implementation of the method from LauncherModel.Callbacks.
4243 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004244 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004245 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004246 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4247 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4248 getHotseat().addAllAppsFolder(mIconCache, apps,
4249 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4250 }
4251 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004252 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004253 if (mAppsCustomizeContent != null) {
4254 mAppsCustomizeContent.onPackagesUpdated(
4255 LauncherModel.getSortedWidgetsAndShortcuts(this));
4256 }
Winson Chungc58497e2013-09-03 17:48:37 -07004257 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004258 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004259 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004260 mAppsCustomizeContent.onPackagesUpdated(
4261 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004262 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004263 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004264 }
4265
4266 /**
4267 * A package was updated.
4268 *
4269 * Implementation of the method from LauncherModel.Callbacks.
4270 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004271 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004272 Runnable r = new Runnable() {
4273 public void run() {
4274 bindAppsUpdated(apps);
4275 }
4276 };
4277 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004278 return;
4279 }
4280
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004281 if (mWorkspace != null) {
4282 mWorkspace.updateShortcuts(apps);
4283 }
Winson Chungc58497e2013-09-03 17:48:37 -07004284
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004285 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004286 mAppsCustomizeContent != null) {
4287 mAppsCustomizeContent.updateApps(apps);
4288 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004289 }
4290
4291 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004292 * Update the state of a package, typically related to install state.
4293 *
4294 * Implementation of the method from LauncherModel.Callbacks.
4295 */
4296 public void updatePackageState(String pkgName, int state) {
4297 if (mWorkspace != null) {
4298 mWorkspace.updatePackageState(pkgName, state);
4299 }
4300 }
4301
4302 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004303 * A package was uninstalled. We take both the super set of packageNames
4304 * in addition to specific applications to remove, the reason being that
4305 * this can be called when a package is updated as well. In that scenario,
4306 * we only remove specific components from the workspace, where as
4307 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004308 *
4309 * Implementation of the method from LauncherModel.Callbacks.
4310 */
Winson Chung83892cc2013-05-01 16:53:33 -07004311 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004312 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004313 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004314 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004315 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004316 }
Winson Chungd64d1762013-08-20 14:37:16 -07004317 };
4318 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004319 return;
4320 }
4321
Winson Chungdf95eb12013-10-16 14:57:07 -07004322 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004323 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004324 }
4325 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004326 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004327 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004328
Winson Chunga1820962011-10-03 16:31:06 -07004329 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004330 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004331
Winson Chungdf95eb12013-10-16 14:57:07 -07004332 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004333 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004334 mAppsCustomizeContent != null) {
4335 mAppsCustomizeContent.removeApps(appInfos);
4336 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004337 }
Joe Onoratobe386092009-11-17 17:32:16 -08004338
4339 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004340 * A number of packages were updated.
4341 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004342 private ArrayList<Object> mWidgetsAndShortcuts;
4343 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004344 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004345 bindPackagesUpdated(mWidgetsAndShortcuts);
4346 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004347 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004348 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004349 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4350 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4351 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004352 return;
4353 }
4354
Winson Chung64359a52013-07-08 17:17:08 -07004355 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004356 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004357 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004358 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004359 }
4360
Winson Chung400438b2011-01-16 17:53:48 -08004361 private int mapConfigurationOriActivityInfoOri(int configOri) {
4362 final Display d = getWindowManager().getDefaultDisplay();
4363 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4364 switch (d.getRotation()) {
4365 case Surface.ROTATION_0:
4366 case Surface.ROTATION_180:
4367 // We are currently in the same basic orientation as the natural orientation
4368 naturalOri = configOri;
4369 break;
4370 case Surface.ROTATION_90:
4371 case Surface.ROTATION_270:
4372 // We are currently in the other basic orientation to the natural orientation
4373 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4374 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4375 break;
4376 }
4377
4378 int[] oriMap = {
4379 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4380 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4381 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4382 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4383 };
4384 // Since the map starts at portrait, we need to offset if this device's natural orientation
4385 // is landscape.
4386 int indexOffset = 0;
4387 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4388 indexOffset = 1;
4389 }
4390 return oriMap[(d.getRotation() + indexOffset) % 4];
4391 }
Adam Cohen446e9402011-09-15 18:21:21 -07004392
Winson Chung4b919f82012-05-01 10:44:08 -07004393 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004394 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004395 getResources().getBoolean(R.bool.allow_rotation);
4396 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004397 }
Winson Chung4b919f82012-05-01 10:44:08 -07004398 public void lockScreenOrientation() {
4399 if (isRotationEnabled()) {
4400 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4401 .getConfiguration().orientation));
4402 }
4403 }
4404 public void unlockScreenOrientation(boolean immediate) {
4405 if (isRotationEnabled()) {
4406 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004407 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004408 } else {
4409 mHandler.postDelayed(new Runnable() {
4410 public void run() {
4411 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4412 }
4413 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004414 }
Winson Chung4b919f82012-05-01 10:44:08 -07004415 }
Winson Chung400438b2011-01-16 17:53:48 -08004416 }
4417
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004418 /**
4419 * Called when the SearchBar hint should be changed.
4420 *
4421 * @param hint the hint to be displayed in the search bar.
4422 */
4423 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004424 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004425 }
4426
Winson Chunge43a1e72014-01-15 10:33:02 -08004427 protected boolean isLauncherPreinstalled() {
4428 PackageManager pm = getPackageManager();
4429 try {
4430 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4431 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4432 return true;
4433 } else {
4434 return false;
4435 }
4436 } catch (NameNotFoundException e) {
4437 e.printStackTrace();
4438 return false;
4439 }
4440 }
4441
Winson Chunge6eabff2013-09-24 11:01:23 -07004442 protected String getFirstRunClingSearchBarHint() {
4443 return "";
4444 }
4445 protected String getFirstRunCustomContentHint() {
4446 return "";
4447 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004448 protected int getFirstRunFocusedHotseatAppDrawableId() {
4449 return -1;
4450 }
4451 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4452 return null;
4453 }
4454 protected int getFirstRunFocusedHotseatAppRank() {
4455 return -1;
4456 }
4457 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4458 return "";
4459 }
4460 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4461 return "";
4462 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004463
Winson Chungaf40f202013-09-18 18:26:31 -07004464 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004465 mLauncherClings.dismissFirstRunCling(v);
4466 }
4467 public void dismissMigrationClingCopyApps(View v) {
4468 mLauncherClings.dismissMigrationClingCopyApps(v);
4469 }
4470 public void dismissMigrationClingUseDefault(View v) {
4471 mLauncherClings.dismissMigrationClingUseDefault(v);
4472 }
4473 public void dismissMigrationWorkspaceCling(View v) {
4474 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004475 }
Winson Chung82f55532011-08-09 14:14:23 -07004476 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004477 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004478 }
4479 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004480 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004481 }
4482
Adam Cohen432609a2014-03-13 17:03:22 -07004483
4484 /**
4485 * To be overridden by subclasses to indicate that there is an activity to launch
4486 * before showing the standard launcher experience.
4487 */
4488 protected boolean hasFirstRunActivity() {
4489 return false;
4490 }
4491
4492 /**
4493 * To be overridden by subclasses to launch any first run activity
4494 */
4495 protected Intent getFirstRunActivity() {
4496 return null;
4497 }
4498
Winson Chunga6945242014-01-08 14:04:34 -08004499 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004500 return !ActivityManager.isRunningInTestHarness() &&
4501 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004502 }
4503
Adam Cohen4a9423d2014-03-28 14:22:31 -07004504 protected boolean hasRunFirstRunActivity() {
4505 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4506 }
4507
Adam Cohen432609a2014-03-13 17:03:22 -07004508 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004509 if (shouldRunFirstRunActivity() &&
4510 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004511 Intent firstRunIntent = getFirstRunActivity();
4512 if (firstRunIntent != null) {
4513 startActivity(firstRunIntent);
4514 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004515 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004516 }
4517 }
Adam Cohen432609a2014-03-13 17:03:22 -07004518 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004519 }
4520
4521 private void markFirstRunActivityShown() {
4522 SharedPreferences.Editor editor = mSharedPrefs.edit();
4523 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4524 editor.apply();
4525 }
4526
Adam Cohen432609a2014-03-13 17:03:22 -07004527 /**
4528 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4529 * screen that must be displayed and dismissed.
4530 */
4531 protected boolean hasDismissableIntroScreen() {
4532 return false;
4533 }
4534
4535 /**
4536 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4537 */
4538 protected View getIntroScreen() {
4539 return null;
4540 }
4541
4542 /**
4543 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4544 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4545 */
4546 private boolean shouldShowIntroScreen() {
4547 return hasDismissableIntroScreen() &&
4548 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4549 }
4550
4551 protected void showIntroScreen() {
4552 View introScreen = getIntroScreen();
4553 changeWallpaperVisiblity(false);
4554 if (introScreen != null) {
4555 mDragLayer.showOverlayView(introScreen);
4556 }
4557 }
4558
4559 public void dismissIntroScreen() {
4560 markIntroScreenDismissed();
4561 if (showFirstRunActivity()) {
4562 // We delay hiding the intro view until the first run activity is showing. This
4563 // avoids a blip.
4564 mWorkspace.postDelayed(new Runnable() {
4565 @Override
4566 public void run() {
4567 mDragLayer.dismissOverlayView();
4568 }
4569 }, ACTIVITY_START_DELAY);
4570 } else {
4571 mDragLayer.dismissOverlayView();
4572 }
4573 changeWallpaperVisiblity(true);
4574 }
4575
4576 private void markIntroScreenDismissed() {
4577 SharedPreferences.Editor editor = mSharedPrefs.edit();
4578 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4579 editor.apply();
4580 }
4581
Winson Chunga6945242014-01-08 14:04:34 -08004582 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004583 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4584 if (mHotseat != null) mHotseat.setAlpha(1f);
4585 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4586 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004587 }
4588
4589 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004590 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4591 if (mHotseat != null) mHotseat.setAlpha(0f);
4592 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4593 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004594 }
4595
Mathew Inwood72fbec12013-11-19 15:45:07 +00004596 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004597 // Called from search suggestion, not supported in other profiles.
4598 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4599 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4600 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4601 myUser);
4602 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004603 return null;
4604 }
Kenny Guyed131872014-04-30 03:02:21 +01004605 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004606 }
4607
4608 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4609 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004610 // Called from search suggestion, not supported in other profiles.
4611 return createShortcutDragInfo(shortcutIntent, caption, icon,
4612 UserHandleCompat.myUserHandle());
4613 }
4614
4615 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4616 Bitmap icon, UserHandleCompat user) {
4617 return new ShortcutInfo(shortcutIntent, caption, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004618 }
4619
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004620 protected void moveWorkspaceToDefaultScreen() {
4621 mWorkspace.moveToDefaultScreen(false);
4622 }
4623
Mathew Inwood72fbec12013-11-19 15:45:07 +00004624 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4625 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004626 mWorkspace.onExternalDragStartedWithItem(dragView);
4627 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004628 }
4629
Anjali Koppalf5d29132014-02-28 13:33:27 -08004630 @Override
4631 public void onPageSwitch(View newPage, int newPageIndex) {
4632 }
4633
Winson Chung80baf5a2010-08-09 16:03:15 -07004634 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004635 * Prints out out state for debugging.
4636 */
4637 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004638 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004639 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004640 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4641 Log.d(TAG, "mRestoring=" + mRestoring);
4642 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4643 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004644 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004645 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004646
Winson Chung785d2eb2011-04-14 16:08:02 -07004647 if (mAppsCustomizeContent != null) {
4648 mAppsCustomizeContent.dumpState();
4649 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004650 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004651 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004652
4653 @Override
4654 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4655 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004656 synchronized (sDumpLogs) {
4657 writer.println(" ");
4658 writer.println("Debug logs: ");
4659 for (int i = 0; i < sDumpLogs.size(); i++) {
4660 writer.println(" " + sDumpLogs.get(i));
4661 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004662 }
4663 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004664
4665 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004666 if (DEBUG_DUMP_LOG) {
4667 synchronized (sDumpLogs) {
4668 Log.d(TAG, "");
4669 Log.d(TAG, "*********************");
4670 Log.d(TAG, "Launcher debug logs: ");
4671 for (int i = 0; i < sDumpLogs.size(); i++) {
4672 Log.d(TAG, " " + sDumpLogs.get(i));
4673 }
4674 Log.d(TAG, "*********************");
4675 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004676 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004677 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004678 }
4679
4680 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004681 addDumpLog(tag, log, null, debugLog);
4682 }
4683
4684 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004685 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004686 if (e != null) {
4687 Log.d(tag, log, e);
4688 } else {
4689 Log.d(tag, log);
4690 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004691 }
Winson Chungede41292013-09-19 16:27:36 -07004692 if (DEBUG_DUMP_LOG) {
4693 sDateStamp.setTime(System.currentTimeMillis());
4694 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004695 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4696 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004697 }
Winson Chungede41292013-09-19 16:27:36 -07004698 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004699 }
4700
Winson Chungede41292013-09-19 16:27:36 -07004701 public void dumpLogsToLocalData() {
4702 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004703 new AsyncTask<Void, Void, Void>() {
4704 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004705 boolean success = false;
4706 sDateStamp.setTime(sRunStart);
4707 String FILENAME = sDateStamp.getMonth() + "-"
4708 + sDateStamp.getDay() + "_"
4709 + sDateStamp.getHours() + "-"
4710 + sDateStamp.getMinutes() + "_"
4711 + sDateStamp.getSeconds() + ".txt";
4712
4713 FileOutputStream fos = null;
4714 File outFile = null;
4715 try {
4716 outFile = new File(getFilesDir(), FILENAME);
4717 outFile.createNewFile();
4718 fos = new FileOutputStream(outFile);
4719 } catch (Exception e) {
4720 e.printStackTrace();
4721 }
4722 if (fos != null) {
4723 PrintWriter writer = new PrintWriter(fos);
4724
4725 writer.println(" ");
4726 writer.println("Debug logs: ");
4727 synchronized (sDumpLogs) {
4728 for (int i = 0; i < sDumpLogs.size(); i++) {
4729 writer.println(" " + sDumpLogs.get(i));
4730 }
4731 }
4732 writer.close();
4733 }
4734 try {
4735 if (fos != null) {
4736 fos.close();
4737 success = true;
4738 }
4739 } catch (IOException e) {
4740 e.printStackTrace();
4741 }
Michael Jurka43467462013-11-14 12:03:58 +01004742 return null;
Winson Chungede41292013-09-19 16:27:36 -07004743 }
Michael Jurka43467462013-11-14 12:03:58 +01004744 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004745 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004747}
Michael Jurka2763be32011-02-24 11:19:57 -08004748
Michael Jurkaabded662011-03-04 12:06:57 -08004749interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004750 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004751 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004752 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004753 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004754 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004755}
Dan Sandlerd5024042014-01-09 15:01:33 -05004756
4757interface DebugIntents {
4758 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4759 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004760}