blob: 9da1fbb426517333397e5c1d868b0ff7a87e24e4 [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;
Sandeep Siddhartha876b0032014-05-19 11:45:01 -070027import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070028import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070029import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070030import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070042import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070043import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070044import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080045import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
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;
Kenny Guyed131872014-04-30 03:02:21 +010099import com.android.launcher3.compat.LauncherActivityInfoCompat;
100import com.android.launcher3.compat.LauncherAppsCompat;
101import com.android.launcher3.compat.UserHandleCompat;
102import com.android.launcher3.compat.UserManagerCompat;
Daniel Sandler325dc232013-06-05 22:57:57 -0400103import com.android.launcher3.DropTarget.DragObject;
Anjali Koppalf5d29132014-02-28 13:33:27 -0800104import com.android.launcher3.PagedView.PageSwitchListener;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.io.DataInputStream;
106import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700107import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700108import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -0700113import java.lang.reflect.Field;
114import java.lang.reflect.InvocationTargetException;
115import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700118import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700119import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700120import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700121import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000122import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700123
Winson Chunga6945242014-01-08 14:04:34 -0800124
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125/**
126 * Default launcher application.
127 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100128public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700129 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700130 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800131 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700132 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133
Daniel Sandlerf061f822013-06-27 13:59:36 -0400134 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400135 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700136 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400137 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700138 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700139
Dan Sandlerd5024042014-01-09 15:01:33 -0500140 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
141
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700143 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700145 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700146 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Michael Jurka8b805b12012-04-18 14:23:14 -0700148 private static final int REQUEST_BIND_APPWIDGET = 11;
149
Mathew Inwood876a8462013-06-14 14:12:41 +0100150 /**
151 * IntentStarter uses request codes starting with this. This must be greater than all activity
152 * request codes used internally.
153 */
154 protected static final int REQUEST_LAST = 100;
155
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
157
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800158 static final int SCREEN_COUNT = 5;
159 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Romain Guy98d01652009-06-30 16:21:04 -0700161 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800162 // To turn on these properties, type
163 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
164 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
165 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800166 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167
Winson Chung2672ff92012-05-04 16:22:30 -0700168 // The Intent extra that defines whether to ignore the launch animation
169 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400170 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700171
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 // Type: int
173 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700174 // Type: int
175 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700177 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
178 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
180 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700181 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700183 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 // Type: boolean
185 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
186 // Type: long
187 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700188 // Type: int
189 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
190 // Type: int
191 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
192 // Type: parcelable
193 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000194 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800195 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000196 // Type: int[]
197 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800198
Adam Cohenb54a5982014-01-08 15:21:04 -0800199
Adam Cohen432609a2014-03-13 17:03:22 -0700200 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800201 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
202
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100203 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700204 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100205 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700206 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100207 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700208
Adam Cohen39a06042013-07-19 14:30:12 -0700209 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700210 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700211
Winson Chunga6945242014-01-08 14:04:34 -0800212 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
213
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700214 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700215 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700216 private State mState = State.WORKSPACE;
217 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700218
Joe Onorato9c1289c2009-08-17 11:03:03 -0400219 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700220 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
221 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700222 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800225 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000227 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
228 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
229
Winson Chunga2413752012-04-03 14:22:34 -0700230 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700231 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
232 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700233 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700234
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800235 private final BroadcastReceiver mCloseSystemDialogsReceiver
236 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800237 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
238
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800239 private LayoutInflater mInflater;
240
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700242 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800243 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800244 private DragLayer mDragLayer;
245 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700246 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800247 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700248
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700249 private AppWidgetManager mAppWidgetManager;
250 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700251
Michael Jurkac9d95c52011-08-29 14:03:34 -0700252 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700253 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800254 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700255
Michael Jurka0280c3b2010-09-17 15:00:07 -0700256 private int[] mTmpAddItemCellCoordinates = new int[2];
257
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 private FolderInfo mFolderInfo;
259
Winson Chung3d503fb2011-07-13 17:25:49 -0700260 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800261 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700262
Michael Jurka838a4ca2011-02-07 13:33:06 -0800263 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700264
Winson Chungc51db6a2011-10-05 11:44:49 -0700265 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700266 private AppsCustomizeTabHost mAppsCustomizeTabHost;
267 private AppsCustomizePagedView mAppsCustomizeContent;
268 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800269 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700272 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
273 // scroll issues (because the workspace may not have been measured yet) and extra work.
274 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
275 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276
277 private SpannableStringBuilder mDefaultKeySsb = null;
278
Joe Onorato9c1289c2009-08-17 11:03:03 -0400279 private boolean mWorkspaceLoading = true;
280
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800281 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 private boolean mRestoring;
283 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700284 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285
Michael Jurka1e2f4652013-07-08 18:03:46 -0700286 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700287 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
288
Winson Chung4a2afa32012-07-19 14:53:05 -0700289 // Keep track of whether the user has left launcher
290 private static boolean sPausedFromUserAction = false;
291
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 private Bundle mSavedInstanceState;
293
Joe Onorato9c1289c2009-08-17 11:03:03 -0400294 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800295 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800296 private boolean mUserPresent = true;
297 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700298 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800299 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400300
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700301 private static LocaleConfiguration sLocaleConfiguration = null;
302
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700303 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700304
Adam Cohen61f560d2013-09-30 15:58:20 -0700305 private View.OnTouchListener mHapticFeedbackTouchListener;
306
Adam Cohended9f8d2010-11-03 13:25:16 -0700307 // Related to the auto-advancing of widgets
308 private final int ADVANCE_MSG = 1;
309 private final int mAdvanceInterval = 20000;
310 private final int mAdvanceStagger = 250;
311 private long mAutoAdvanceSentTime;
312 private long mAutoAdvanceTimeLeft = -1;
313 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
314 new HashMap<View, AppWidgetProviderInfo>();
315
Winson Chung400438b2011-01-16 17:53:48 -0800316 // Determines how long to wait after a rotation before restoring the screen orientation to
317 // match the sensor state.
318 private final int mRestoreScreenOrientationDelay = 500;
319
Michael Jurka4ef207b2010-11-29 17:05:45 -0800320 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700321 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
322 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
323 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800324
Winson Chungd64a6662013-09-30 11:06:59 -0700325 private Intent mAppMarketIntent = null;
326 private static final boolean DISABLE_MARKET_BUTTON = true;
327
Craig Mautner360310b2012-10-26 15:13:08 -0700328 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700329
Adam Cohen1462de32012-07-24 22:34:36 -0700330 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700331 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700332
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700333 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700334 static Date sDateStamp = new Date();
335 static DateFormat sDateFormat =
336 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
337 static long sRunStart = System.currentTimeMillis();
338 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700339
Winson Chung46353de2012-02-16 14:05:10 -0800340 // We only want to get the SharedPreferences once since it does an FS stat each time we get
341 // it from the context.
342 private SharedPreferences mSharedPrefs;
343
Adam Cohene25af792013-06-06 23:08:25 -0700344 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
345
Winson Chungf0c6ae02012-03-21 16:10:31 -0700346 // Holds the page that we need to animate to, and the icon views that we need to animate up
347 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700348 private ImageView mFolderIconImageView;
349 private Bitmap mFolderIconBitmap;
350 private Canvas mFolderIconCanvas;
351 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700352
Michael Jurkaddd62e92011-02-16 17:49:14 -0800353 private BubbleTextView mWaitingForResume;
354
Michael Jurkac1f5d262011-09-30 19:32:27 -0700355 private Runnable mBuildLayersRunnable = new Runnable() {
356 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700357 if (mWorkspace != null) {
358 mWorkspace.buildPageHardwareLayers();
359 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700360 }
361 };
362
Adam Cohendb364c32014-05-20 14:23:40 -0700363 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800364
Michael Jurka7267fa52013-09-26 15:29:57 -0700365 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800366
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800367 private static class PendingAddArguments {
368 int requestCode;
369 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700370 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700371 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800372 int cellX;
373 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700374 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800375 }
376
Daniel Sandlerff02d492013-08-05 02:12:05 -0400377 private Stats mStats;
378
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800379 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800380 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700381 }
382
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 @Override
384 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700385 if (DEBUG_STRICT_MODE) {
386 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
387 .detectDiskReads()
388 .detectDiskWrites()
389 .detectNetwork() // or .detectAll() for all detectable problems
390 .penaltyLog()
391 .build());
392 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
393 .detectLeakedSqlLiteObjects()
394 .detectLeakedClosableObjects()
395 .penaltyLog()
396 .penaltyDeath()
397 .build());
398 }
399
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400401
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400402 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400403 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700404 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700405 // Determine the dynamic grid properties
406 Point smallestSize = new Point();
407 Point largestSize = new Point();
408 Point realSize = new Point();
409 Display display = getWindowManager().getDefaultDisplay();
410 display.getCurrentSizeRange(smallestSize, largestSize);
411 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700412 DisplayMetrics dm = new DisplayMetrics();
413 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700414
Winson Chung5f8afe62013-08-12 16:19:28 -0700415 // Lazy-initialize the dynamic grid
416 DeviceProfile grid = app.initDynamicGrid(this,
417 Math.min(smallestSize.x, smallestSize.y),
418 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700419 realSize.x, realSize.y,
420 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700421
422 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400423 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700424 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800425 mModel = app.setLauncher(this);
426 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700427 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400428 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800429 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700431
Daniel Sandlerff02d492013-08-05 02:12:05 -0400432 mStats = new Stats(this);
433
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700434 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700435
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700436 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
437 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700438
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700439 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
440 // this also ensures that any synchronous binding below doesn't re-trigger another
441 // LauncherModel load.
442 mPaused = false;
443
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200445 android.os.Debug.startMethodTracing(
446 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447 }
448
Adam Cohen53805212013-10-01 10:39:23 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700452
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100454 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800456 registerContentObservers();
457
Joe Onorato7c312c12009-08-13 21:36:53 -0700458 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 mSavedState = savedInstanceState;
461 restoreState(mSavedState);
462
463 if (PROFILE_STARTUP) {
464 android.os.Debug.stopMethodTracing();
465 }
466
467 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700468 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700469 // If the user leaves launcher, then we should just load items asynchronously when
470 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500471 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700472 } else {
473 // We only load the page synchronously if the user rotates (or triggers a
474 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800475 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700476 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800477 }
478
479 // For handling default keys
480 mDefaultKeySsb = new SpannableStringBuilder();
481 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800482
483 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
484 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800485
Adam Cohenf9426d52012-06-04 17:26:21 -0700486 updateGlobalIcons();
487
488 // On large interfaces, we want the screen to auto-rotate based on the current orientation
489 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700490
Adam Cohen432609a2014-03-13 17:03:22 -0700491 if (shouldShowIntroScreen()) {
492 showIntroScreen();
493 } else {
494 showFirstRunActivity();
495 }
496
Winson Chunge43a1e72014-01-15 10:33:02 -0800497 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
498 // on the device, then we always show the first run cling experience (or if there is no
499 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800500 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
501 if (mModel.canMigrateFromOldLauncherDb(this)) {
502 mLauncherClings.showMigrationCling();
503 } else {
504 mLauncherClings.showFirstRunCling();
505 }
Winson Chunga6945242014-01-08 14:04:34 -0800506 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800507 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800508 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700509 }
510
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700511 @Override
512 public void onLauncherProviderChange() { }
513
Winson Chung4a2afa32012-07-19 14:53:05 -0700514 protected void onUserLeaveHint() {
515 super.onUserLeaveHint();
516 sPausedFromUserAction = true;
517 }
518
Winson Chung98ca0f72013-07-29 12:58:51 -0700519 /** To be overriden by subclasses to hint to Launcher that we have custom content */
520 protected boolean hasCustomContentToLeft() {
521 return false;
522 }
523
Dave Hawkeya8881582013-09-17 15:55:33 -0600524 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500525 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600526 * {@link #addToCustomContentPage}. This will only be invoked if
527 * {@link #hasCustomContentToLeft()} is {@code true}.
528 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500529 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600530 }
531
532 /**
533 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
534 * ensure the custom content page is added or removed if necessary.
535 */
536 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600537 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600538 // Not bound yet, wait for bindScreens to be called.
539 return;
540 }
541
542 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
543 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500544 mWorkspace.createCustomContentContainer();
545 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600546 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
547 mWorkspace.removeCustomContentPage();
548 }
549 }
550
Adam Cohenf9426d52012-06-04 17:26:21 -0700551 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700552 boolean searchVisible = false;
553 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800554 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700555 int coi = getCurrentOrientationIndexForGlobalIcons();
556 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
557 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700558 if (!DISABLE_MARKET_BUTTON) {
559 updateAppMarketIcon();
560 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700561 searchVisible = updateGlobalSearchIcon();
562 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700563 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700564 if (sGlobalSearchIcon[coi] != null) {
565 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700566 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700567 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700568 if (sVoiceSearchIcon[coi] != null) {
569 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700570 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700571 }
Winson Chungd64a6662013-09-30 11:06:59 -0700572 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700573 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800574 }
Winson Chungadf0c182012-08-23 14:59:07 -0700575 if (mSearchDropTargetBar != null) {
576 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
577 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578 }
Romain Guycbb89e42009-06-08 15:52:54 -0700579
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800580 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700581 if (sLocaleConfiguration == null) {
582 new AsyncTask<Void, Void, LocaleConfiguration>() {
583 @Override
584 protected LocaleConfiguration doInBackground(Void... unused) {
585 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
586 readConfiguration(Launcher.this, localeConfiguration);
587 return localeConfiguration;
588 }
589
590 @Override
591 protected void onPostExecute(LocaleConfiguration result) {
592 sLocaleConfiguration = result;
593 checkForLocaleChange(); // recursive, but now with a locale configuration
594 }
595 }.execute();
596 return;
597 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700598
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599 final Configuration configuration = getResources().getConfiguration();
600
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800602 final String locale = configuration.locale.toString();
603
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700604 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800605 final int mcc = configuration.mcc;
606
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700607 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800608 final int mnc = configuration.mnc;
609
Romain Guy84f296c2009-11-04 15:00:44 -0800610 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800611
Romain Guy84f296c2009-11-04 15:00:44 -0800612 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613 sLocaleConfiguration.locale = locale;
614 sLocaleConfiguration.mcc = mcc;
615 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700616
Joe Onorato0589f0f2010-02-08 13:44:00 -0800617 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700618
619 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100620 new AsyncTask<Void, Void, Void>() {
621 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700622 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100623 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700624 }
Michael Jurka43467462013-11-14 12:03:58 +0100625 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700626 }
627 }
628
629 private static class LocaleConfiguration {
630 public String locale;
631 public int mcc = -1;
632 public int mnc = -1;
633 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700634
Romain Guy98d01652009-06-30 16:21:04 -0700635 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
636 DataInputStream in = null;
637 try {
638 in = new DataInputStream(context.openFileInput(PREFERENCES));
639 configuration.locale = in.readUTF();
640 configuration.mcc = in.readInt();
641 configuration.mnc = in.readInt();
642 } catch (FileNotFoundException e) {
643 // Ignore
644 } catch (IOException e) {
645 // Ignore
646 } finally {
647 if (in != null) {
648 try {
649 in.close();
650 } catch (IOException e) {
651 // Ignore
652 }
653 }
654 }
655 }
656
657 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
658 DataOutputStream out = null;
659 try {
660 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
661 out.writeUTF(configuration.locale);
662 out.writeInt(configuration.mcc);
663 out.writeInt(configuration.mnc);
664 out.flush();
665 } catch (FileNotFoundException e) {
666 // Ignore
667 } catch (IOException e) {
668 //noinspection ResultOfMethodCallIgnored
669 context.getFileStreamPath(PREFERENCES).delete();
670 } finally {
671 if (out != null) {
672 try {
673 out.close();
674 } catch (IOException e) {
675 // Ignore
676 }
677 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 }
679 }
680
Anton Hanssona2f665f2013-09-26 12:18:32 +0100681 public Stats getStats() {
682 return mStats;
683 }
684
Bjorn Bringertc459e522013-06-07 19:36:01 +0100685 public LayoutInflater getInflater() {
686 return mInflater;
687 }
688
Winson Chung36a62fe2012-05-06 18:04:42 -0700689 boolean isDraggingEnabled() {
690 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
691 // that is subsequently removed from the workspace in startBinding().
692 return !mModel.isLoadingWorkspace();
693 }
694
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 static int getScreen() {
696 synchronized (sLock) {
697 return sScreen;
698 }
699 }
700
701 static void setScreen(int screen) {
702 synchronized (sLock) {
703 sScreen = screen;
704 }
705 }
706
Winson Chung557d6ed2011-07-08 15:34:52 -0700707 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000708 * Copied from View -- the View version of the method isn't called
709 * anywhere else in our process and only exists for API level 17+,
710 * so it's ok to keep our own version with no API requirement.
711 */
712 public static int generateViewId() {
713 for (;;) {
714 final int result = sNextGeneratedId.get();
715 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
716 int newValue = result + 1;
717 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
718 if (sNextGeneratedId.compareAndSet(result, newValue)) {
719 return result;
720 }
721 }
722 }
723
724 public int getViewIdForItem(ItemInfo info) {
725 // This cast is safe given the > 2B range for int.
726 int itemId = (int) info.id;
727 if (mItemIdToViewId.containsKey(itemId)) {
728 return mItemIdToViewId.get(itemId);
729 }
730 int viewId = generateViewId();
731 mItemIdToViewId.put(itemId, viewId);
732 return viewId;
733 }
734
735 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700736 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
737 * a configuration step, this allows the proper animations to run after other transitions.
738 */
Adam Cohendb364c32014-05-20 14:23:40 -0700739 private long completeAdd(PendingAddArguments args) {
740
741 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800743 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700744 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700745 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700746 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700748 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700749 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800750 }
Michael Jurka27614d22012-04-02 06:40:22 -0700751 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
752 // if you turned the screen off and then back while in All Apps, Launcher would not
753 // return to the workspace. Clearing mAddInfo.container here fixes this issue
754 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700755 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800756 }
757
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700759 protected void onActivityResult(
760 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700761 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700762 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700763 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800764 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700765
Adam Cohenad4e15c2013-10-17 16:21:35 -0700766 Runnable exitSpringLoaded = new Runnable() {
767 @Override
768 public void run() {
769 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
770 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
771 }
772 };
773
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700775 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700776 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
777 if (resultCode == RESULT_CANCELED) {
778 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700779 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
783 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700784 }
785 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200786 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
787 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
788 mWorkspace.exitOverviewMode(false);
789 }
790 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700791 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200792
Adam Cohened66b2b2012-01-23 17:28:51 -0800793 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
794 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700795
Adam Cohendb364c32014-05-20 14:23:40 -0700796 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800797 // We have special handling for widgets
798 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800799 final int appWidgetId;
800 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
801 : -1;
802 if (widgetId < 0) {
803 appWidgetId = pendingAddWidgetId;
804 } else {
805 appWidgetId = widgetId;
806 }
807
Adam Cohenad4e15c2013-10-17 16:21:35 -0700808 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800809 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700810 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
811 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700812 result = RESULT_CANCELED;
813 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700814 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700815 @Override
816 public void run() {
817 exitSpringLoadedDragModeDelayed(false, 0, null);
818 }
819 };
Adam Cohendb364c32014-05-20 14:23:40 -0700820 if (workspaceLocked) {
821 // No need to remove the empty screen if we're mid-binding, as the
822 // the bind will not add the empty screen.
823 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
824 } else {
825 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
826 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
827 }
Winson Chung5aaab772012-04-27 15:24:02 -0700828 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700829 if (!workspaceLocked) {
830 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
831 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
832
833 dropLayout.setDropPending(true);
834 final Runnable onComplete = new Runnable() {
835 @Override
836 public void run() {
837 completeTwoStageWidgetDrop(resultCode, appWidgetId);
838 dropLayout.setDropPending(false);
839 }
840 };
841 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
842 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
843 } else {
844 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
845 mPendingAddInfo);
846 sPendingAddItem = args;
847 }
Winson Chung5aaab772012-04-27 15:24:02 -0700848 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800849 return;
850 }
851
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800852 // The pattern used here is that a user PICKs a specific application,
853 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700854
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
856 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700857 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700858 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
859 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800860 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700861 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800862 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700863 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700864 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
865 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 }
Adam Cohen00074722013-10-11 17:46:09 -0700867 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700868 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700869 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800870 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800871 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800872 }
873
Adam Cohendb364c32014-05-20 14:23:40 -0700874 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
875 appWidgetId, ItemInfo info) {
876 PendingAddArguments args = new PendingAddArguments();
877 args.requestCode = requestCode;
878 args.intent = data;
879 args.container = info.container;
880 args.screenId = info.screenId;
881 args.cellX = info.cellX;
882 args.cellY = info.cellY;
883 args.appWidgetId = appWidgetId;
884 return args;
885 }
886
887 /**
888 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
889 *
890 * @param screenId the screen id to check
891 * @return the new screen, or screenId if it exists
892 */
893 private long ensurePendingDropLayoutExists(long screenId) {
894 CellLayout dropLayout =
895 (CellLayout) mWorkspace.getScreenWithId(screenId);
896 if (dropLayout == null) {
897 // it's possible that the add screen was removed because it was
898 // empty and a re-bind occurred
899 mWorkspace.addExtraEmptyScreen();
900 return mWorkspace.commitExtraEmptyScreen();
901 } else {
902 return screenId;
903 }
904 }
905
Adam Cohened66b2b2012-01-23 17:28:51 -0800906 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700907 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700908 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800909 Runnable onCompleteRunnable = null;
910 int animationType = 0;
911
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700912 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800913 if (resultCode == RESULT_OK) {
914 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
915 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700916 mPendingAddWidgetInfo);
917 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800918 onCompleteRunnable = new Runnable() {
919 @Override
920 public void run() {
921 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700922 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700923 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
924 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800925 }
926 };
927 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800928 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800929 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700931 if (mDragLayer.getAnimatedView() != null) {
932 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
933 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
934 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700935 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700936 // The animated view may be null in the case of a rotation during widget configuration
937 onCompleteRunnable.run();
938 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 }
940
941 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700942 protected void onStop() {
943 super.onStop();
944 FirstFrameAnimatorHelper.setIsVisible(false);
945 }
946
947 @Override
948 protected void onStart() {
949 super.onStart();
950 FirstFrameAnimatorHelper.setIsVisible(true);
951 }
952
953 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200955 long startTime = 0;
956 if (DEBUG_RESUME_TIME) {
957 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400958 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200959 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700961
Winson Chung4a2afa32012-07-19 14:53:05 -0700962 // Restore the previous launcher state
963 if (mOnResumeState == State.WORKSPACE) {
964 showWorkspace(false);
965 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800966 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700967 }
968 mOnResumeState = State.NONE;
969
Craig Mautner360310b2012-10-26 15:13:08 -0700970 // Background was set to gradient in onPause(), restore to black if in all apps.
971 setWorkspaceBackground(mState == State.WORKSPACE);
972
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800973 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700974 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700975 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700976 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500977 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700979 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700981 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200982 // We might have postponed some bind calls until onResume (see waitUntilResume) --
983 // execute them here
984 long startTimeCallbacks = 0;
985 if (DEBUG_RESUME_TIME) {
986 startTimeCallbacks = System.currentTimeMillis();
987 }
988
989 if (mAppsCustomizeContent != null) {
990 mAppsCustomizeContent.setBulkBind(true);
991 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700992 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
993 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200994 }
995 if (mAppsCustomizeContent != null) {
996 mAppsCustomizeContent.setBulkBind(false);
997 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700998 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200999 if (DEBUG_RESUME_TIME) {
1000 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1001 (System.currentTimeMillis() - startTimeCallbacks));
1002 }
Michael Jurka447bf842013-05-15 14:52:15 +02001003 }
Michael Jurka54554252013-08-01 12:52:23 +02001004 if (mOnResumeCallbacks.size() > 0) {
1005 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1006 mOnResumeCallbacks.get(i).run();
1007 }
1008 mOnResumeCallbacks.clear();
1009 }
Winson Chunge4e50662012-01-23 14:45:13 -08001010
1011 // Reset the pressed state of icons that were locked in the press state while activities
1012 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001013 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001014 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001015 mWaitingForResume.setStayPressed(false);
1016 }
Winson Chunge4e50662012-01-23 14:45:13 -08001017 if (mAppsCustomizeContent != null) {
1018 // Resets the previous all apps icon press state
1019 mAppsCustomizeContent.resetDrawableState();
1020 }
Winson Chung82963d52013-10-09 11:20:57 -07001021
Adam Cohen06dff352012-06-01 17:17:08 -07001022 // It is possible that widgets can receive updates while launcher is not in the foreground.
1023 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1024 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1025 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001026 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001027
Winson Chung780fe592013-09-26 14:48:44 -07001028 // Process any items that were added while Launcher was away.
1029 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1030
Winson Chung5841efa2013-09-30 18:06:44 -07001031 // Update the voice search button proxy
1032 updateVoiceButtonProxyVisible(false);
1033
Adam Cohenf9426d52012-06-04 17:26:21 -07001034 // Again, as with the above scenario, it's possible that one or more of the global icons
1035 // were updated in the wrong orientation.
1036 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001037 if (DEBUG_RESUME_TIME) {
1038 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1039 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001040
1041 if (mWorkspace.getCustomContentCallbacks() != null) {
1042 // If we are resuming and the custom content is the current page, we call onShow().
1043 // It is also poassible that onShow will instead be called slightly after first layout
1044 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1045 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001046 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001047 }
1048 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001049 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001050 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001051 }
1052
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001054 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001055 // Ensure that items added to Launcher are queued until Launcher returns
1056 InstallShortcutReceiver.enableInstallQueue();
1057
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001058 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001059 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001060 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001061 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001062
1063 // We call onHide() aggressively. The custom content callbacks should be able to
1064 // debounce excess onHide calls.
1065 if (mWorkspace.getCustomContentCallbacks() != null) {
1066 mWorkspace.getCustomContentCallbacks().onHide();
1067 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 }
Romain Guycbb89e42009-06-08 15:52:54 -07001069
Adam Cohenbffe7452013-07-22 18:21:45 -07001070 QSBScroller mQsbScroller = new QSBScroller() {
1071 int scrollY = 0;
1072
1073 @Override
1074 public void setScrollY(int scroll) {
1075 scrollY = scroll;
1076
1077 if (mWorkspace.isOnOrMovingToCustomContent()) {
1078 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001079 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001080 }
1081 }
1082 };
1083
1084 public void resetQSBScroll() {
1085 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001086 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001087 }
1088
1089 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001090 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1091 // by a onResume or by scrolling otherwise.
1092 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001093
1094 // Custom content is completely hidden
1095 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001096
1097 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1098 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001099 }
1100
Jorim Jaggid017f882014-01-14 17:08:48 -08001101 protected boolean hasSettings() {
1102 return false;
1103 }
1104
Adam Cohenbffe7452013-07-22 18:21:45 -07001105 public interface QSBScroller {
1106 public void setScrollY(int scrollY);
1107 }
1108
Winson Chung98ca0f72013-07-29 12:58:51 -07001109 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001110 CustomContentCallbacks callbacks, String description) {
1111 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001112 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001113 }
1114
Adam Cohenedb40762013-07-18 16:45:45 -07001115 // The custom content needs to offset its content to account for the QSB
1116 public int getTopOffsetForCustomContent() {
1117 return mWorkspace.getPaddingTop();
1118 }
1119
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001120 @Override
1121 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001122 // Flag the loader to stop early before switching
1123 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001124 if (mAppsCustomizeContent != null) {
1125 mAppsCustomizeContent.surrender();
1126 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001127 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001128 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001129
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001130 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001131 @Override
1132 public void onWindowFocusChanged(boolean hasFocus) {
1133 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001134 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001135 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001136
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001137 private boolean acceptFilter() {
1138 final InputMethodManager inputManager = (InputMethodManager)
1139 getSystemService(Context.INPUT_METHOD_SERVICE);
1140 return !inputManager.isFullscreenMode();
1141 }
1142
1143 @Override
1144 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001145 final int uniChar = event.getUnicodeChar();
1146 final boolean handled = super.onKeyDown(keyCode, event);
1147 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1148 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001149 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1150 keyCode, event);
1151 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001152 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001153 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001154 // showSearchDialog()
1155 // If there are multiple keystrokes before the search dialog takes focus,
1156 // onSearchRequested() will be called for every keystroke,
1157 // but it is idempotent, so it's fine.
1158 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 }
1160 }
1161
Joe Onorato8a9625e2010-01-28 15:55:35 -08001162 // Eat the long press event so the keyboard doesn't come up.
1163 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1164 return true;
1165 }
1166
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 return handled;
1168 }
1169
Karl Rosaen138a0412009-04-23 19:00:21 -07001170 private String getTypedText() {
1171 return mDefaultKeySsb.toString();
1172 }
1173
1174 private void clearTypedText() {
1175 mDefaultKeySsb.clear();
1176 mDefaultKeySsb.clearSpans();
1177 Selection.setSelection(mDefaultKeySsb, 0);
1178 }
1179
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001181 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1182 * State
1183 */
1184 private static State intToState(int stateOrdinal) {
1185 State state = State.WORKSPACE;
1186 final State[] stateValues = State.values();
1187 for (int i = 0; i < stateValues.length; i++) {
1188 if (stateValues[i].ordinal() == stateOrdinal) {
1189 state = stateValues[i];
1190 break;
1191 }
1192 }
1193 return state;
1194 }
1195
1196 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001197 * Restores the previous state, if it exists.
1198 *
1199 * @param savedState The previous state.
1200 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001201 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 private void restoreState(Bundle savedState) {
1203 if (savedState == null) {
1204 return;
1205 }
1206
Michael Jurka883f55b2010-10-21 15:47:14 -07001207 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001208 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001209 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001210 }
1211
Adam Cohen21cd0022013-10-09 18:57:02 -07001212 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1213 PagedView.INVALID_RESTORE_PAGE);
1214 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001215 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 }
1217
Winson Chung3d503fb2011-07-13 17:25:49 -07001218 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001219 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001220
Winson Chung3d503fb2011-07-13 17:25:49 -07001221 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1222 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001223 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001224 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1225 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001226 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1227 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1228 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001229 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001230 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231 mRestoring = true;
1232 }
1233
1234 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1235 if (renameFolder) {
1236 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001237 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 mRestoring = true;
1239 }
Winson Chunga12a2502010-12-20 14:41:35 -08001240
Winson Chung785d2eb2011-04-14 16:08:02 -07001241 // Restore the AppsCustomize tab
1242 if (mAppsCustomizeTabHost != null) {
1243 String curTab = savedState.getString("apps_customize_currentTab");
1244 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001245 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001246 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001247 mAppsCustomizeContent.loadAssociatedPages(
1248 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001249 }
1250
Winson Chung5afbf7b2011-07-25 11:53:08 -07001251 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1252 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001253 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001254 mItemIdToViewId = (HashMap<Integer, Integer>)
1255 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 }
1257
1258 /**
1259 * Finds all the views we need and configure them properly.
1260 */
1261 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001262 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001263
Craig Mautner360310b2012-10-26 15:13:08 -07001264 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001265 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1266 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001267 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001268 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001269
John Spurlock77e1f472013-09-11 10:09:51 -04001270 mLauncherView.setSystemUiVisibility(
1271 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001272 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001273
Winson Chung4c98d922011-05-31 16:50:48 -07001274 // Setup the drag layer
1275 mDragLayer.setup(this, dragController);
1276
Winson Chung3d503fb2011-07-13 17:25:49 -07001277 // Setup the hotseat
1278 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1279 if (mHotseat != null) {
1280 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001281 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001282 }
1283
Jorim Jaggid017f882014-01-14 17:08:48 -08001284 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001285 View widgetButton = findViewById(R.id.widget_button);
1286 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001287 @Override
1288 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001289 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001290 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001291 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001292 }
1293 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001294 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1295
1296 View wallpaperButton = findViewById(R.id.wallpaper_button);
1297 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001298 @Override
1299 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001300 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001301 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001302 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001303 }
1304 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001305 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1306
1307 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001308 if (hasSettings()) {
1309 settingsButton.setOnClickListener(new OnClickListener() {
1310 @Override
1311 public void onClick(View arg0) {
1312 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001313 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001314 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001315 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001316 });
1317 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1318 } else {
1319 settingsButton.setVisibility(View.GONE);
1320 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1321 lp.gravity = Gravity.END | Gravity.TOP;
1322 widgetButton.requestLayout();
1323 }
1324
Adam Cohendbdff6b2013-09-18 19:09:15 -07001325 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001326
Winson Chung4c98d922011-05-31 16:50:48 -07001327 // Setup the workspace
1328 mWorkspace.setHapticFeedbackEnabled(false);
1329 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001330 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001331 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001332
Winson Chungf0ea4d32011-06-06 14:27:16 -07001333 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001334 mSearchDropTargetBar = (SearchDropTargetBar)
1335 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001336
Winson Chungf0ea4d32011-06-06 14:27:16 -07001337 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001338 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001339 mAppsCustomizeContent = (AppsCustomizePagedView)
1340 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1341 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001342
Winson Chung3d503fb2011-07-13 17:25:49 -07001343 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001344 dragController.setDragScoller(mWorkspace);
1345 dragController.setScrollView(mDragLayer);
1346 dragController.setMoveTarget(mWorkspace);
1347 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001348 if (mSearchDropTargetBar != null) {
1349 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001350 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001351
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001352 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001353 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001354 mWeightWatcher = new WeightWatcher(this);
1355 mWeightWatcher.setAlpha(0.5f);
1356 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001357 new FrameLayout.LayoutParams(
1358 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001359 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001360 Gravity.BOTTOM)
1361 );
Adam Cohen39a06042013-07-19 14:30:12 -07001362
1363 boolean show = shouldShowWeightWatcher();
1364 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001365 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 }
1367
1368 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001369 * Sets the all apps button. This method is called from {@link Hotseat}.
1370 */
1371 public void setAllAppsButton(View allAppsButton) {
1372 mAllAppsButton = allAppsButton;
1373 }
1374
1375 public View getAllAppsButton() {
1376 return mAllAppsButton;
1377 }
1378
1379 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 * Creates a view representing a shortcut.
1381 *
1382 * @param info The data structure describing the shortcut.
1383 *
1384 * @return A View inflated from R.layout.application.
1385 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001386 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001387 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001388 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389 }
1390
1391 /**
1392 * Creates a view representing a shortcut inflated from the specified resource.
1393 *
1394 * @param layoutResId The id of the XML layout used to create the shortcut.
1395 * @param parent The group the shortcut belongs to.
1396 * @param info The data structure describing the shortcut.
1397 *
1398 * @return A View inflated from layoutResId.
1399 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001400 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001401 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1402 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 return favorite;
1405 }
1406
1407 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 * Add a shortcut to the workspace.
1409 *
1410 * @param data The intent describing the shortcut.
1411 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001413 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001414 int cellY) {
1415 int[] cellXY = mTmpAddItemCellCoordinates;
1416 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001417 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001418
Michael Jurkad3ef3062010-11-23 16:23:58 -08001419 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001420
Adam Cohen558baaf2011-08-15 15:22:57 -07001421 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001422 if (info == null) {
1423 return;
1424 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001425 final View view = createShortcut(info);
1426
Adam Cohenfbba09b2011-07-18 21:43:05 -07001427 // First we check if we already know the exact location where we want to add this item.
1428 if (cellX >= 0 && cellY >= 0) {
1429 cellXY[0] = cellX;
1430 cellXY[1] = cellY;
1431 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001432
1433 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001434 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001435 true, null,null)) {
1436 return;
1437 }
1438 DragObject dragObject = new DragObject();
1439 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001440 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1441 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001442 return;
1443 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001444 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001445 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001446 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001447 foundCellSpan = (result != null);
1448 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001449 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001450 }
1451
1452 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001453 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001454 return;
1455 }
1456
Adam Cohendcd297f2013-06-18 13:13:40 -07001457 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458
1459 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001460 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001461 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001462 }
1463 }
1464
Adam Cohen2f093b62012-04-30 18:59:53 -07001465 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1466 int minHeight) {
1467 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001468 // We want to account for the extra amount of padding that we are adding to the widget
1469 // to ensure that it gets the full amount of space that it has requested
1470 int requiredWidth = minWidth + padding.left + padding.right;
1471 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001472 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001473 }
1474
Adam Cohen2f093b62012-04-30 18:59:53 -07001475 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1476 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001477 }
1478
Adam Cohen2f093b62012-04-30 18:59:53 -07001479 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1480 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001481 }
1482
Adam Cohen2f093b62012-04-30 18:59:53 -07001483 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1484 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001485 }
1486
Adam Cohen2f093b62012-04-30 18:59:53 -07001487 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1488 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001489 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001490 }
1491
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001493 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001494 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001495 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001496 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001498 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001499 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1500 if (appWidgetInfo == null) {
1501 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1502 }
Romain Guycbb89e42009-06-08 15:52:54 -07001503
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001504 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001505 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001506
Adam Cohen2f093b62012-04-30 18:59:53 -07001507 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1508 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001509
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001511 // We have saved the position to which the widget was dragged-- this really only matters
1512 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001513 int[] cellXY = mTmpAddItemCellCoordinates;
1514 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001515 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001516 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001517 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1518 cellXY[0] = mPendingAddInfo.cellX;
1519 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001520 spanXY[0] = mPendingAddInfo.spanX;
1521 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001522 foundCellSpan = true;
1523 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001524 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001525 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001526 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1527 spanXY[1], cellXY, finalSpan);
1528 spanXY[0] = finalSpan[0];
1529 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001530 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001531 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001532 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001533 }
1534
Michael Jurka0280c3b2010-09-17 15:00:07 -07001535 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001536 if (appWidgetId != -1) {
1537 // Deleting an app widget ID is a void call but writes to disk before returning
1538 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001539 new AsyncTask<Void, Void, Void>() {
1540 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001541 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001542 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001543 }
Michael Jurka43467462013-11-14 12:03:58 +01001544 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001545 }
Winson Chung93eef082012-03-23 15:59:27 -07001546 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001547 return;
1548 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001550 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001551 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1552 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001553 launcherInfo.spanX = spanXY[0];
1554 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001555 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1556 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001557
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001559 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560
1561 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001562 if (hostView == null) {
1563 // Perform actual inflation because we're live
1564 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1565 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1566 } else {
1567 // The AppWidgetHostView has already been inflated and instantiated
1568 launcherInfo.hostView = hostView;
1569 }
Romain Guycbb89e42009-06-08 15:52:54 -07001570
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001572 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001573 launcherInfo.notifyWidgetSizeChanged(this);
1574
Adam Cohendcd297f2013-06-18 13:13:40 -07001575 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001576 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001577
1578 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001579 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001580 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001581 }
Romain Guycbb89e42009-06-08 15:52:54 -07001582
Adam Cohended9f8d2010-11-03 13:25:16 -07001583 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1584 @Override
1585 public void onReceive(Context context, Intent intent) {
1586 final String action = intent.getAction();
1587 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1588 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001589 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001590 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001591
Winson Chungc100e8e2011-08-09 16:02:43 -07001592 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001593 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001594 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001595 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001596 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001597 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1598 mUserPresent = true;
1599 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001600 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1601 mModel.resetLoadedState(false, true);
1602 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1603 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1604 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1605 mModel.resetLoadedState(false, true);
1606 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1607 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1608 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001609 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1610 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1611 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001612 }
1613 }
1614 };
1615
1616 @Override
1617 public void onAttachedToWindow() {
1618 super.onAttachedToWindow();
1619
1620 // Listen for broadcasts related to user-presence
1621 final IntentFilter filter = new IntentFilter();
1622 filter.addAction(Intent.ACTION_SCREEN_OFF);
1623 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001624 // For handling managed profiles
1625 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1626 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001627 if (ENABLE_DEBUG_INTENTS) {
1628 filter.addAction(DebugIntents.DELETE_DATABASE);
1629 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1630 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001631 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001632 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001633 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001634 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001635 mVisible = true;
1636 }
1637
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001638 /**
1639 * Sets up transparent navigation and status bars in LMP.
1640 * This method is a no-op for other platform versions.
1641 */
Sandeep Siddhartha876b0032014-05-19 11:45:01 -07001642 @TargetApi(19)
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001643 private void setupTransparentSystemBarsForLmp() {
1644 // TODO(sansid): use the APIs directly when compiling against L sdk.
1645 // Currently we use reflection to access the flags and the API to set the transparency
1646 // on the System bars.
1647 if (Utilities.isLmp()) {
1648 try {
1649 getWindow().getAttributes().systemUiVisibility |=
1650 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1651 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1652 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Sandeep Siddhartha876b0032014-05-19 11:45:01 -07001653 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1654 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001655 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1656 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1657 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1658
1659 Method setStatusBarColorMethod =
1660 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1661 Method setNavigationBarColorMethod =
1662 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1663 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1664 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1665 } catch (NoSuchFieldException e) {
1666 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1667 } catch (NoSuchMethodException ex) {
1668 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1669 } catch (IllegalAccessException e) {
1670 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1671 } catch (IllegalArgumentException e) {
1672 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1673 } catch (InvocationTargetException e) {
1674 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1675 } finally {}
1676 }
1677 }
1678
Adam Cohended9f8d2010-11-03 13:25:16 -07001679 @Override
1680 public void onDetachedFromWindow() {
1681 super.onDetachedFromWindow();
1682 mVisible = false;
1683
Adam Cohend113e0c2010-11-11 10:48:05 -08001684 if (mAttached) {
1685 unregisterReceiver(mReceiver);
1686 mAttached = false;
1687 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001688 updateRunning();
1689 }
1690
1691 public void onWindowVisibilityChanged(int visibility) {
1692 mVisible = visibility == View.VISIBLE;
1693 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001694 // The following code used to be in onResume, but it turns out onResume is called when
1695 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1696 // is a more appropriate event to handle
1697 if (mVisible) {
1698 mAppsCustomizeTabHost.onWindowVisible();
1699 if (!mWorkspaceLoading) {
1700 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001701 // We want to let Launcher draw itself at least once before we force it to build
1702 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001703 // apps is nice and speedy.
1704 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001705 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001706 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001707 if (mStarted) return;
1708 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001709 // We delay the layer building a bit in order to give
1710 // other message processing a time to run. In particular
1711 // this avoids a delay in hiding the IME if it was
1712 // currently shown, because doing that may involve
1713 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001714 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001715 final ViewTreeObserver.OnDrawListener listener = this;
1716 mWorkspace.post(new Runnable() {
1717 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001718 if (mWorkspace != null &&
1719 mWorkspace.getViewTreeObserver() != null) {
1720 mWorkspace.getViewTreeObserver().
1721 removeOnDrawListener(listener);
1722 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001723 }
1724 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001725 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001726 }
1727 });
1728 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001729 // When Launcher comes back to foreground, a different Activity might be responsible for
1730 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001731 if (!DISABLE_MARKET_BUTTON) {
1732 updateAppMarketIcon();
1733 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001734 clearTypedText();
1735 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001736 }
1737
1738 private void sendAdvanceMessage(long delay) {
1739 mHandler.removeMessages(ADVANCE_MSG);
1740 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1741 mHandler.sendMessageDelayed(msg, delay);
1742 mAutoAdvanceSentTime = System.currentTimeMillis();
1743 }
1744
1745 private void updateRunning() {
1746 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1747 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1748 mAutoAdvanceRunning = autoAdvanceRunning;
1749 if (autoAdvanceRunning) {
1750 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1751 sendAdvanceMessage(delay);
1752 } else {
1753 if (!mWidgetsToAdvance.isEmpty()) {
1754 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1755 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1756 }
1757 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001758 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001759 }
1760 }
1761 }
1762
1763 private final Handler mHandler = new Handler() {
1764 @Override
1765 public void handleMessage(Message msg) {
1766 if (msg.what == ADVANCE_MSG) {
1767 int i = 0;
1768 for (View key: mWidgetsToAdvance.keySet()) {
1769 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1770 final int delay = mAdvanceStagger * i;
1771 if (v instanceof Advanceable) {
1772 postDelayed(new Runnable() {
1773 public void run() {
1774 ((Advanceable) v).advance();
1775 }
1776 }, delay);
1777 }
1778 i++;
1779 }
1780 sendAdvanceMessage(mAdvanceInterval);
1781 }
1782 }
1783 };
1784
1785 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001786 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001787 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1788 if (v instanceof Advanceable) {
1789 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001790 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001791 updateRunning();
1792 }
1793 }
1794
1795 void removeWidgetToAutoAdvance(View hostView) {
1796 if (mWidgetsToAdvance.containsKey(hostView)) {
1797 mWidgetsToAdvance.remove(hostView);
1798 updateRunning();
1799 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001800 }
1801
Joe Onorato9c1289c2009-08-17 11:03:03 -04001802 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001803 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001804 launcherInfo.hostView = null;
1805 }
1806
Winson Chung93eef082012-03-23 15:59:27 -07001807 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1808 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1809 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001810 }
1811
Winson Chunga6945242014-01-08 14:04:34 -08001812 public DragLayer getDragLayer() {
1813 return mDragLayer;
1814 }
1815
1816 public Workspace getWorkspace() {
1817 return mWorkspace;
1818 }
1819
1820 public Hotseat getHotseat() {
1821 return mHotseat;
1822 }
1823
Jorim Jaggid017f882014-01-14 17:08:48 -08001824 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001825 return mOverviewPanel;
1826 }
1827
1828 public SearchDropTargetBar getSearchBar() {
1829 return mSearchDropTargetBar;
1830 }
1831
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001832 public LauncherAppWidgetHost getAppWidgetHost() {
1833 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 }
Romain Guycbb89e42009-06-08 15:52:54 -07001835
Winson Chunga9abd0e2010-10-27 17:18:37 -07001836 public LauncherModel getModel() {
1837 return mModel;
1838 }
1839
Winson Chunga6945242014-01-08 14:04:34 -08001840 public LauncherClings getLauncherClings() {
1841 return mLauncherClings;
1842 }
1843
1844 protected SharedPreferences getSharedPrefs() {
1845 return mSharedPrefs;
1846 }
1847
Bjorn Bringertc459e522013-06-07 19:36:01 +01001848 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001849 getWindow().closeAllPanels();
1850
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001851 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001852 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001853 }
1854
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 @Override
1856 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001857 long startTime = 0;
1858 if (DEBUG_RESUME_TIME) {
1859 startTime = System.currentTimeMillis();
1860 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 super.onNewIntent(intent);
1862
1863 // Close the menu
1864 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001865 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001866 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001867
Adam Cohened307df2013-10-02 09:37:31 -07001868 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1869 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1870 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001871
Adam Cohen6fecd412013-10-02 17:41:50 -07001872 if (mWorkspace == null) {
1873 // Can be cases where mWorkspace is null, this prevents a NPE
1874 return;
1875 }
1876 Folder openFolder = mWorkspace.getOpenFolder();
1877 // In all these cases, only animate if we're already on home
1878 mWorkspace.exitWidgetResizeMode();
1879 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001880 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001881 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001882 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001883
Adam Cohen6fecd412013-10-02 17:41:50 -07001884 closeFolder();
1885 exitSpringLoadedDragMode();
1886
1887 // If we are already on home, then just animate back to the workspace,
1888 // otherwise, just wait until onResume to set the state back to Workspace
1889 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001890 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001891 } else {
1892 mOnResumeState = State.WORKSPACE;
1893 }
1894
1895 final View v = getWindow().peekDecorView();
1896 if (v != null && v.getWindowToken() != null) {
1897 InputMethodManager imm = (InputMethodManager)getSystemService(
1898 INPUT_METHOD_SERVICE);
1899 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1900 }
1901
1902 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001903 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001904 mAppsCustomizeTabHost.reset();
1905 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001906
1907 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 }
Adam Cohened307df2013-10-02 09:37:31 -07001909
Michael Jurka447bf842013-05-15 14:52:15 +02001910 if (DEBUG_RESUME_TIME) {
1911 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1912 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001913 }
1914
Adam Coppa120b8e2013-11-12 16:26:04 +00001915 /**
1916 * Override point for subclasses to prevent movement to the default screen when the home
1917 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1918 */
1919 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1920 return true;
1921 }
1922
1923 /**
1924 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1925 */
1926 protected void onHomeIntent() {
1927 // Do nothing
1928 }
1929
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001931 public void onRestoreInstanceState(Bundle state) {
1932 super.onRestoreInstanceState(state);
1933 for (int page: mSynchronouslyBoundPages) {
1934 mWorkspace.restoreInstanceStateForChild(page);
1935 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 }
1937
1938 @Override
1939 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001940 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001941 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1942 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001943 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001944 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945
Michael Jurka883f55b2010-10-21 15:47:14 -07001946 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001947 // We close any open folder since it will not be re-opened, and we need to make sure
1948 // this state is reflected.
1949 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950
Adam Cohendcd297f2013-06-18 13:13:40 -07001951 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001952 mWaitingForResult) {
1953 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001954 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001955 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1956 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001957 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1958 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1959 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001960 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 }
1962
1963 if (mFolderInfo != null && mWaitingForResult) {
1964 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1965 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1966 }
Michael Jurka946ad472010-07-09 18:05:18 -07001967
Winson Chung785d2eb2011-04-14 16:08:02 -07001968 // Save the current AppsCustomize tab
1969 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001970 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1971 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001972 if (currentTabTag != null) {
1973 outState.putString("apps_customize_currentTab", currentTabTag);
1974 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001975 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1976 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001977 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001978 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001979 }
1980
1981 @Override
1982 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001984
Winson Chunge7a03942011-08-05 15:05:12 -07001985 // Remove all pending runnables
1986 mHandler.removeMessages(ADVANCE_MSG);
1987 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001988 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001989
Winson Chungcd2b0142011-06-08 16:02:26 -07001990 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001991 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001992 mModel.stopLoader();
1993 app.setLauncher(null);
1994
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001996 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001998 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002000 mAppWidgetHost = null;
2001
2002 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003
2004 TextKeyListener.getInstance().release();
2005
Winson Chung81b52252012-08-27 15:34:29 -07002006 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2007 // to prevent leaking Launcher activities on orientation change.
2008 if (mModel != null) {
2009 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2010 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002011
2012 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002013 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002014
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002015 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002016 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002017 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002018 mWorkspace = null;
2019 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002020
Michael Jurka2ecf9952012-06-18 12:52:28 -07002021 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 }
2023
Adam Cohena9cf38f2011-05-02 15:36:58 -07002024 public DragController getDragController() {
2025 return mDragController;
2026 }
2027
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002028 @Override
2029 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002030 if (requestCode >= 0) {
2031 setWaitingForResult(true);
2032 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 super.startActivityForResult(intent, requestCode);
2034 }
2035
Winson Chung70d72102011-08-12 11:24:35 -07002036 /**
2037 * Indicates that we want global search for this activity by setting the globalSearch
2038 * argument for {@link #startSearch} to true.
2039 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002041 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002042 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002043
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002044 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002045
Karl Rosaen138a0412009-04-23 19:00:21 -07002046 if (initialQuery == null) {
2047 // Use any text typed in the launcher as the initial query
2048 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002049 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 if (appSearchData == null) {
2051 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002052 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 }
Winson Chungadf0c182012-08-23 14:59:07 -07002054 Rect sourceBounds = new Rect();
2055 if (mSearchDropTargetBar != null) {
2056 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2057 }
Romain Guycbb89e42009-06-08 15:52:54 -07002058
Bjorn Bringertc459e522013-06-07 19:36:01 +01002059 startSearch(initialQuery, selectInitialQuery,
2060 appSearchData, sourceBounds);
2061 }
2062
2063 public void startSearch(String initialQuery,
2064 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002065 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002066 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002067 }
2068
2069 /**
2070 * Starts the global search activity. This code is a copied from SearchManager
2071 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002072 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002073 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002074 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002075 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2076 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2077 if (globalSearchActivity == null) {
2078 Log.w(TAG, "No global search activity found.");
2079 return;
2080 }
2081 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2082 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2083 intent.setComponent(globalSearchActivity);
2084 // Make sure that we have a Bundle to put source in
2085 if (appSearchData == null) {
2086 appSearchData = new Bundle();
2087 } else {
2088 appSearchData = new Bundle(appSearchData);
2089 }
2090 // Set source to package name of app that starts global search, if not set already.
2091 if (!appSearchData.containsKey("source")) {
2092 appSearchData.putString("source", getPackageName());
2093 }
2094 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2095 if (!TextUtils.isEmpty(initialQuery)) {
2096 intent.putExtra(SearchManager.QUERY, initialQuery);
2097 }
2098 if (selectInitialQuery) {
2099 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2100 }
2101 intent.setSourceBounds(sourceBounds);
2102 try {
2103 startActivity(intent);
2104 } catch (ActivityNotFoundException ex) {
2105 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2106 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002107 }
2108
Yura4f93ec62014-02-04 14:15:21 +00002109 public boolean isOnCustomContent() {
2110 return mWorkspace.isOnOrMovingToCustomContent();
2111 }
2112
Winson Chung70d72102011-08-12 11:24:35 -07002113 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002114 public boolean onPrepareOptionsMenu(Menu menu) {
2115 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002116 if (!isOnCustomContent()) {
2117 // Close any open folders
2118 closeFolder();
2119 // Stop resizing any widgets
2120 mWorkspace.exitWidgetResizeMode();
2121 if (!mWorkspace.isInOverviewMode()) {
2122 // Show the overview mode
2123 showOverviewMode(true);
2124 } else {
2125 showWorkspace(true);
2126 }
Winson Chunge0298742014-01-17 12:03:00 -08002127 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002128 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002129 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002131 @Override
2132 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002133 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002134 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002135 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002136 }
2137
Joe Onorato9c1289c2009-08-17 11:03:03 -04002138 public boolean isWorkspaceLocked() {
2139 return mWorkspaceLoading || mWaitingForResult;
2140 }
2141
Adam Cohen517a7f52014-03-01 12:12:59 -08002142 public boolean isWorkspaceLoading() {
2143 return mWorkspaceLoading;
2144 }
2145
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002146 private void setWorkspaceLoading(boolean value) {
2147 boolean isLocked = isWorkspaceLocked();
2148 mWorkspaceLoading = value;
2149 if (isLocked != isWorkspaceLocked()) {
2150 onWorkspaceLockedChanged();
2151 }
2152 }
2153
2154 private void setWaitingForResult(boolean value) {
2155 boolean isLocked = isWorkspaceLocked();
2156 mWaitingForResult = value;
2157 if (isLocked != isWorkspaceLocked()) {
2158 onWorkspaceLockedChanged();
2159 }
2160 }
2161
2162 protected void onWorkspaceLockedChanged() { }
2163
Michael Jurka0280c3b2010-09-17 15:00:07 -07002164 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002165 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002166 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002167 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2168 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002169 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002170 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002171 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002172
Adam Cohenad4e15c2013-10-17 16:21:35 -07002173 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2174 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2175 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2176 }
2177
2178 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2179 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2180 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002181 if (appWidgetInfo.configure != null) {
2182 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002183 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002184
Bjorn Bringert7984c942009-12-09 15:38:25 +00002185 // Launch over to configure widget, if needed
2186 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002187 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002188 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002189 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002190 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002191 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002192 Runnable onComplete = new Runnable() {
2193 @Override
2194 public void run() {
2195 // Exit spring loaded mode if necessary after adding the widget
2196 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2197 null);
2198 }
2199 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002200 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002201 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002202 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 }
2204 }
Romain Guycbb89e42009-06-08 15:52:54 -07002205
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002206 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002207 // Close any folders that may be open.
2208 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002209 mWorkspace.moveToCustomContentScreen(animate);
2210 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002211 /**
2212 * Process a shortcut drop.
2213 *
2214 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002215 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002216 * @param cell The cell it should be added to, optional
2217 * @param position The location on the screen where it was dropped, optional
2218 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002219 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002220 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002221 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002222 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002223 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002224 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002225
2226 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002227 mPendingAddInfo.cellX = cell[0];
2228 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002229 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002230
2231 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2232 createShortcutIntent.setComponent(componentName);
2233 processShortcut(createShortcutIntent);
2234 }
2235
Adam Cohenfbba09b2011-07-18 21:43:05 -07002236 /**
2237 * Process a widget drop.
2238 *
2239 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002240 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002241 * @param cell The cell it should be added to, optional
2242 * @param position The location on the screen where it was dropped, optional
2243 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002244 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002245 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002246 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002247 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002248 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002249 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002250 mPendingAddInfo.minSpanX = info.minSpanX;
2251 mPendingAddInfo.minSpanY = info.minSpanY;
2252
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002254 mPendingAddInfo.cellX = cell[0];
2255 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002256 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002257 if (span != null) {
2258 mPendingAddInfo.spanX = span[0];
2259 mPendingAddInfo.spanY = span[1];
2260 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002261
Adam Cohened66b2b2012-01-23 17:28:51 -08002262 AppWidgetHostView hostView = info.boundWidget;
2263 int appWidgetId;
2264 if (hostView != null) {
2265 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002266 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002267 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002268 // In this case, we either need to start an activity to get permission to bind
2269 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002270 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002271 Bundle options = info.bindOptions;
2272
2273 boolean success = false;
2274 if (options != null) {
2275 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2276 info.componentName, options);
2277 } else {
2278 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2279 info.componentName);
2280 }
2281 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002282 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002283 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002284 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002285 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2286 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2287 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002288 // TODO: we need to make sure that this accounts for the options bundle.
2289 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002290 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2291 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002292 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002293 }
2294
Joe Onoratodeb98af2010-02-19 14:59:39 -08002295 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002296 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002297 }
2298
Winson Chung24ab2f12010-09-16 14:10:47 -07002299 void processWallpaper(Intent intent) {
2300 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2301 }
2302
Adam Cohendcd297f2013-06-18 13:13:40 -07002303 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002305 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002306 folderInfo.title = getText(R.string.folder_name);
2307
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002308 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002309 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002311 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002312
2313 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002314 FolderIcon newFolder =
2315 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002316 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002317 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002318 // Force measure the new folder icon
2319 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2320 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002321 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002322 }
Romain Guycbb89e42009-06-08 15:52:54 -07002323
Joe Onorato9c1289c2009-08-17 11:03:03 -04002324 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002325 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002326 }
2327
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002328 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002329 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002330 }
2331
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002332 /**
2333 * Registers various content observers. The current implementation registers
2334 * only a favorites observer to keep track of the favorites applications.
2335 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002336 private void registerContentObservers() {
2337 ContentResolver resolver = getContentResolver();
2338 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2339 true, mWidgetObserver);
2340 }
2341
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 @Override
2343 public boolean dispatchKeyEvent(KeyEvent event) {
2344 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2345 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002346 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002347 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002348 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002349 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002350 dumpState();
2351 return true;
2352 }
2353 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002354 }
2355 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2356 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002357 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 return true;
2359 }
2360 }
2361
2362 return super.dispatchKeyEvent(event);
2363 }
2364
Joe Onorato88ec0992009-11-19 13:16:06 -08002365 @Override
2366 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002367 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002368 if (mAppsCustomizeContent.getContentType() ==
2369 AppsCustomizePagedView.ContentType.Applications) {
2370 showWorkspace(true);
2371 } else {
2372 showOverviewMode(true);
2373 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002374 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002375 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002376 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002377 Folder openFolder = mWorkspace.getOpenFolder();
2378 if (openFolder.isEditingName()) {
2379 openFolder.dismissEditingName();
2380 } else {
2381 closeFolder();
2382 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002383 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002384 mWorkspace.exitWidgetResizeMode();
2385
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002386 // Back button is a no-op here, but give at least some feedback for the button press
2387 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002388 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002389 }
2390
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002391 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002392 * Re-listen when widgets are reset.
2393 */
2394 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002395 if (mAppWidgetHost != null) {
2396 mAppWidgetHost.startListening();
2397 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002398 }
2399
2400 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002401 * Launches the intent referred by the clicked shortcut.
2402 *
2403 * @param v The view representing the clicked shortcut.
2404 */
2405 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002406 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2407 // view has detached (it's possible for this to happen if the view is removed mid touch).
2408 if (v.getWindowToken() == null) {
2409 return;
2410 }
2411
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002412 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002413 return;
2414 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002415
Adam Cohen1697b792013-09-17 19:08:21 -07002416 if (v instanceof Workspace) {
2417 if (mWorkspace.isInOverviewMode()) {
2418 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002419 }
2420 return;
2421 }
2422
2423 if (v instanceof CellLayout) {
2424 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002425 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002426 }
2427 }
2428
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002430 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002431 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002432 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002433 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002434 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002435 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002436 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002437 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002438 }
2439 }
2440
Michael Jurka0e260592010-06-30 17:07:39 -07002441 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002442 return false;
2443 }
2444
Michael Jurkaaf442092010-06-10 17:01:57 -07002445 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002446 * Event handler for the search button
2447 *
2448 * @param v The view that was clicked.
2449 */
2450 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002451 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2452
Amith Yamasania135ba82011-08-09 17:42:01 -07002453 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002454 }
2455
2456 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002457 * Event handler for the voice button
2458 *
2459 * @param v The view that was clicked.
2460 */
2461 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002462 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002463
Bjorn Bringertc459e522013-06-07 19:36:01 +01002464 startVoice();
2465 }
2466
2467 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002468 try {
2469 final SearchManager searchManager =
2470 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2471 ComponentName activityName = searchManager.getGlobalSearchActivity();
2472 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002473 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002474 if (activityName != null) {
2475 intent.setPackage(activityName.getPackageName());
2476 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002477 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002478 } catch (ActivityNotFoundException e) {
2479 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002480 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002481 startActivitySafely(null, intent, "onClickVoiceButton");
2482 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002483 }
2484
2485 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002486 * Event handler for the "grid" button that appears on the home screen, which
2487 * enters all apps mode.
2488 *
2489 * @param v The view that was clicked.
2490 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002491 protected void onClickAllAppsButton(View v) {
2492 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2493 if (isAllAppsVisible()) {
2494 showWorkspace(true);
2495 } else {
2496 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2497 }
2498 }
2499
2500 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002501 * Event handler for a paged view icon click.
2502 * @param v The view that was clicked.
2503 * @param appInfo The {link AppInfo} of the view.
2504 */
2505 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2506 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2507 startActivitySafely(v, appInfo.intent, appInfo);
2508 getStats().recordLaunch(appInfo.intent);
2509 }
2510
2511 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002512 * Event handler for an app shortcut click.
2513 *
2514 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2515 */
2516 protected void onClickAppShortcut(View v) {
2517 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2518 Object tag = v.getTag();
2519 if (!(tag instanceof ShortcutInfo)) {
2520 throw new IllegalArgumentException("Input must be a Shortcut");
2521 }
2522
2523 // Open shortcut
2524 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2525 final Intent intent = shortcut.intent;
2526
2527 // Check for special shortcuts
2528 if (intent.getComponent() != null) {
2529 final String shortcutClass = intent.getComponent().getClassName();
2530
2531 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2532 MemoryDumpActivity.startDump(this);
2533 return;
2534 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2535 toggleShowWeightWatcher();
2536 return;
2537 }
2538 }
2539
2540 // Start activities
2541 int[] pos = new int[2];
2542 v.getLocationOnScreen(pos);
2543 intent.setSourceBounds(new Rect(pos[0], pos[1],
2544 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2545
2546 boolean success = startActivitySafely(v, intent, tag);
2547
2548 mStats.recordLaunch(intent, shortcut);
2549
2550 if (success && v instanceof BubbleTextView) {
2551 mWaitingForResume = (BubbleTextView) v;
2552 mWaitingForResume.setStayPressed(true);
2553 }
2554 }
2555
2556 /**
2557 * Event handler for a folder icon click.
2558 *
2559 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2560 */
2561 protected void onClickFolderIcon(View v) {
2562 if (LOGD) Log.d(TAG, "onClickFolder");
2563 if (!(v instanceof FolderIcon)){
2564 throw new IllegalArgumentException("Input must be a FolderIcon");
2565 }
2566
2567 FolderIcon folderIcon = (FolderIcon) v;
2568 final FolderInfo info = folderIcon.getFolderInfo();
2569 Folder openFolder = mWorkspace.getFolderForTag(info);
2570
2571 // If the folder info reports that the associated folder is open, then verify that
2572 // it is actually opened. There have been a few instances where this gets out of sync.
2573 if (info.opened && openFolder == null) {
2574 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2575 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2576 info.opened = false;
2577 }
2578
2579 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2580 // Close any open folder
2581 closeFolder();
2582 // Open the requested folder
2583 openFolder(folderIcon);
2584 } else {
2585 // Find the open folder...
2586 int folderScreen;
2587 if (openFolder != null) {
2588 folderScreen = mWorkspace.getPageForView(openFolder);
2589 // .. and close it
2590 closeFolder(openFolder);
2591 if (folderScreen != mWorkspace.getCurrentPage()) {
2592 // Close any folder open on the current screen
2593 closeFolder();
2594 // Pull the folder onto this screen
2595 openFolder(folderIcon);
2596 }
2597 }
2598 }
Michael Jurka5130e402011-10-13 04:55:35 -07002599 }
2600
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002601 /**
2602 * Event handler for the (Add) Widgets button that appears after a long press
2603 * on the home screen.
2604 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002605 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002606 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002607 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2608 }
2609
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002610 /**
2611 * Event handler for the wallpaper picker button that appears after a long press
2612 * on the home screen.
2613 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002614 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002615 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2616 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2617 pickWallpaper.setComponent(getWallpaperPickerComponent());
2618 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2619 }
2620
2621 /**
2622 * Event handler for a click on the settings button that appears after a long press
2623 * on the home screen.
2624 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002625 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002626 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2627 }
2628
Michael Jurka5130e402011-10-13 04:55:35 -07002629 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002630 // Provide the same haptic feedback that the system offers for virtual keys.
2631 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002632 }
2633
Adam Cohen61f560d2013-09-30 15:58:20 -07002634 public void performHapticFeedbackOnTouchDown(View v) {
2635 // Provide the same haptic feedback that the system offers for virtual keys.
2636 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2637 }
2638
2639 public View.OnTouchListener getHapticFeedbackTouchListener() {
2640 if (mHapticFeedbackTouchListener == null) {
2641 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2642 @Override
2643 public boolean onTouch(View v, MotionEvent event) {
2644 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2645 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2646 }
2647 return false;
2648 }
2649 };
2650 }
2651 return mHapticFeedbackTouchListener;
2652 }
2653
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002654 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002655 if (!DISABLE_MARKET_BUTTON) {
2656 if (mAppMarketIntent != null) {
2657 startActivitySafely(v, mAppMarketIntent, "app market");
2658 } else {
2659 Log.e(TAG, "Invalid app market intent.");
2660 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002661 }
2662 }
2663
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002664 public void onDragStarted(View view) {}
2665
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002666 /**
2667 * Called when the user stops interacting with the launcher.
2668 * This implies that the user is now on the homescreen and is not doing housekeeping.
2669 */
2670 protected void onInteractionEnd() {}
2671
2672 /**
2673 * Called when the user starts interacting with the launcher.
2674 * The possible interactions are:
2675 * - open all apps
2676 * - reorder an app shortcut, or a widget
2677 * - open the overview mode.
2678 * This is a good time to stop doing things that only make sense
2679 * when the user is on the homescreen and not doing housekeeping.
2680 */
2681 protected void onInteractionBegin() {}
2682
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002683 void startApplicationDetailsActivity(ComponentName componentName) {
2684 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002685 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2686 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002687 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2688 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002689 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002690 }
2691
Michael Jurka1e2f4652013-07-08 18:03:46 -07002692 // returns true if the activity was started
2693 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002694 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002695 // System applications cannot be installed. For now, show a toast explaining that.
2696 // We may give them the option of disabling apps this way.
2697 int messageId = R.string.uninstall_system_app_text;
2698 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002699 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002700 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002701 String packageName = componentName.getPackageName();
2702 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002703 Intent intent = new Intent(
2704 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002705 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2706 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002707 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002708 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002709 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002710 }
2711
Michael Jurka86a720e2012-05-09 11:23:23 -07002712 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002713 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002714 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002715 // Only launch using the new animation if the shortcut has not opted out (this is a
2716 // private contract between launcher and may be ignored in the future).
2717 boolean useLaunchAnimation = (v != null) &&
2718 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002719 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2720 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002721
Kenny Guy1317e2d2014-05-08 18:52:50 +01002722 UserHandleCompat user = null;
2723 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2724 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2725 user = userManager.getUserForSerialNumber(serialNumber);
2726 }
2727
2728 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002729 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002730 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2731 v.getMeasuredWidth(), v.getMeasuredHeight());
Kenny Guy1317e2d2014-05-08 18:52:50 +01002732 optsBundle = opts.toBundle();
2733 }
2734
2735 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2736 // Could be launching some bookkeeping activity
2737 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002738 } else {
Kenny Guy1317e2d2014-05-08 18:52:50 +01002739 launcherApps.startActivityForProfile(intent.getComponent(),
2740 intent.getSourceBounds(), optsBundle, user);
Winson Chungc7450e32012-04-17 17:34:08 -07002741 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002742 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002743 } catch (SecurityException e) {
2744 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002745 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002746 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002747 "or use the exported attribute for this activity. "
2748 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002749 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002750 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002752
Michael Jurka86a720e2012-05-09 11:23:23 -07002753 boolean startActivitySafely(View v, Intent intent, Object tag) {
2754 boolean success = false;
2755 try {
2756 success = startActivity(v, intent, tag);
2757 } catch (ActivityNotFoundException e) {
2758 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2759 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2760 }
2761 return success;
2762 }
2763
Adam Cohen268c4752012-06-06 17:47:33 -07002764 /**
2765 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2766 * in the DragLayer in the exact absolute location of the original FolderIcon.
2767 */
2768 private void copyFolderIconToImage(FolderIcon fi) {
2769 final int width = fi.getMeasuredWidth();
2770 final int height = fi.getMeasuredHeight();
2771
2772 // Lazy load ImageView, Bitmap and Canvas
2773 if (mFolderIconImageView == null) {
2774 mFolderIconImageView = new ImageView(this);
2775 }
2776 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2777 mFolderIconBitmap.getHeight() != height) {
2778 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2779 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2780 }
2781
2782 DragLayer.LayoutParams lp;
2783 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2784 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2785 } else {
2786 lp = new DragLayer.LayoutParams(width, height);
2787 }
2788
Adam Cohen307fe232012-08-16 17:55:58 -07002789 // The layout from which the folder is being opened may be scaled, adjust the starting
2790 // view size by this scale factor.
2791 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002792 lp.customPosition = true;
2793 lp.x = mRectForFolderAnimation.left;
2794 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002795 lp.width = (int) (scale * width);
2796 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002797
2798 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2799 fi.draw(mFolderIconCanvas);
2800 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002801 if (fi.getFolder() != null) {
2802 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2803 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002804 }
Adam Cohen268c4752012-06-06 17:47:33 -07002805 // Just in case this image view is still in the drag layer from a previous animation,
2806 // we remove it and re-add it.
2807 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2808 mDragLayer.removeView(mFolderIconImageView);
2809 }
2810 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002811 if (fi.getFolder() != null) {
2812 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002813 }
Adam Cohen268c4752012-06-06 17:47:33 -07002814 }
2815
Adam Cohen2801caf2011-05-13 20:57:39 -07002816 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002817 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002818 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2819 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2820 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2821
Adam Cohenc51934b2011-07-26 21:07:43 -07002822 FolderInfo info = (FolderInfo) fi.getTag();
2823 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2824 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002825 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2826 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002827 }
2828
Adam Cohen268c4752012-06-06 17:47:33 -07002829 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2830 copyFolderIconToImage(fi);
2831 fi.setVisibility(View.INVISIBLE);
2832
Michael Jurka2ecf9952012-06-18 12:52:28 -07002833 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002834 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002835 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2836 oa.start();
2837 }
2838
Adam Cohen268c4752012-06-06 17:47:33 -07002839 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002840 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002841 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2842 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2843 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2844
Adam Cohen268c4752012-06-06 17:47:33 -07002845 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002846
Adam Cohen268c4752012-06-06 17:47:33 -07002847 // We remove and re-draw the FolderIcon in-case it has changed
2848 mDragLayer.removeView(mFolderIconImageView);
2849 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002850 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002851 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002852 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002853 oa.addListener(new AnimatorListenerAdapter() {
2854 @Override
2855 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002856 if (cl != null) {
2857 cl.clearFolderLeaveBehind();
2858 // Remove the ImageView copy of the FolderIcon and make the original visible.
2859 mDragLayer.removeView(mFolderIconImageView);
2860 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002861 }
2862 }
2863 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002864 oa.start();
2865 }
2866
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002867 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002868 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002869 * is animated relative to the specified View. If the View is null, no animation
2870 * is played.
2871 *
2872 * @param folderInfo The FolderInfo describing the folder to open.
2873 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002874 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002875 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002876 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002877
Adam Cohena9cf38f2011-05-02 15:36:58 -07002878 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002879
Adam Cohen4554ee12011-08-03 16:13:21 -07002880 // Just verify that the folder hasn't already been added to the DragLayer.
2881 // There was a one-off crash where the folder had a parent already.
2882 if (folder.getParent() == null) {
2883 mDragLayer.addView(folder);
2884 mDragController.addDropTarget((DropTarget) folder);
2885 } else {
2886 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2887 folder.getParent() + ").");
2888 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002889 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002890 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002891
2892 // Notify the accessibility manager that this folder "window" has appeared and occluded
2893 // the workspace items
2894 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2895 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002896 }
2897
2898 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002899 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002900 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002901 if (folder.isEditingName()) {
2902 folder.dismissEditingName();
2903 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002904 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002905
2906 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002907 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002908 }
2909 }
2910
2911 void closeFolder(Folder folder) {
2912 folder.getInfo().opened = false;
2913
2914 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2915 if (parent != null) {
2916 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2917 shrinkAndFadeInFolderIcon(fi);
2918 }
2919 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002920
2921 // Notify the accessibility manager that this folder "window" has disappeard and no
2922 // longer occludeds the workspace items
2923 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002924 }
2925
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002926 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002927 if (!isDraggingEnabled()) return false;
2928 if (isWorkspaceLocked()) return false;
2929 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002930
Adam Cohen1697b792013-09-17 19:08:21 -07002931 if (v instanceof Workspace) {
2932 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002933 if (mWorkspace.enterOverviewMode()) {
2934 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2935 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2936 return true;
2937 } else {
2938 return false;
2939 }
Adam Cohen1697b792013-09-17 19:08:21 -07002940 }
Adam Cohen1697b792013-09-17 19:08:21 -07002941 }
2942
Adam Cohene0aaa0d2014-05-12 12:44:22 -07002943 CellLayout.CellInfo longClickCellInfo = null;
2944 View itemUnderLongClick = null;
2945 if (v.getTag() instanceof ItemInfo) {
2946 ItemInfo info = (ItemInfo) v.getTag();
2947 longClickCellInfo = new CellLayout.CellInfo(v, info);;
2948 itemUnderLongClick = longClickCellInfo.cell;
2949 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002950 }
2951
Winson Chung3d503fb2011-07-13 17:25:49 -07002952 // The hotseat touch handling does not go through Workspace, and we always allow long press
2953 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05002954 final boolean inHotseat = isHotseatLayout(v);
2955 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002956 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002957 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002958 // User long pressed on empty space
2959 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2960 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2961 // Disabling reordering until we sort out some issues.
2962 if (mWorkspace.isInOverviewMode()) {
2963 mWorkspace.startReordering(v);
2964 } else {
2965 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002966 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002967 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002968 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2969 mHotseat.getOrderInHotseat(
2970 longClickCellInfo.cellX,
2971 longClickCellInfo.cellY));
2972 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002973 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002974 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002975 }
2976 }
2977 }
2978 return true;
2979 }
2980
Winson Chung3d503fb2011-07-13 17:25:49 -07002981 boolean isHotseatLayout(View layout) {
2982 return mHotseat != null && layout != null &&
2983 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2984 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002985
Winson Chung3d503fb2011-07-13 17:25:49 -07002986 /**
2987 * Returns the CellLayout of the specified container at the specified screen.
2988 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002989 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002990 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2991 if (mHotseat != null) {
2992 return mHotseat.getLayout();
2993 } else {
2994 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002995 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002996 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002997 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002998 }
2999 }
3000
Daniel Sandler843e8602010-06-07 14:59:01 -04003001 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003002 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003003 }
3004
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003005 /**
3006 * Helper method for the cameraZoomIn/cameraZoomOut animations
3007 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003008 * @param scaleFactor The scale factor used for the zoom
3009 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07003010 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003011 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07003012 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003013 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05003014
Craig Mautner360310b2012-10-26 15:13:08 -07003015 private void setWorkspaceBackground(boolean workspace) {
3016 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003017 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003018 }
3019
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003020 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003021 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3022 int curflags = getWindow().getAttributes().flags
3023 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3024 if (wpflags != curflags) {
3025 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3026 }
Craig Mautner360310b2012-10-26 15:13:08 -07003027 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003028 }
3029
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003030 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3031 if (v instanceof LauncherTransitionable) {
3032 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3033 }
3034 }
3035
Michael Jurkabed61d22012-02-14 22:51:29 -08003036 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3037 if (v instanceof LauncherTransitionable) {
3038 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3039 }
Winson Chung70442722012-02-10 15:43:22 -08003040
3041 // Update the workspace transition step as well
3042 dispatchOnLauncherTransitionStep(v, 0f);
3043 }
3044
3045 private void dispatchOnLauncherTransitionStep(View v, float t) {
3046 if (v instanceof LauncherTransitionable) {
3047 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3048 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003049 }
3050
3051 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3052 if (v instanceof LauncherTransitionable) {
3053 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3054 }
Winson Chung70442722012-02-10 15:43:22 -08003055
3056 // Update the workspace transition step as well
3057 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003058 }
3059
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003060 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003061 * Things to test when changing the following seven functions.
3062 * - Home from workspace
3063 * - from center screen
3064 * - from other screens
3065 * - Home from all apps
3066 * - from center screen
3067 * - from other screens
3068 * - Back from all apps
3069 * - from center screen
3070 * - from other screens
3071 * - Launch app from workspace and quit
3072 * - with back
3073 * - with home
3074 * - Launch app from all apps and quit
3075 * - with back
3076 * - with home
3077 * - Go to a screen that's not the default, then all
3078 * apps, and launch and app, and go back
3079 * - with back
3080 * -with home
3081 * - On workspace, long press power and go back
3082 * - with back
3083 * - with home
3084 * - On all apps, long press power and go back
3085 * - with back
3086 * - with home
3087 * - On workspace, power off
3088 * - On all apps, power off
3089 * - Launch an app and turn off the screen while in that app
3090 * - Go back with home key
3091 * - Go back with back key TODO: make this not go to workspace
3092 * - From all apps
3093 * - From workspace
3094 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3095 * - From all apps
3096 * - From the center workspace
3097 * - From another workspace
3098 */
3099
3100 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003101 * Zoom the camera out from the workspace to reveal 'toView'.
3102 * Assumes that the view to show is anchored at either the very top or very bottom
3103 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003104 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003105 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003106 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3107 showAppsCustomizeHelper(animated, springLoaded, contentType);
3108 }
3109 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3110 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003111 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003112 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003113 mStateAnimation.cancel();
3114 mStateAnimation = null;
3115 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003116 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003117
Winson Chungf0ea4d32011-06-06 14:27:16 -07003118 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3119 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3120 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003121 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003122 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003123 final int startDelay =
3124 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003125
Michael Jurkab3e22d92011-10-31 15:58:33 -07003126 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003127
Michael Jurkad74c9842011-07-10 12:44:21 -07003128 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003129 Animator workspaceAnim =
3130 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003131 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003132 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3133 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003134 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3135 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003136
3137 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003138 toView.setScaleX(scale);
3139 toView.setScaleY(scale);
3140 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3141 scaleAnim.
3142 scaleX(1f).scaleY(1f).
3143 setDuration(duration).
3144 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003145
Winson Chungf0ea4d32011-06-06 14:27:16 -07003146 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003147 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003148 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003149 .ofFloat(toView, "alpha", 0f, 1f)
3150 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003151 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003152 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3153 @Override
3154 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003155 if (animation == null) {
3156 throw new RuntimeException("animation is null");
3157 }
Winson Chung70442722012-02-10 15:43:22 -08003158 float t = (Float) animation.getAnimatedValue();
3159 dispatchOnLauncherTransitionStep(fromView, t);
3160 dispatchOnLauncherTransitionStep(toView, t);
3161 }
3162 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003163
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003164 // toView should appear right at the end of the workspace shrink
3165 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003166 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003167 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003168 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003169
3170 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003171 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003172 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003173 // Prepare the position
3174 toView.setTranslationX(0.0f);
3175 toView.setTranslationY(0.0f);
3176 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003177 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003178 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003179 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003180 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003181 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3182 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003183
Winson Chungc7d2b602012-05-16 17:02:20 -07003184 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003185 if (mSearchDropTargetBar != null) {
3186 mSearchDropTargetBar.hideSearchBar(false);
3187 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003188 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003189 });
3190
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003191 if (workspaceAnim != null) {
3192 mStateAnimation.play(workspaceAnim);
3193 }
Michael Jurka1899a362011-11-03 13:50:45 -07003194
3195 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003196
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003197 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3198 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003199
3200 // If any of the objects being animated haven't been measured/laid out
3201 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003202 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003203 (mWorkspace.getMeasuredWidth() == 0) ||
3204 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003205 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003206 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003207
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003208 final AnimatorSet stateAnimation = mStateAnimation;
3209 final Runnable startAnimRunnable = new Runnable() {
3210 public void run() {
3211 // Check that mStateAnimation hasn't changed while
3212 // we waited for a layout/draw pass
3213 if (mStateAnimation != stateAnimation)
3214 return;
3215 setPivotsForZoom(toView, scale);
3216 dispatchOnLauncherTransitionStart(fromView, animated, false);
3217 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003218 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003219 }
3220 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003221 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003222 final ViewTreeObserver observer = toView.getViewTreeObserver();
3223 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3224 public void onGlobalLayout() {
3225 startAnimRunnable.run();
3226 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3227 }
3228 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003229 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003230 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003231 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003232 } else {
3233 toView.setTranslationX(0.0f);
3234 toView.setTranslationY(0.0f);
3235 toView.setScaleX(1.0f);
3236 toView.setScaleY(1.0f);
3237 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003238 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003239
Daniel Sandlere4f98912013-06-25 15:13:26 -04003240 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003241 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003242 if (mSearchDropTargetBar != null) {
3243 mSearchDropTargetBar.hideSearchBar(false);
3244 }
Michael Jurkaabded662011-03-04 12:06:57 -08003245 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003246 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003247 dispatchOnLauncherTransitionStart(fromView, animated, false);
3248 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003249 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003250 dispatchOnLauncherTransitionStart(toView, animated, false);
3251 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003252 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003253 }
3254
3255 /**
3256 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003257 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003258 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003259 */
Adam Cohened307df2013-10-02 09:37:31 -07003260 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003261 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003262
Michael Jurkab3e22d92011-10-31 15:58:33 -07003263 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003264 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003265 mStateAnimation.cancel();
3266 mStateAnimation = null;
3267 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003268 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003269
Winson Chungf0ea4d32011-06-06 14:27:16 -07003270 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003271 final int fadeOutDuration =
3272 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003273 final float scaleFactor = (float)
3274 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3275 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003276 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003277 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003278 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003279 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3280 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003281 toState, animated, stagger, -1);
3282 } else if (toState == Workspace.State.SPRING_LOADED ||
3283 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003284 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003285 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003286 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003287
Michael Jurkab3e22d92011-10-31 15:58:33 -07003288 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003289 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003290 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003291 final LauncherViewPropertyAnimator scaleAnim =
3292 new LauncherViewPropertyAnimator(fromView);
3293 scaleAnim.
3294 scaleX(scaleFactor).scaleY(scaleFactor).
3295 setDuration(duration).
3296 setInterpolator(new Workspace.ZoomInInterpolator());
3297
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003298 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003299 .ofFloat(fromView, "alpha", 1f, 0f)
3300 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003301 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003302 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3303 @Override
3304 public void onAnimationUpdate(ValueAnimator animation) {
3305 float t = 1f - (Float) animation.getAnimatedValue();
3306 dispatchOnLauncherTransitionStep(fromView, t);
3307 dispatchOnLauncherTransitionStep(toView, t);
3308 }
3309 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003310
Michael Jurka2ecf9952012-06-18 12:52:28 -07003311 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003312
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003313 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3314 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003315 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003316
3317 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003318 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003319 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003320 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003321 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3322 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003323 if (onCompleteRunnable != null) {
3324 onCompleteRunnable.run();
3325 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003326 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003327 }
3328 });
3329
Winson Chungf0ea4d32011-06-06 14:27:16 -07003330 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003331 if (workspaceAnim != null) {
3332 mStateAnimation.play(workspaceAnim);
3333 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003334 dispatchOnLauncherTransitionStart(fromView, animated, true);
3335 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003336 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003337 } else {
3338 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003339 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003340 dispatchOnLauncherTransitionStart(fromView, animated, true);
3341 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003342 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003343 dispatchOnLauncherTransitionStart(toView, animated, true);
3344 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003345 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003346 }
3347
Michael Jurkae326f182011-11-21 14:05:46 -08003348 @Override
3349 public void onTrimMemory(int level) {
3350 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003351 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003352 mAppsCustomizeTabHost.onTrimMemory();
3353 }
3354 }
3355
Adam Cohened307df2013-10-02 09:37:31 -07003356 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003357 showWorkspace(animated, null);
3358 }
3359
Adam Cohened307df2013-10-02 09:37:31 -07003360 protected void showWorkspace() {
3361 showWorkspace(true);
3362 }
3363
Adam Cohened66b2b2012-01-23 17:28:51 -08003364 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003365 if (mWorkspace.isInOverviewMode()) {
3366 mWorkspace.exitOverviewMode(animated);
3367 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003368 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003369 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003370 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003371 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003372
Winson Chungc7d2b602012-05-16 17:02:20 -07003373 // Show the search bar (only animate if we were showing the drop target bar in spring
3374 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003375 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003376 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003377 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003378
Michael Jurkab3e22d92011-10-31 15:58:33 -07003379 // Set focus to the AppsCustomize button
3380 if (mAllAppsButton != null) {
3381 mAllAppsButton.requestFocus();
3382 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003383 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003384
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003385 // Change the state *after* we've called all the transition code
3386 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003387
Winson Chung5fb63472011-02-02 17:03:37 -08003388 // Resume the auto-advance of widgets
3389 mUserPresent = true;
3390 updateRunning();
3391
alanv1d4fde62012-10-17 13:15:47 -07003392 // Send an accessibility event to announce the context change
3393 getWindow().getDecorView()
3394 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003395
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003396 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003397 }
3398
Adam Cohened307df2013-10-02 09:37:31 -07003399 void showOverviewMode(boolean animated) {
3400 mWorkspace.setVisibility(View.VISIBLE);
3401 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3402 mState = State.WORKSPACE;
3403 onWorkspaceShown(animated);
3404 }
3405
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003406 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003407 }
3408
Winson Chung82963d52013-10-09 11:20:57 -07003409 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3410 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003411 if (mState != State.WORKSPACE) return;
3412
Winson Chung82963d52013-10-09 11:20:57 -07003413 if (resetPageToZero) {
3414 mAppsCustomizeTabHost.reset();
3415 }
Winson Chungc58497e2013-09-03 17:48:37 -07003416 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003417 mAppsCustomizeTabHost.requestFocus();
3418
Michael Jurkab3e22d92011-10-31 15:58:33 -07003419 // Change the state *after* we've called all the transition code
3420 mState = State.APPS_CUSTOMIZE;
3421
3422 // Pause the auto-advance of widgets until we are out of AllApps
3423 mUserPresent = false;
3424 updateRunning();
3425 closeFolder();
3426
3427 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003428 getWindow().getDecorView()
3429 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003430 }
3431
Adam Cohen7777d962011-08-18 18:58:38 -07003432 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003433 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003434 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003435 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003436 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003437 }
Adam Cohen7777d962011-08-18 18:58:38 -07003438
Adam Cohenad4e15c2013-10-17 16:21:35 -07003439 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003440 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003441 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3442
Winson Chunge7a03942011-08-05 15:05:12 -07003443 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003444 @Override
3445 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003446 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003447 // Before we show workspace, hide all apps again because
3448 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3449 // clean up our state transition functions
3450 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003451 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003452 } else {
3453 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003454 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003455 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003456 }, delay);
3457
Winson Chung557d6ed2011-07-08 15:34:52 -07003458 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003459
Michael Jurkad3ef3062010-11-23 16:23:58 -08003460 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003461 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003462 final boolean animated = true;
3463 final boolean springLoaded = true;
3464 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003465 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003466 }
3467 // Otherwise, we are not in spring loaded mode, so don't do anything.
3468 }
3469
Michael Jurkab3e22d92011-10-31 15:58:33 -07003470 void lockAllApps() {
3471 // TODO
3472 }
3473
3474 void unlockAllApps() {
3475 // TODO
3476 }
3477
Winson Chungf0ea4d32011-06-06 14:27:16 -07003478 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003479 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003480 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003481 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003482 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003483 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003484 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003485 int duration = 0;
3486 if (mSearchDropTargetBar != null) {
3487 duration = mSearchDropTargetBar.getTransitionInDuration();
3488 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003489 mHotseat.animate().alpha(1f).setDuration(duration);
3490 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003491 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003492 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003493 }
3494 }
3495 }
3496
3497 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003498 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003499 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003500 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003501 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003502 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003503 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003504 int duration = 0;
3505 if (mSearchDropTargetBar != null) {
3506 duration = mSearchDropTargetBar.getTransitionOutDuration();
3507 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003508 mHotseat.animate().alpha(0f).setDuration(duration);
3509 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003510 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003511 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003512 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003513 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003514 }
3515
Patrick Dubroy5f445422011-02-18 14:35:21 -08003516 /**
3517 * Add an item from all apps or customize onto the given workspace screen.
3518 * If layout is null, add to the current screen.
3519 */
3520 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003521 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003522 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003523 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003524 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003525
Winson Chungdff8ebb2011-09-08 17:25:31 -07003526 /** Maps the current orientation to an index for referencing orientation correct global icons */
3527 private int getCurrentOrientationIndexForGlobalIcons() {
3528 // default - 0, landscape - 1
3529 switch (getResources().getConfiguration().orientation) {
3530 case Configuration.ORIENTATION_LANDSCAPE:
3531 return 1;
3532 default:
3533 return 0;
3534 }
3535 }
3536
Michael Jurkaae65ee32012-04-30 11:45:54 -07003537 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003538 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003539 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003540 // Look for the toolbar icon specified in the activity meta-data
3541 Bundle metaData = packageManager.getActivityInfo(
3542 activityName, PackageManager.GET_META_DATA).metaData;
3543 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003544 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003545 if (iconResId != 0) {
3546 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003547 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003548 }
3549 }
3550 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003551 // This can happen if the activity defines an invalid drawable
3552 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3553 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003554 } catch (Resources.NotFoundException nfe) {
3555 // This can happen if the activity defines an invalid drawable
3556 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3557 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003558 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003559 return null;
3560 }
3561
3562 // if successful in getting icon, return it; otherwise, set button to use default drawable
3563 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003564 int buttonId, ComponentName activityName, int fallbackDrawableId,
3565 String toolbarResourceName) {
3566 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003567 Resources r = getResources();
3568 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3569 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003570
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003571 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003572 // If we were unable to find the icon via the meta-data, use a generic one
3573 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003574 toolbarIcon = r.getDrawable(fallbackDrawableId);
3575 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003576 if (button != null) {
3577 button.setCompoundDrawables(toolbarIcon, null, null, null);
3578 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003579 return null;
3580 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003581 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003582 if (button != null) {
3583 button.setCompoundDrawables(toolbarIcon, null, null, null);
3584 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003585 return toolbarIcon.getConstantState();
3586 }
3587 }
3588
3589 // if successful in getting icon, return it; otherwise, set button to use default drawable
3590 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003591 int buttonId, ComponentName activityName, int fallbackDrawableId,
3592 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003593 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003594 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003595
Michael Jurka19e0fc52011-07-22 18:00:21 -07003596 if (button != null) {
3597 // If we were unable to find the icon via the meta-data, use a
3598 // generic one
3599 if (toolbarIcon == null) {
3600 button.setImageResource(fallbackDrawableId);
3601 } else {
3602 button.setImageDrawable(toolbarIcon);
3603 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003604 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003605
3606 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3607
Michael Jurka0423dcf2010-10-05 14:56:18 -07003608 }
3609
Winson Chung1b884092012-06-08 17:13:02 -07003610 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003611 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003612 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003613 }
3614
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003615 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003616 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003617 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003618 }
3619
Winson Chungbb185bd2011-11-21 12:31:42 -08003620 private void invalidatePressedFocusedStates(View container, View button) {
3621 if (container instanceof HolographicLinearLayout) {
3622 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3623 layout.invalidatePressedFocusedStates();
3624 } else if (button instanceof HolographicImageView) {
3625 HolographicImageView view = (HolographicImageView) button;
3626 view.invalidatePressedFocusedStates();
3627 }
3628 }
3629
Cristina Stancu476493b2013-08-07 17:20:14 +01003630 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003631 if (mQsb == null) {
3632 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3633 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003634 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003635 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003636 }
3637
3638 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003639 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003640 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003641 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003642 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003643
Winson Chung1cad91e2011-05-25 17:41:01 -07003644 final SearchManager searchManager =
3645 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3646 ComponentName activityName = searchManager.getGlobalSearchActivity();
3647 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003648 int coi = getCurrentOrientationIndexForGlobalIcons();
3649 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003650 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3651 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3652 if (sGlobalSearchIcon[coi] == null) {
3653 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3654 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3655 TOOLBAR_ICON_METADATA_NAME);
3656 }
3657
Winson Chungc51db6a2011-10-05 11:44:49 -07003658 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3659 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003660 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003661 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003662 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003663 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003664 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3665 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003666 if (searchButton != null) searchButton.setVisibility(View.GONE);
3667 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003668 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003669 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003670 }
3671 }
3672
Cristina Stancu476493b2013-08-07 17:20:14 +01003673 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003674 final View searchButtonContainer = findViewById(R.id.search_button_container);
3675 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003676 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003677 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003678 }
3679
Cristina Stancu476493b2013-08-07 17:20:14 +01003680 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003681 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003682 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003683
Winson Chungc51db6a2011-10-05 11:44:49 -07003684 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003685 final SearchManager searchManager =
3686 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3687 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3688
3689 ComponentName activityName = null;
3690 if (globalSearchActivity != null) {
3691 // Check if the global search activity handles voice search
3692 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3693 intent.setPackage(globalSearchActivity.getPackageName());
3694 activityName = intent.resolveActivity(getPackageManager());
3695 }
3696
3697 if (activityName == null) {
3698 // Fallback: check if an activity other than the global search activity
3699 // resolves this
3700 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3701 activityName = intent.resolveActivity(getPackageManager());
3702 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003703 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003704 int coi = getCurrentOrientationIndexForGlobalIcons();
3705 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003706 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3707 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3708 if (sVoiceSearchIcon[coi] == null) {
3709 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3710 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3711 TOOLBAR_ICON_METADATA_NAME);
3712 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003713 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003714 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003715 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003716 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003717 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003718 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003719 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003720 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003721 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003722 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003723 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003724 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003725
Cristina Stancu476493b2013-08-07 17:20:14 +01003726 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003727 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3728 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003729 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003730 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003731 }
3732
Winson Chung5841efa2013-09-30 18:06:44 -07003733 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003734 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3735 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003736 boolean visible = !forceDisableVoiceButtonProxy &&
3737 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003738 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003739 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003740 }
3741 }
Winson Chung5841efa2013-09-30 18:06:44 -07003742
3743 /**
3744 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3745 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3746 */
3747 public void disableVoiceButtonProxy(boolean disabled) {
3748 updateVoiceButtonProxyVisible(disabled);
3749 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003750 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003751 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003752 */
3753 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003754 if (!DISABLE_MARKET_BUTTON) {
3755 final View marketButton = findViewById(R.id.market_button);
3756 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3757 // Find the app market activity by resolving an intent.
3758 // (If multiple app markets are installed, it will return the ResolverActivity.)
3759 ComponentName activityName = intent.resolveActivity(getPackageManager());
3760 if (activityName != null) {
3761 int coi = getCurrentOrientationIndexForGlobalIcons();
3762 mAppMarketIntent = intent;
3763 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3764 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3765 TOOLBAR_ICON_METADATA_NAME);
3766 marketButton.setVisibility(View.VISIBLE);
3767 } else {
3768 // We should hide and disable the view so that we don't try and restore the visibility
3769 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3770 marketButton.setVisibility(View.GONE);
3771 marketButton.setEnabled(false);
3772 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003773 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003774 }
3775
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003776 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003777 if (!DISABLE_MARKET_BUTTON) {
3778 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3779 Resources r = getResources();
3780 Drawable marketIconDrawable = d.newDrawable(r);
3781 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3782 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3783 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003784
Winson Chungd64a6662013-09-30 11:06:59 -07003785 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3786 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003787 }
3788
Michael Jurkad7c28052012-04-27 15:43:36 -07003789 @Override
3790 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003791 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003792 final List<CharSequence> text = event.getText();
3793 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003794 // Populate event with a fake title based on the current state.
3795 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003796 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003797 } else {
3798 text.add(getString(R.string.all_apps_home_button_label));
3799 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003800 return result;
3801 }
3802
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003803 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003804 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003805 */
3806 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3807 @Override
3808 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003809 closeSystemDialogs();
3810 }
3811 }
3812
3813 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003814 * Receives notifications whenever the appwidgets are reset.
3815 */
3816 private class AppWidgetResetObserver extends ContentObserver {
3817 public AppWidgetResetObserver() {
3818 super(new Handler());
3819 }
3820
3821 @Override
3822 public void onChange(boolean selfChange) {
3823 onAppWidgetReset();
3824 }
3825 }
3826
3827 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003828 * If the activity is currently paused, signal that we need to run the passed Runnable
3829 * in onResume.
3830 *
3831 * This needs to be called from incoming places where resources might have been loaded
3832 * while we are paused. That is becaues the Configuration might be wrong
3833 * when we're not running, and if it comes back to what it was when we
3834 * were paused, we are not restarted.
3835 *
3836 * Implementation of the method from LauncherModel.Callbacks.
3837 *
3838 * @return true if we are currently paused. The caller might be able to
3839 * skip some work in that case since we will come back again.
3840 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003841 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003842 if (mPaused) {
3843 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003844 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003845 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003846 }
3847 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003848 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003849 return true;
3850 } else {
3851 return false;
3852 }
3853 }
3854
Michael Jurkac402cd92013-05-20 15:49:32 +02003855 private boolean waitUntilResume(Runnable run) {
3856 return waitUntilResume(run, false);
3857 }
3858
Michael Jurka1e2f4652013-07-08 18:03:46 -07003859 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003860 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003861 }
3862
Michael Jurka7607c2f2013-04-03 14:33:19 -07003863 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003864 * If the activity is currently paused, signal that we need to re-run the loader
3865 * in onResume.
3866 *
3867 * This needs to be called from incoming places where resources might have been loaded
3868 * while we are paused. That is becaues the Configuration might be wrong
3869 * when we're not running, and if it comes back to what it was when we
3870 * were paused, we are not restarted.
3871 *
3872 * Implementation of the method from LauncherModel.Callbacks.
3873 *
3874 * @return true if we are currently paused. The caller might be able to
3875 * skip some work in that case since we will come back again.
3876 */
3877 public boolean setLoadOnResume() {
3878 if (mPaused) {
3879 Log.i(TAG, "setLoadOnResume");
3880 mOnResumeNeedsLoad = true;
3881 return true;
3882 } else {
3883 return false;
3884 }
3885 }
3886
3887 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003888 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003889 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003890 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003891 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003892 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003893 } else {
3894 return SCREEN_COUNT / 2;
3895 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003896 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003897
Joe Onorato9c1289c2009-08-17 11:03:03 -04003898 /**
3899 * Refreshes the shortcuts shown on the workspace.
3900 *
3901 * Implementation of the method from LauncherModel.Callbacks.
3902 */
3903 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003904 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003905
Michael Jurka7607c2f2013-04-03 14:33:19 -07003906 // If we're starting binding all over again, clear any bind calls we'd postponed in
3907 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3908 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003909 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003910
Winson Chungd64d1762013-08-20 14:37:16 -07003911 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003912 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003913 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003914
Michael Jurka05bf6442011-11-30 20:28:53 -08003915 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003916 if (mHotseat != null) {
3917 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003918 }
3919 }
3920
Adam Cohendcd297f2013-06-18 13:13:40 -07003921 @Override
3922 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003923 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003924
Adam Cohen5084cba2013-09-03 12:01:16 -07003925 // If there are no screens, we need to have an empty screen
3926 if (orderedScreenIds.size() == 0) {
3927 mWorkspace.addExtraEmptyScreen();
3928 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003929
3930 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003931 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003932 if (hasCustomContentToLeft()) {
3933 mWorkspace.createCustomContentContainer();
3934 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003935 }
Winson Chung64359a52013-07-08 17:17:08 -07003936 }
3937
3938 @Override
3939 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003940 // Log to disk
3941 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3942 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3943 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003944 int count = orderedScreenIds.size();
3945 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003946 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003947 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003948 }
3949
Adam Cohen39a06042013-07-19 14:30:12 -07003950 private boolean shouldShowWeightWatcher() {
3951 String spKey = LauncherAppState.getSharedPreferencesKey();
3952 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003953 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003954
3955 return show;
3956 }
3957
3958 private void toggleShowWeightWatcher() {
3959 String spKey = LauncherAppState.getSharedPreferencesKey();
3960 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3961 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3962
3963 show = !show;
3964
3965 SharedPreferences.Editor editor = sp.edit();
3966 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3967 editor.commit();
3968
3969 if (mWeightWatcher != null) {
3970 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3971 }
3972 }
3973
Winson Chungd64d1762013-08-20 14:37:16 -07003974 public void bindAppsAdded(final ArrayList<Long> newScreens,
3975 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003976 final ArrayList<ItemInfo> addAnimated,
3977 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003978 Runnable r = new Runnable() {
3979 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003980 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003981 }
3982 };
3983 if (waitUntilResume(r)) {
3984 return;
3985 }
3986
Winson Chungd64d1762013-08-20 14:37:16 -07003987 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003988 if (newScreens != null) {
3989 bindAddScreens(newScreens);
3990 }
Winson Chungd64d1762013-08-20 14:37:16 -07003991
3992 // We add the items without animation on non-visible pages, and with
3993 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003994 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003995 bindItems(addNotAnimated, 0,
3996 addNotAnimated.size(), false);
3997 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003998 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003999 bindItems(addAnimated, 0,
4000 addAnimated.size(), true);
4001 }
Winson Chungc58497e2013-09-03 17:48:37 -07004002
Winson Chung87412982013-10-03 18:34:14 -07004003 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004004 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004005
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004006 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004007 addedApps != null && mAppsCustomizeContent != null) {
4008 mAppsCustomizeContent.addApps(addedApps);
4009 }
Winson Chungd64d1762013-08-20 14:37:16 -07004010 }
4011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004012 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004013 * Bind the items start-end from the list.
4014 *
4015 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004016 */
Winson Chung64359a52013-07-08 17:17:08 -07004017 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4018 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004019 Runnable r = new Runnable() {
4020 public void run() {
4021 bindItems(shortcuts, start, end, forceAnimateIcons);
4022 }
4023 };
4024 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004025 return;
4026 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004027
Winson Chungf0c6ae02012-03-21 16:10:31 -07004028 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004029 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4030 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004031 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004032 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004033 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004034 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004035 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004036
4037 // Short circuit if we are loading dock items for a configuration which has no dock
4038 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4039 mHotseat == null) {
4040 continue;
4041 }
4042
Joe Onorato9c1289c2009-08-17 11:03:03 -04004043 switch (item.itemType) {
4044 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4045 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004046 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004047 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004048
Winson Chung64359a52013-07-08 17:17:08 -07004049 /*
4050 * TODO: FIX collision case
4051 */
Winson Chungce376632013-07-11 16:12:41 -07004052 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4053 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4054 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004055 View v = cl.getChildAt(item.cellX, item.cellY);
4056 Object tag = v.getTag();
4057 String desc = "Collision while binding workspace item: " + item
4058 + ". Collides with " + tag;
4059 if (LauncherAppState.isDogfoodBuild()) {
4060 throw (new RuntimeException(desc));
4061 } else {
4062 Log.d(TAG, desc);
4063 }
Winson Chungce376632013-07-11 16:12:41 -07004064 }
Winson Chung64359a52013-07-08 17:17:08 -07004065 }
4066
Adam Cohendcd297f2013-06-18 13:13:40 -07004067 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4068 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004069 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004070 // Animate all the applications up now
4071 shortcut.setAlpha(0f);
4072 shortcut.setScaleX(0f);
4073 shortcut.setScaleY(0f);
4074 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004075 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004076 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004077 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004078 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004079 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004080 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004081 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004082 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4083 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004084 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004085 default:
4086 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004087 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004088 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004089
Winson Chung997a9232013-07-24 15:33:46 -07004090 if (animateIcons) {
4091 // Animate to the correct page
4092 if (newShortcutsScreenId > -1) {
4093 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004094 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004095 final Runnable startBounceAnimRunnable = new Runnable() {
4096 public void run() {
4097 anim.playTogether(bounceAnims);
4098 anim.start();
4099 }
4100 };
Winson Chung997a9232013-07-24 15:33:46 -07004101 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004102 // We post the animation slightly delayed to prevent slowdowns
4103 // when we are loading right after we return to launcher.
4104 mWorkspace.postDelayed(new Runnable() {
4105 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004106 if (mWorkspace != null) {
4107 mWorkspace.snapToPage(newScreenIndex);
4108 mWorkspace.postDelayed(startBounceAnimRunnable,
4109 NEW_APPS_ANIMATION_DELAY);
4110 }
Winson Chung94d67682013-09-25 16:29:40 -07004111 }
4112 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004113 } else {
4114 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004115 }
4116 }
Winson Chung64359a52013-07-08 17:17:08 -07004117 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004118 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004119 }
4120
Joe Onorato9c1289c2009-08-17 11:03:03 -04004121 /**
4122 * Implementation of the method from LauncherModel.Callbacks.
4123 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004124 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004125 Runnable r = new Runnable() {
4126 public void run() {
4127 bindFolders(folders);
4128 }
4129 };
4130 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004131 return;
4132 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004133 sFolders.clear();
4134 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004135 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004136
4137 /**
4138 * Add the views for a widget to the workspace.
4139 *
4140 * Implementation of the method from LauncherModel.Callbacks.
4141 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004142 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004143 Runnable r = new Runnable() {
4144 public void run() {
4145 bindAppWidget(item);
4146 }
4147 };
4148 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004149 return;
4150 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004151
Daniel Sandler843e8602010-06-07 14:59:01 -04004152 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4153 if (DEBUG_WIDGETS) {
4154 Log.d(TAG, "bindAppWidget: " + item);
4155 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004156 final Workspace workspace = mWorkspace;
4157
4158 final int appWidgetId = item.appWidgetId;
4159 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004160 if (DEBUG_WIDGETS) {
4161 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4162 }
4163
Joe Onorato9c1289c2009-08-17 11:03:03 -04004164 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4165
Joe Onorato9c1289c2009-08-17 11:03:03 -04004166 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004167 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004168
Adam Cohendcd297f2013-06-18 13:13:40 -07004169 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004170 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004171 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4172
Joe Onorato9c1289c2009-08-17 11:03:03 -04004173 workspace.requestLayout();
4174
Daniel Sandler843e8602010-06-07 14:59:01 -04004175 if (DEBUG_WIDGETS) {
4176 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4177 + (SystemClock.uptimeMillis()-start) + "ms");
4178 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004179 }
4180
Adam Cohen1462de32012-07-24 22:34:36 -07004181 public void onPageBoundSynchronously(int page) {
4182 mSynchronouslyBoundPages.add(page);
4183 }
4184
Joe Onorato9c1289c2009-08-17 11:03:03 -04004185 /**
4186 * Callback saying that there aren't any more items to bind.
4187 *
4188 * Implementation of the method from LauncherModel.Callbacks.
4189 */
Adam Cohene25af792013-06-06 23:08:25 -07004190 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004191 Runnable r = new Runnable() {
4192 public void run() {
4193 finishBindingItems(upgradePath);
4194 }
4195 };
4196 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004197 return;
4198 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004199 if (mSavedState != null) {
4200 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004201 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004202 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004203 mSavedState = null;
4204 }
4205
Adam Cohen1462de32012-07-24 22:34:36 -07004206 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004207
Winson Chungc51db6a2011-10-05 11:44:49 -07004208 // Update the market app icon as necessary (the other icons will be managed in response to
4209 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004210 if (!DISABLE_MARKET_BUTTON) {
4211 updateAppMarketIcon();
4212 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004213
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004214 setWorkspaceLoading(false);
Adam Cohendb364c32014-05-20 14:23:40 -07004215
4216 // If we received the result of any pending adds while the loader was running (e.g. the
4217 // widget configuration forced an orientation change), process them now.
4218 if (sPendingAddItem != null) {
4219 final long screenId = completeAdd(sPendingAddItem);
4220
4221 // TODO: this moves the user to the page where the pending item was added. Ideally,
4222 // the screen would be guaranteed to exist after bind, and the page would be set through
4223 // the workspace restore process.
4224 mWorkspace.post(new Runnable() {
4225 @Override
4226 public void run() {
4227 mWorkspace.snapToScreenId(screenId);
4228 }
4229 });
4230 sPendingAddItem = null;
4231 }
4232
Adam Cohene25af792013-06-06 23:08:25 -07004233 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004234 mWorkspace.getUniqueComponents(true, null);
4235 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004236 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004237 }
4238
Winson Chunga0b7e862013-09-05 16:03:15 -07004239 public boolean isAllAppsButtonRank(int rank) {
4240 if (mHotseat != null) {
4241 return mHotseat.isAllAppsButtonRank(rank);
4242 }
4243 return false;
4244 }
4245
Winson Chunga2413752012-04-03 14:22:34 -07004246 private boolean canRunNewAppsAnimation() {
4247 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4248 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4249 }
4250
Winson Chungc9168342013-06-26 14:54:55 -07004251 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4252 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4253 PropertyValuesHolder.ofFloat("alpha", 1f),
4254 PropertyValuesHolder.ofFloat("scaleX", 1f),
4255 PropertyValuesHolder.ofFloat("scaleY", 1f));
4256 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4257 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4258 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4259 return bounceAnim;
4260 }
4261
Adam Cohen27772732013-11-11 14:00:56 +00004262 public boolean useVerticalBarLayout() {
4263 return LauncherAppState.getInstance().getDynamicGrid().
4264 getDeviceProfile().isVerticalBarLayout();
4265 }
4266
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004267 protected Rect getSearchBarBounds() {
4268 return LauncherAppState.getInstance().getDynamicGrid().
4269 getDeviceProfile().getSearchBarBounds();
4270 }
4271
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004272 @Override
4273 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004274 boolean searchVisible = updateGlobalSearchIcon();
4275 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004276 if (mSearchDropTargetBar != null) {
4277 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4278 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004279 }
4280
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004281 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004282 * Add the icons for all apps.
4283 *
4284 * Implementation of the method from LauncherModel.Callbacks.
4285 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004286 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004287 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004288 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4289 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4290 getHotseat().addAllAppsFolder(mIconCache, apps,
4291 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4292 }
4293 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004294 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004295 if (mAppsCustomizeContent != null) {
4296 mAppsCustomizeContent.onPackagesUpdated(
4297 LauncherModel.getSortedWidgetsAndShortcuts(this));
4298 }
Winson Chungc58497e2013-09-03 17:48:37 -07004299 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004300 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004301 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004302 mAppsCustomizeContent.onPackagesUpdated(
4303 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004304 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004305 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004306 }
4307
4308 /**
4309 * A package was updated.
4310 *
4311 * Implementation of the method from LauncherModel.Callbacks.
4312 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004313 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004314 Runnable r = new Runnable() {
4315 public void run() {
4316 bindAppsUpdated(apps);
4317 }
4318 };
4319 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004320 return;
4321 }
4322
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004323 if (mWorkspace != null) {
4324 mWorkspace.updateShortcuts(apps);
4325 }
Winson Chungc58497e2013-09-03 17:48:37 -07004326
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004327 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004328 mAppsCustomizeContent != null) {
4329 mAppsCustomizeContent.updateApps(apps);
4330 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004331 }
4332
4333 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004334 * Update the state of a package, typically related to install state.
4335 *
4336 * Implementation of the method from LauncherModel.Callbacks.
4337 */
4338 public void updatePackageState(String pkgName, int state) {
4339 if (mWorkspace != null) {
4340 mWorkspace.updatePackageState(pkgName, state);
4341 }
4342 }
4343
4344 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004345 * A package was uninstalled. We take both the super set of packageNames
4346 * in addition to specific applications to remove, the reason being that
4347 * this can be called when a package is updated as well. In that scenario,
4348 * we only remove specific components from the workspace, where as
4349 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004350 *
4351 * Implementation of the method from LauncherModel.Callbacks.
4352 */
Winson Chung83892cc2013-05-01 16:53:33 -07004353 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004354 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004355 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004356 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004357 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004358 }
Winson Chungd64d1762013-08-20 14:37:16 -07004359 };
4360 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004361 return;
4362 }
4363
Winson Chungdf95eb12013-10-16 14:57:07 -07004364 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004365 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004366 }
4367 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004368 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004369 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004370
Winson Chunga1820962011-10-03 16:31:06 -07004371 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004372 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004373
Winson Chungdf95eb12013-10-16 14:57:07 -07004374 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004375 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004376 mAppsCustomizeContent != null) {
4377 mAppsCustomizeContent.removeApps(appInfos);
4378 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004379 }
Joe Onoratobe386092009-11-17 17:32:16 -08004380
4381 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004382 * A number of packages were updated.
4383 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004384 private ArrayList<Object> mWidgetsAndShortcuts;
4385 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004386 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004387 bindPackagesUpdated(mWidgetsAndShortcuts);
4388 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004389 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004390 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004391 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4392 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4393 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004394 return;
4395 }
4396
Winson Chung64359a52013-07-08 17:17:08 -07004397 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004398 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004399 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004400 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004401 }
4402
Winson Chung400438b2011-01-16 17:53:48 -08004403 private int mapConfigurationOriActivityInfoOri(int configOri) {
4404 final Display d = getWindowManager().getDefaultDisplay();
4405 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4406 switch (d.getRotation()) {
4407 case Surface.ROTATION_0:
4408 case Surface.ROTATION_180:
4409 // We are currently in the same basic orientation as the natural orientation
4410 naturalOri = configOri;
4411 break;
4412 case Surface.ROTATION_90:
4413 case Surface.ROTATION_270:
4414 // We are currently in the other basic orientation to the natural orientation
4415 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4416 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4417 break;
4418 }
4419
4420 int[] oriMap = {
4421 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4422 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4423 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4424 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4425 };
4426 // Since the map starts at portrait, we need to offset if this device's natural orientation
4427 // is landscape.
4428 int indexOffset = 0;
4429 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4430 indexOffset = 1;
4431 }
4432 return oriMap[(d.getRotation() + indexOffset) % 4];
4433 }
Adam Cohen446e9402011-09-15 18:21:21 -07004434
Winson Chung4b919f82012-05-01 10:44:08 -07004435 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004436 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004437 getResources().getBoolean(R.bool.allow_rotation);
4438 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004439 }
Winson Chung4b919f82012-05-01 10:44:08 -07004440 public void lockScreenOrientation() {
4441 if (isRotationEnabled()) {
4442 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4443 .getConfiguration().orientation));
4444 }
4445 }
4446 public void unlockScreenOrientation(boolean immediate) {
4447 if (isRotationEnabled()) {
4448 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004449 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004450 } else {
4451 mHandler.postDelayed(new Runnable() {
4452 public void run() {
4453 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4454 }
4455 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004456 }
Winson Chung4b919f82012-05-01 10:44:08 -07004457 }
Winson Chung400438b2011-01-16 17:53:48 -08004458 }
4459
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004460 /**
4461 * Called when the SearchBar hint should be changed.
4462 *
4463 * @param hint the hint to be displayed in the search bar.
4464 */
4465 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004466 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004467 }
4468
Winson Chunge43a1e72014-01-15 10:33:02 -08004469 protected boolean isLauncherPreinstalled() {
4470 PackageManager pm = getPackageManager();
4471 try {
4472 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4473 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4474 return true;
4475 } else {
4476 return false;
4477 }
4478 } catch (NameNotFoundException e) {
4479 e.printStackTrace();
4480 return false;
4481 }
4482 }
4483
Adam Cohen5eed5d82014-05-19 13:12:13 -07004484 protected boolean shouldClingFocusHotseatApp() {
4485 return false;
4486 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004487 protected String getFirstRunClingSearchBarHint() {
4488 return "";
4489 }
4490 protected String getFirstRunCustomContentHint() {
4491 return "";
4492 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004493 protected int getFirstRunFocusedHotseatAppDrawableId() {
4494 return -1;
4495 }
4496 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4497 return null;
4498 }
4499 protected int getFirstRunFocusedHotseatAppRank() {
4500 return -1;
4501 }
4502 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4503 return "";
4504 }
4505 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4506 return "";
4507 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004508
Winson Chungaf40f202013-09-18 18:26:31 -07004509 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004510 mLauncherClings.dismissFirstRunCling(v);
4511 }
4512 public void dismissMigrationClingCopyApps(View v) {
4513 mLauncherClings.dismissMigrationClingCopyApps(v);
4514 }
4515 public void dismissMigrationClingUseDefault(View v) {
4516 mLauncherClings.dismissMigrationClingUseDefault(v);
4517 }
4518 public void dismissMigrationWorkspaceCling(View v) {
4519 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004520 }
Winson Chung82f55532011-08-09 14:14:23 -07004521 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004522 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004523 }
4524 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004525 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004526 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004527 public void markFolderClingDismissedIfNecessary() {
4528 mLauncherClings.markFolderClingDismissedIfNecessary();
4529 }
Adam Cohen432609a2014-03-13 17:03:22 -07004530
4531 /**
4532 * To be overridden by subclasses to indicate that there is an activity to launch
4533 * before showing the standard launcher experience.
4534 */
4535 protected boolean hasFirstRunActivity() {
4536 return false;
4537 }
4538
4539 /**
4540 * To be overridden by subclasses to launch any first run activity
4541 */
4542 protected Intent getFirstRunActivity() {
4543 return null;
4544 }
4545
Winson Chunga6945242014-01-08 14:04:34 -08004546 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004547 return !ActivityManager.isRunningInTestHarness() &&
4548 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004549 }
4550
Adam Cohen4a9423d2014-03-28 14:22:31 -07004551 protected boolean hasRunFirstRunActivity() {
4552 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4553 }
4554
Adam Cohen432609a2014-03-13 17:03:22 -07004555 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004556 if (shouldRunFirstRunActivity() &&
4557 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004558 Intent firstRunIntent = getFirstRunActivity();
4559 if (firstRunIntent != null) {
4560 startActivity(firstRunIntent);
4561 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004562 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004563 }
4564 }
Adam Cohen432609a2014-03-13 17:03:22 -07004565 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004566 }
4567
4568 private void markFirstRunActivityShown() {
4569 SharedPreferences.Editor editor = mSharedPrefs.edit();
4570 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4571 editor.apply();
4572 }
4573
Adam Cohen432609a2014-03-13 17:03:22 -07004574 /**
4575 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4576 * screen that must be displayed and dismissed.
4577 */
4578 protected boolean hasDismissableIntroScreen() {
4579 return false;
4580 }
4581
4582 /**
4583 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4584 */
4585 protected View getIntroScreen() {
4586 return null;
4587 }
4588
4589 /**
4590 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4591 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4592 */
4593 private boolean shouldShowIntroScreen() {
4594 return hasDismissableIntroScreen() &&
4595 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4596 }
4597
4598 protected void showIntroScreen() {
4599 View introScreen = getIntroScreen();
4600 changeWallpaperVisiblity(false);
4601 if (introScreen != null) {
4602 mDragLayer.showOverlayView(introScreen);
4603 }
4604 }
4605
4606 public void dismissIntroScreen() {
4607 markIntroScreenDismissed();
4608 if (showFirstRunActivity()) {
4609 // We delay hiding the intro view until the first run activity is showing. This
4610 // avoids a blip.
4611 mWorkspace.postDelayed(new Runnable() {
4612 @Override
4613 public void run() {
4614 mDragLayer.dismissOverlayView();
4615 }
4616 }, ACTIVITY_START_DELAY);
4617 } else {
4618 mDragLayer.dismissOverlayView();
4619 }
4620 changeWallpaperVisiblity(true);
4621 }
4622
4623 private void markIntroScreenDismissed() {
4624 SharedPreferences.Editor editor = mSharedPrefs.edit();
4625 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4626 editor.apply();
4627 }
4628
Winson Chunga6945242014-01-08 14:04:34 -08004629 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004630 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4631 if (mHotseat != null) mHotseat.setAlpha(1f);
4632 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4633 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004634 }
4635
4636 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004637 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4638 if (mHotseat != null) mHotseat.setAlpha(0f);
4639 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4640 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004641 }
4642
Mathew Inwood72fbec12013-11-19 15:45:07 +00004643 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004644 // Called from search suggestion, not supported in other profiles.
4645 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4646 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4647 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4648 myUser);
4649 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004650 return null;
4651 }
Kenny Guyed131872014-04-30 03:02:21 +01004652 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004653 }
4654
4655 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4656 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004657 // Called from search suggestion, not supported in other profiles.
4658 return createShortcutDragInfo(shortcutIntent, caption, icon,
4659 UserHandleCompat.myUserHandle());
4660 }
4661
4662 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4663 Bitmap icon, UserHandleCompat user) {
4664 return new ShortcutInfo(shortcutIntent, caption, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004665 }
4666
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004667 protected void moveWorkspaceToDefaultScreen() {
4668 mWorkspace.moveToDefaultScreen(false);
4669 }
4670
Mathew Inwood72fbec12013-11-19 15:45:07 +00004671 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4672 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004673 mWorkspace.onExternalDragStartedWithItem(dragView);
4674 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004675 }
4676
Anjali Koppalf5d29132014-02-28 13:33:27 -08004677 @Override
4678 public void onPageSwitch(View newPage, int newPageIndex) {
4679 }
4680
Winson Chung80baf5a2010-08-09 16:03:15 -07004681 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004682 * Prints out out state for debugging.
4683 */
4684 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004685 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004686 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004687 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4688 Log.d(TAG, "mRestoring=" + mRestoring);
4689 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4690 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004691 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004692 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004693
Winson Chung785d2eb2011-04-14 16:08:02 -07004694 if (mAppsCustomizeContent != null) {
4695 mAppsCustomizeContent.dumpState();
4696 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004697 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004698 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004699
4700 @Override
4701 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4702 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004703 synchronized (sDumpLogs) {
4704 writer.println(" ");
4705 writer.println("Debug logs: ");
4706 for (int i = 0; i < sDumpLogs.size(); i++) {
4707 writer.println(" " + sDumpLogs.get(i));
4708 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004709 }
4710 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004711
4712 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004713 if (DEBUG_DUMP_LOG) {
4714 synchronized (sDumpLogs) {
4715 Log.d(TAG, "");
4716 Log.d(TAG, "*********************");
4717 Log.d(TAG, "Launcher debug logs: ");
4718 for (int i = 0; i < sDumpLogs.size(); i++) {
4719 Log.d(TAG, " " + sDumpLogs.get(i));
4720 }
4721 Log.d(TAG, "*********************");
4722 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004723 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004724 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004725 }
4726
4727 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004728 addDumpLog(tag, log, null, debugLog);
4729 }
4730
4731 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004732 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004733 if (e != null) {
4734 Log.d(tag, log, e);
4735 } else {
4736 Log.d(tag, log);
4737 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004738 }
Winson Chungede41292013-09-19 16:27:36 -07004739 if (DEBUG_DUMP_LOG) {
4740 sDateStamp.setTime(System.currentTimeMillis());
4741 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004742 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4743 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004744 }
Winson Chungede41292013-09-19 16:27:36 -07004745 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004746 }
4747
Winson Chungede41292013-09-19 16:27:36 -07004748 public void dumpLogsToLocalData() {
4749 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004750 new AsyncTask<Void, Void, Void>() {
4751 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004752 boolean success = false;
4753 sDateStamp.setTime(sRunStart);
4754 String FILENAME = sDateStamp.getMonth() + "-"
4755 + sDateStamp.getDay() + "_"
4756 + sDateStamp.getHours() + "-"
4757 + sDateStamp.getMinutes() + "_"
4758 + sDateStamp.getSeconds() + ".txt";
4759
4760 FileOutputStream fos = null;
4761 File outFile = null;
4762 try {
4763 outFile = new File(getFilesDir(), FILENAME);
4764 outFile.createNewFile();
4765 fos = new FileOutputStream(outFile);
4766 } catch (Exception e) {
4767 e.printStackTrace();
4768 }
4769 if (fos != null) {
4770 PrintWriter writer = new PrintWriter(fos);
4771
4772 writer.println(" ");
4773 writer.println("Debug logs: ");
4774 synchronized (sDumpLogs) {
4775 for (int i = 0; i < sDumpLogs.size(); i++) {
4776 writer.println(" " + sDumpLogs.get(i));
4777 }
4778 }
4779 writer.close();
4780 }
4781 try {
4782 if (fos != null) {
4783 fos.close();
4784 success = true;
4785 }
4786 } catch (IOException e) {
4787 e.printStackTrace();
4788 }
Michael Jurka43467462013-11-14 12:03:58 +01004789 return null;
Winson Chungede41292013-09-19 16:27:36 -07004790 }
Michael Jurka43467462013-11-14 12:03:58 +01004791 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004792 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004793 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004794}
Michael Jurka2763be32011-02-24 11:19:57 -08004795
Michael Jurkaabded662011-03-04 12:06:57 -08004796interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004797 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004798 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004799 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004800 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004801 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004802}
Dan Sandlerd5024042014-01-09 15:01:33 -05004803
4804interface DebugIntents {
4805 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4806 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004807}