blob: dc5674c253c65d52e8e40caa413ed2b78dd578be [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
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800363 private static ArrayList<PendingAddArguments> sPendingAddList
364 = new ArrayList<PendingAddArguments>();
365
Michael Jurka7267fa52013-09-26 15:29:57 -0700366 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800367
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800368 private static class PendingAddArguments {
369 int requestCode;
370 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700371 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700372 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800373 int cellX;
374 int cellY;
375 }
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 */
739 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700740 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800741 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 case REQUEST_PICK_SHORTCUT:
743 processShortcut(args.intent);
744 break;
745 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700746 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700747 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700748 result = true;
749 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800750 case REQUEST_CREATE_APPWIDGET:
751 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700752 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700753 result = true;
754 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800755 }
Michael Jurka27614d22012-04-02 06:40:22 -0700756 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
757 // if you turned the screen off and then back while in All Apps, Launcher would not
758 // return to the workspace. Clearing mAddInfo.container here fixes this issue
759 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700760 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800761 }
762
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800763 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700764 protected void onActivityResult(
765 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700766 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700767 setWaitingForResult(false);
Adam Cohen4637b5a2013-11-04 18:21:24 -0800768 int pendingAddWidgetId = mPendingAddWidgetId;
769 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700770
Adam Cohenad4e15c2013-10-17 16:21:35 -0700771 Runnable exitSpringLoaded = new Runnable() {
772 @Override
773 public void run() {
774 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
775 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
776 }
777 };
778
Michael Jurka8b805b12012-04-18 14:23:14 -0700779 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
782 if (resultCode == RESULT_CANCELED) {
783 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700784 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700785 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700786 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700787 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
788 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700789 }
790 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200791 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
792 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
793 mWorkspace.exitOverviewMode(false);
794 }
795 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700796 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200797
Adam Cohened66b2b2012-01-23 17:28:51 -0800798 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
799 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700800
Adam Cohened66b2b2012-01-23 17:28:51 -0800801 // We have special handling for widgets
802 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800803 final int appWidgetId;
804 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
805 : -1;
806 if (widgetId < 0) {
807 appWidgetId = pendingAddWidgetId;
808 } else {
809 appWidgetId = widgetId;
810 }
811
Adam Cohenad4e15c2013-10-17 16:21:35 -0700812 final int result;
813 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800814 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700815 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
816 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700817 result = RESULT_CANCELED;
818 completeTwoStageWidgetDrop(result, appWidgetId);
819 onComplete = new Runnable() {
820 @Override
821 public void run() {
822 exitSpringLoadedDragModeDelayed(false, 0, null);
823 }
824 };
Winson Chung5aaab772012-04-27 15:24:02 -0700825 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700826 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700827 final CellLayout dropLayout =
828 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
829 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700830 onComplete = new Runnable() {
831 @Override
832 public void run() {
833 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700834 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700835 }
836 };
Winson Chung5aaab772012-04-27 15:24:02 -0700837 }
Adam Cohen689ff162014-05-08 17:27:56 -0700838 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700839 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800840 return;
841 }
842
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 // The pattern used here is that a user PICKs a specific application,
844 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700845
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
847 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700848 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800849 final PendingAddArguments args = new PendingAddArguments();
850 args.requestCode = requestCode;
851 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700852 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700853 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700854 args.cellX = mPendingAddInfo.cellX;
855 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800856 if (isWorkspaceLocked()) {
857 sPendingAddList.add(args);
858 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700859 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800860 }
Adam Cohen689ff162014-05-08 17:27:56 -0700861 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700862 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700863 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700864 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700865 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800867 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800868 }
869
870 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700871 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700872 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800873 Runnable onCompleteRunnable = null;
874 int animationType = 0;
875
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700876 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800877 if (resultCode == RESULT_OK) {
878 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
879 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700880 mPendingAddWidgetInfo);
881 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800882 onCompleteRunnable = new Runnable() {
883 @Override
884 public void run() {
885 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700886 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700887 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
888 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800889 }
890 };
891 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800892 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800893 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800894 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700895 if (mDragLayer.getAnimatedView() != null) {
896 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
897 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
898 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700899 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700900 // The animated view may be null in the case of a rotation during widget configuration
901 onCompleteRunnable.run();
902 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800903 }
904
905 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700906 protected void onStop() {
907 super.onStop();
908 FirstFrameAnimatorHelper.setIsVisible(false);
909 }
910
911 @Override
912 protected void onStart() {
913 super.onStart();
914 FirstFrameAnimatorHelper.setIsVisible(true);
915 }
916
917 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800918 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200919 long startTime = 0;
920 if (DEBUG_RESUME_TIME) {
921 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400922 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200923 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800924 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700925
Winson Chung4a2afa32012-07-19 14:53:05 -0700926 // Restore the previous launcher state
927 if (mOnResumeState == State.WORKSPACE) {
928 showWorkspace(false);
929 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800930 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700931 }
932 mOnResumeState = State.NONE;
933
Craig Mautner360310b2012-10-26 15:13:08 -0700934 // Background was set to gradient in onPause(), restore to black if in all apps.
935 setWorkspaceBackground(mState == State.WORKSPACE);
936
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800937 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700938 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700939 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700940 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500941 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400942 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700943 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800944 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700945 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200946 // We might have postponed some bind calls until onResume (see waitUntilResume) --
947 // execute them here
948 long startTimeCallbacks = 0;
949 if (DEBUG_RESUME_TIME) {
950 startTimeCallbacks = System.currentTimeMillis();
951 }
952
953 if (mAppsCustomizeContent != null) {
954 mAppsCustomizeContent.setBulkBind(true);
955 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700956 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
957 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200958 }
959 if (mAppsCustomizeContent != null) {
960 mAppsCustomizeContent.setBulkBind(false);
961 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700962 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200963 if (DEBUG_RESUME_TIME) {
964 Log.d(TAG, "Time spent processing callbacks in onResume: " +
965 (System.currentTimeMillis() - startTimeCallbacks));
966 }
Michael Jurka447bf842013-05-15 14:52:15 +0200967 }
Michael Jurka54554252013-08-01 12:52:23 +0200968 if (mOnResumeCallbacks.size() > 0) {
969 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
970 mOnResumeCallbacks.get(i).run();
971 }
972 mOnResumeCallbacks.clear();
973 }
Winson Chunge4e50662012-01-23 14:45:13 -0800974
975 // Reset the pressed state of icons that were locked in the press state while activities
976 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800977 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800978 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800979 mWaitingForResume.setStayPressed(false);
980 }
Winson Chunge4e50662012-01-23 14:45:13 -0800981 if (mAppsCustomizeContent != null) {
982 // Resets the previous all apps icon press state
983 mAppsCustomizeContent.resetDrawableState();
984 }
Winson Chung82963d52013-10-09 11:20:57 -0700985
Adam Cohen06dff352012-06-01 17:17:08 -0700986 // It is possible that widgets can receive updates while launcher is not in the foreground.
987 // Consequently, the widgets will be inflated in the orientation of the foreground activity
988 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
989 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700990 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700991
Winson Chung780fe592013-09-26 14:48:44 -0700992 // Process any items that were added while Launcher was away.
993 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
994
Winson Chung5841efa2013-09-30 18:06:44 -0700995 // Update the voice search button proxy
996 updateVoiceButtonProxyVisible(false);
997
Adam Cohenf9426d52012-06-04 17:26:21 -0700998 // Again, as with the above scenario, it's possible that one or more of the global icons
999 // were updated in the wrong orientation.
1000 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001001 if (DEBUG_RESUME_TIME) {
1002 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1003 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001004
1005 if (mWorkspace.getCustomContentCallbacks() != null) {
1006 // If we are resuming and the custom content is the current page, we call onShow().
1007 // It is also poassible that onShow will instead be called slightly after first layout
1008 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1009 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001010 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001011 }
1012 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001013 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001014 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001015 }
1016
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001017 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001018 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001019 // Ensure that items added to Launcher are queued until Launcher returns
1020 InstallShortcutReceiver.enableInstallQueue();
1021
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001022 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001023 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001024 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001025 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001026
1027 // We call onHide() aggressively. The custom content callbacks should be able to
1028 // debounce excess onHide calls.
1029 if (mWorkspace.getCustomContentCallbacks() != null) {
1030 mWorkspace.getCustomContentCallbacks().onHide();
1031 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001032 }
Romain Guycbb89e42009-06-08 15:52:54 -07001033
Adam Cohenbffe7452013-07-22 18:21:45 -07001034 QSBScroller mQsbScroller = new QSBScroller() {
1035 int scrollY = 0;
1036
1037 @Override
1038 public void setScrollY(int scroll) {
1039 scrollY = scroll;
1040
1041 if (mWorkspace.isOnOrMovingToCustomContent()) {
1042 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001043 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001044 }
1045 }
1046 };
1047
1048 public void resetQSBScroll() {
1049 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001050 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001051 }
1052
1053 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001054 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1055 // by a onResume or by scrolling otherwise.
1056 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001057
1058 // Custom content is completely hidden
1059 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001060
1061 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1062 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001063 }
1064
Jorim Jaggid017f882014-01-14 17:08:48 -08001065 protected boolean hasSettings() {
1066 return false;
1067 }
1068
Adam Cohenbffe7452013-07-22 18:21:45 -07001069 public interface QSBScroller {
1070 public void setScrollY(int scrollY);
1071 }
1072
Winson Chung98ca0f72013-07-29 12:58:51 -07001073 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001074 CustomContentCallbacks callbacks, String description) {
1075 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001076 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001077 }
1078
Adam Cohenedb40762013-07-18 16:45:45 -07001079 // The custom content needs to offset its content to account for the QSB
1080 public int getTopOffsetForCustomContent() {
1081 return mWorkspace.getPaddingTop();
1082 }
1083
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001084 @Override
1085 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001086 // Flag the loader to stop early before switching
1087 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001088 if (mAppsCustomizeContent != null) {
1089 mAppsCustomizeContent.surrender();
1090 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001091 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001092 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001093
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001094 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001095 @Override
1096 public void onWindowFocusChanged(boolean hasFocus) {
1097 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001098 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001099 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001100
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 private boolean acceptFilter() {
1102 final InputMethodManager inputManager = (InputMethodManager)
1103 getSystemService(Context.INPUT_METHOD_SERVICE);
1104 return !inputManager.isFullscreenMode();
1105 }
1106
1107 @Override
1108 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001109 final int uniChar = event.getUnicodeChar();
1110 final boolean handled = super.onKeyDown(keyCode, event);
1111 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1112 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1114 keyCode, event);
1115 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001116 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001117 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001118 // showSearchDialog()
1119 // If there are multiple keystrokes before the search dialog takes focus,
1120 // onSearchRequested() will be called for every keystroke,
1121 // but it is idempotent, so it's fine.
1122 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123 }
1124 }
1125
Joe Onorato8a9625e2010-01-28 15:55:35 -08001126 // Eat the long press event so the keyboard doesn't come up.
1127 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1128 return true;
1129 }
1130
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131 return handled;
1132 }
1133
Karl Rosaen138a0412009-04-23 19:00:21 -07001134 private String getTypedText() {
1135 return mDefaultKeySsb.toString();
1136 }
1137
1138 private void clearTypedText() {
1139 mDefaultKeySsb.clear();
1140 mDefaultKeySsb.clearSpans();
1141 Selection.setSelection(mDefaultKeySsb, 0);
1142 }
1143
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001144 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001145 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1146 * State
1147 */
1148 private static State intToState(int stateOrdinal) {
1149 State state = State.WORKSPACE;
1150 final State[] stateValues = State.values();
1151 for (int i = 0; i < stateValues.length; i++) {
1152 if (stateValues[i].ordinal() == stateOrdinal) {
1153 state = stateValues[i];
1154 break;
1155 }
1156 }
1157 return state;
1158 }
1159
1160 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 * Restores the previous state, if it exists.
1162 *
1163 * @param savedState The previous state.
1164 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001165 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001166 private void restoreState(Bundle savedState) {
1167 if (savedState == null) {
1168 return;
1169 }
1170
Michael Jurka883f55b2010-10-21 15:47:14 -07001171 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001172 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001173 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001174 }
1175
Adam Cohen21cd0022013-10-09 18:57:02 -07001176 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1177 PagedView.INVALID_RESTORE_PAGE);
1178 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001179 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 }
1181
Winson Chung3d503fb2011-07-13 17:25:49 -07001182 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001183 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001184
Winson Chung3d503fb2011-07-13 17:25:49 -07001185 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1186 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001187 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001188 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1189 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001190 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1191 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1192 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001193 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001194 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 mRestoring = true;
1196 }
1197
1198 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1199 if (renameFolder) {
1200 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001201 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 mRestoring = true;
1203 }
Winson Chunga12a2502010-12-20 14:41:35 -08001204
Winson Chung785d2eb2011-04-14 16:08:02 -07001205 // Restore the AppsCustomize tab
1206 if (mAppsCustomizeTabHost != null) {
1207 String curTab = savedState.getString("apps_customize_currentTab");
1208 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001209 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001210 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001211 mAppsCustomizeContent.loadAssociatedPages(
1212 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001213 }
1214
Winson Chung5afbf7b2011-07-25 11:53:08 -07001215 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1216 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001217 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001218 mItemIdToViewId = (HashMap<Integer, Integer>)
1219 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001220 }
1221
1222 /**
1223 * Finds all the views we need and configure them properly.
1224 */
1225 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001226 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001227
Craig Mautner360310b2012-10-26 15:13:08 -07001228 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001229 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1230 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001231 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001232 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001233
John Spurlock77e1f472013-09-11 10:09:51 -04001234 mLauncherView.setSystemUiVisibility(
1235 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001236 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237
Winson Chung4c98d922011-05-31 16:50:48 -07001238 // Setup the drag layer
1239 mDragLayer.setup(this, dragController);
1240
Winson Chung3d503fb2011-07-13 17:25:49 -07001241 // Setup the hotseat
1242 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1243 if (mHotseat != null) {
1244 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001245 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001246 }
1247
Jorim Jaggid017f882014-01-14 17:08:48 -08001248 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001249 View widgetButton = findViewById(R.id.widget_button);
1250 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001251 @Override
1252 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001253 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001254 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001255 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001256 }
1257 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001258 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1259
1260 View wallpaperButton = findViewById(R.id.wallpaper_button);
1261 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001262 @Override
1263 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001264 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001265 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001266 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001267 }
1268 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001269 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1270
1271 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001272 if (hasSettings()) {
1273 settingsButton.setOnClickListener(new OnClickListener() {
1274 @Override
1275 public void onClick(View arg0) {
1276 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001277 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001278 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001279 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001280 });
1281 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1282 } else {
1283 settingsButton.setVisibility(View.GONE);
1284 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1285 lp.gravity = Gravity.END | Gravity.TOP;
1286 widgetButton.requestLayout();
1287 }
1288
Adam Cohendbdff6b2013-09-18 19:09:15 -07001289 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001290
Winson Chung4c98d922011-05-31 16:50:48 -07001291 // Setup the workspace
1292 mWorkspace.setHapticFeedbackEnabled(false);
1293 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001294 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001295 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001296
Winson Chungf0ea4d32011-06-06 14:27:16 -07001297 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001298 mSearchDropTargetBar = (SearchDropTargetBar)
1299 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001300
Winson Chungf0ea4d32011-06-06 14:27:16 -07001301 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001302 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001303 mAppsCustomizeContent = (AppsCustomizePagedView)
1304 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1305 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001306
Winson Chung3d503fb2011-07-13 17:25:49 -07001307 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001308 dragController.setDragScoller(mWorkspace);
1309 dragController.setScrollView(mDragLayer);
1310 dragController.setMoveTarget(mWorkspace);
1311 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001312 if (mSearchDropTargetBar != null) {
1313 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001314 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001315
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001316 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001317 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001318 mWeightWatcher = new WeightWatcher(this);
1319 mWeightWatcher.setAlpha(0.5f);
1320 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001321 new FrameLayout.LayoutParams(
1322 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001323 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001324 Gravity.BOTTOM)
1325 );
Adam Cohen39a06042013-07-19 14:30:12 -07001326
1327 boolean show = shouldShowWeightWatcher();
1328 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001329 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330 }
1331
1332 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001333 * Sets the all apps button. This method is called from {@link Hotseat}.
1334 */
1335 public void setAllAppsButton(View allAppsButton) {
1336 mAllAppsButton = allAppsButton;
1337 }
1338
1339 public View getAllAppsButton() {
1340 return mAllAppsButton;
1341 }
1342
1343 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344 * Creates a view representing a shortcut.
1345 *
1346 * @param info The data structure describing the shortcut.
1347 *
1348 * @return A View inflated from R.layout.application.
1349 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001350 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001352 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 }
1354
1355 /**
1356 * Creates a view representing a shortcut inflated from the specified resource.
1357 *
1358 * @param layoutResId The id of the XML layout used to create the shortcut.
1359 * @param parent The group the shortcut belongs to.
1360 * @param info The data structure describing the shortcut.
1361 *
1362 * @return A View inflated from layoutResId.
1363 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001364 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001365 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1366 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368 return favorite;
1369 }
1370
1371 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001372 * Add a shortcut to the workspace.
1373 *
1374 * @param data The intent describing the shortcut.
1375 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001377 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001378 int cellY) {
1379 int[] cellXY = mTmpAddItemCellCoordinates;
1380 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001381 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001382
Michael Jurkad3ef3062010-11-23 16:23:58 -08001383 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001384
Adam Cohen558baaf2011-08-15 15:22:57 -07001385 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001386 if (info == null) {
1387 return;
1388 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001389 final View view = createShortcut(info);
1390
Adam Cohenfbba09b2011-07-18 21:43:05 -07001391 // First we check if we already know the exact location where we want to add this item.
1392 if (cellX >= 0 && cellY >= 0) {
1393 cellXY[0] = cellX;
1394 cellXY[1] = cellY;
1395 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001396
1397 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001398 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001399 true, null,null)) {
1400 return;
1401 }
1402 DragObject dragObject = new DragObject();
1403 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001404 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1405 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001406 return;
1407 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001408 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001409 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001410 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001411 foundCellSpan = (result != null);
1412 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001413 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001414 }
1415
1416 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001417 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001418 return;
1419 }
1420
Adam Cohendcd297f2013-06-18 13:13:40 -07001421 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422
1423 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001424 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001425 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001426 }
1427 }
1428
Adam Cohen2f093b62012-04-30 18:59:53 -07001429 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1430 int minHeight) {
1431 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001432 // We want to account for the extra amount of padding that we are adding to the widget
1433 // to ensure that it gets the full amount of space that it has requested
1434 int requiredWidth = minWidth + padding.left + padding.right;
1435 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001436 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001437 }
1438
Adam Cohen2f093b62012-04-30 18:59:53 -07001439 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1440 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001441 }
1442
Adam Cohen2f093b62012-04-30 18:59:53 -07001443 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1444 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001445 }
1446
Adam Cohen2f093b62012-04-30 18:59:53 -07001447 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1448 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001449 }
1450
Adam Cohen2f093b62012-04-30 18:59:53 -07001451 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1452 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001453 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001454 }
1455
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001456 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001457 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001459 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001460 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001462 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001463 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1464 if (appWidgetInfo == null) {
1465 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1466 }
Romain Guycbb89e42009-06-08 15:52:54 -07001467
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001468 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001469 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001470
Adam Cohen2f093b62012-04-30 18:59:53 -07001471 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1472 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001473
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001475 // We have saved the position to which the widget was dragged-- this really only matters
1476 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001477 int[] cellXY = mTmpAddItemCellCoordinates;
1478 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001479 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001480 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1482 cellXY[0] = mPendingAddInfo.cellX;
1483 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001484 spanXY[0] = mPendingAddInfo.spanX;
1485 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001486 foundCellSpan = true;
1487 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001488 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001489 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001490 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1491 spanXY[1], cellXY, finalSpan);
1492 spanXY[0] = finalSpan[0];
1493 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001494 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001495 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001496 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001497 }
1498
Michael Jurka0280c3b2010-09-17 15:00:07 -07001499 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001500 if (appWidgetId != -1) {
1501 // Deleting an app widget ID is a void call but writes to disk before returning
1502 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001503 new AsyncTask<Void, Void, Void>() {
1504 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001505 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001506 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001507 }
Michael Jurka43467462013-11-14 12:03:58 +01001508 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001509 }
Winson Chung93eef082012-03-23 15:59:27 -07001510 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001511 return;
1512 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001514 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001515 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1516 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001517 launcherInfo.spanX = spanXY[0];
1518 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001519 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1520 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001521
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001523 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524
1525 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001526 if (hostView == null) {
1527 // Perform actual inflation because we're live
1528 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1529 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1530 } else {
1531 // The AppWidgetHostView has already been inflated and instantiated
1532 launcherInfo.hostView = hostView;
1533 }
Romain Guycbb89e42009-06-08 15:52:54 -07001534
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001536 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001537 launcherInfo.notifyWidgetSizeChanged(this);
1538
Adam Cohendcd297f2013-06-18 13:13:40 -07001539 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001540 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001541
1542 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001544 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 }
Romain Guycbb89e42009-06-08 15:52:54 -07001546
Adam Cohended9f8d2010-11-03 13:25:16 -07001547 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1548 @Override
1549 public void onReceive(Context context, Intent intent) {
1550 final String action = intent.getAction();
1551 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1552 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001553 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001554 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001555
Winson Chungc100e8e2011-08-09 16:02:43 -07001556 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001557 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001558 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001559 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001560 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001561 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1562 mUserPresent = true;
1563 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001564 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1565 mModel.resetLoadedState(false, true);
1566 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1567 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1568 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1569 mModel.resetLoadedState(false, true);
1570 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1571 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1572 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001573 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1574 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1575 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001576 }
1577 }
1578 };
1579
1580 @Override
1581 public void onAttachedToWindow() {
1582 super.onAttachedToWindow();
1583
1584 // Listen for broadcasts related to user-presence
1585 final IntentFilter filter = new IntentFilter();
1586 filter.addAction(Intent.ACTION_SCREEN_OFF);
1587 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001588 // For handling managed profiles
1589 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1590 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001591 if (ENABLE_DEBUG_INTENTS) {
1592 filter.addAction(DebugIntents.DELETE_DATABASE);
1593 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1594 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001595 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001596 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001597 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001598 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001599 mVisible = true;
1600 }
1601
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001602 /**
1603 * Sets up transparent navigation and status bars in LMP.
1604 * This method is a no-op for other platform versions.
1605 */
Sandeep Siddhartha876b0032014-05-19 11:45:01 -07001606 @TargetApi(19)
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001607 private void setupTransparentSystemBarsForLmp() {
1608 // TODO(sansid): use the APIs directly when compiling against L sdk.
1609 // Currently we use reflection to access the flags and the API to set the transparency
1610 // on the System bars.
1611 if (Utilities.isLmp()) {
1612 try {
1613 getWindow().getAttributes().systemUiVisibility |=
1614 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1615 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1616 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Sandeep Siddhartha876b0032014-05-19 11:45:01 -07001617 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1618 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -07001619 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1620 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1621 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1622
1623 Method setStatusBarColorMethod =
1624 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1625 Method setNavigationBarColorMethod =
1626 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1627 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1628 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1629 } catch (NoSuchFieldException e) {
1630 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1631 } catch (NoSuchMethodException ex) {
1632 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1633 } catch (IllegalAccessException e) {
1634 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1635 } catch (IllegalArgumentException e) {
1636 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1637 } catch (InvocationTargetException e) {
1638 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1639 } finally {}
1640 }
1641 }
1642
Adam Cohended9f8d2010-11-03 13:25:16 -07001643 @Override
1644 public void onDetachedFromWindow() {
1645 super.onDetachedFromWindow();
1646 mVisible = false;
1647
Adam Cohend113e0c2010-11-11 10:48:05 -08001648 if (mAttached) {
1649 unregisterReceiver(mReceiver);
1650 mAttached = false;
1651 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001652 updateRunning();
1653 }
1654
1655 public void onWindowVisibilityChanged(int visibility) {
1656 mVisible = visibility == View.VISIBLE;
1657 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001658 // The following code used to be in onResume, but it turns out onResume is called when
1659 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1660 // is a more appropriate event to handle
1661 if (mVisible) {
1662 mAppsCustomizeTabHost.onWindowVisible();
1663 if (!mWorkspaceLoading) {
1664 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001665 // We want to let Launcher draw itself at least once before we force it to build
1666 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001667 // apps is nice and speedy.
1668 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001669 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001670 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001671 if (mStarted) return;
1672 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001673 // We delay the layer building a bit in order to give
1674 // other message processing a time to run. In particular
1675 // this avoids a delay in hiding the IME if it was
1676 // currently shown, because doing that may involve
1677 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001678 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001679 final ViewTreeObserver.OnDrawListener listener = this;
1680 mWorkspace.post(new Runnable() {
1681 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001682 if (mWorkspace != null &&
1683 mWorkspace.getViewTreeObserver() != null) {
1684 mWorkspace.getViewTreeObserver().
1685 removeOnDrawListener(listener);
1686 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001687 }
1688 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001689 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001690 }
1691 });
1692 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001693 // When Launcher comes back to foreground, a different Activity might be responsible for
1694 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001695 if (!DISABLE_MARKET_BUTTON) {
1696 updateAppMarketIcon();
1697 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001698 clearTypedText();
1699 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001700 }
1701
1702 private void sendAdvanceMessage(long delay) {
1703 mHandler.removeMessages(ADVANCE_MSG);
1704 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1705 mHandler.sendMessageDelayed(msg, delay);
1706 mAutoAdvanceSentTime = System.currentTimeMillis();
1707 }
1708
1709 private void updateRunning() {
1710 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1711 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1712 mAutoAdvanceRunning = autoAdvanceRunning;
1713 if (autoAdvanceRunning) {
1714 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1715 sendAdvanceMessage(delay);
1716 } else {
1717 if (!mWidgetsToAdvance.isEmpty()) {
1718 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1719 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1720 }
1721 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001722 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001723 }
1724 }
1725 }
1726
1727 private final Handler mHandler = new Handler() {
1728 @Override
1729 public void handleMessage(Message msg) {
1730 if (msg.what == ADVANCE_MSG) {
1731 int i = 0;
1732 for (View key: mWidgetsToAdvance.keySet()) {
1733 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1734 final int delay = mAdvanceStagger * i;
1735 if (v instanceof Advanceable) {
1736 postDelayed(new Runnable() {
1737 public void run() {
1738 ((Advanceable) v).advance();
1739 }
1740 }, delay);
1741 }
1742 i++;
1743 }
1744 sendAdvanceMessage(mAdvanceInterval);
1745 }
1746 }
1747 };
1748
1749 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001750 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001751 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1752 if (v instanceof Advanceable) {
1753 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001754 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001755 updateRunning();
1756 }
1757 }
1758
1759 void removeWidgetToAutoAdvance(View hostView) {
1760 if (mWidgetsToAdvance.containsKey(hostView)) {
1761 mWidgetsToAdvance.remove(hostView);
1762 updateRunning();
1763 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001764 }
1765
Joe Onorato9c1289c2009-08-17 11:03:03 -04001766 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001768 launcherInfo.hostView = null;
1769 }
1770
Winson Chung93eef082012-03-23 15:59:27 -07001771 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1772 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1773 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001774 }
1775
Winson Chunga6945242014-01-08 14:04:34 -08001776 public DragLayer getDragLayer() {
1777 return mDragLayer;
1778 }
1779
1780 public Workspace getWorkspace() {
1781 return mWorkspace;
1782 }
1783
1784 public Hotseat getHotseat() {
1785 return mHotseat;
1786 }
1787
Jorim Jaggid017f882014-01-14 17:08:48 -08001788 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001789 return mOverviewPanel;
1790 }
1791
1792 public SearchDropTargetBar getSearchBar() {
1793 return mSearchDropTargetBar;
1794 }
1795
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001796 public LauncherAppWidgetHost getAppWidgetHost() {
1797 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001798 }
Romain Guycbb89e42009-06-08 15:52:54 -07001799
Winson Chunga9abd0e2010-10-27 17:18:37 -07001800 public LauncherModel getModel() {
1801 return mModel;
1802 }
1803
Winson Chunga6945242014-01-08 14:04:34 -08001804 public LauncherClings getLauncherClings() {
1805 return mLauncherClings;
1806 }
1807
1808 protected SharedPreferences getSharedPrefs() {
1809 return mSharedPrefs;
1810 }
1811
Bjorn Bringertc459e522013-06-07 19:36:01 +01001812 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001813 getWindow().closeAllPanels();
1814
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001815 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001816 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001817 }
1818
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001819 @Override
1820 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001821 long startTime = 0;
1822 if (DEBUG_RESUME_TIME) {
1823 startTime = System.currentTimeMillis();
1824 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 super.onNewIntent(intent);
1826
1827 // Close the menu
1828 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001829 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001830 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001831
Adam Cohened307df2013-10-02 09:37:31 -07001832 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1833 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1834 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001835
Adam Cohen6fecd412013-10-02 17:41:50 -07001836 if (mWorkspace == null) {
1837 // Can be cases where mWorkspace is null, this prevents a NPE
1838 return;
1839 }
1840 Folder openFolder = mWorkspace.getOpenFolder();
1841 // In all these cases, only animate if we're already on home
1842 mWorkspace.exitWidgetResizeMode();
1843 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001844 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001845 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001846 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001847
Adam Cohen6fecd412013-10-02 17:41:50 -07001848 closeFolder();
1849 exitSpringLoadedDragMode();
1850
1851 // If we are already on home, then just animate back to the workspace,
1852 // otherwise, just wait until onResume to set the state back to Workspace
1853 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001854 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001855 } else {
1856 mOnResumeState = State.WORKSPACE;
1857 }
1858
1859 final View v = getWindow().peekDecorView();
1860 if (v != null && v.getWindowToken() != null) {
1861 InputMethodManager imm = (InputMethodManager)getSystemService(
1862 INPUT_METHOD_SERVICE);
1863 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1864 }
1865
1866 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001867 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001868 mAppsCustomizeTabHost.reset();
1869 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001870
1871 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 }
Adam Cohened307df2013-10-02 09:37:31 -07001873
Michael Jurka447bf842013-05-15 14:52:15 +02001874 if (DEBUG_RESUME_TIME) {
1875 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 }
1878
Adam Coppa120b8e2013-11-12 16:26:04 +00001879 /**
1880 * Override point for subclasses to prevent movement to the default screen when the home
1881 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1882 */
1883 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1884 return true;
1885 }
1886
1887 /**
1888 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1889 */
1890 protected void onHomeIntent() {
1891 // Do nothing
1892 }
1893
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001894 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001895 public void onRestoreInstanceState(Bundle state) {
1896 super.onRestoreInstanceState(state);
1897 for (int page: mSynchronouslyBoundPages) {
1898 mWorkspace.restoreInstanceStateForChild(page);
1899 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001900 }
1901
1902 @Override
1903 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001904 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001905 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1906 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001907 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001908 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909
Michael Jurka883f55b2010-10-21 15:47:14 -07001910 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001911 // We close any open folder since it will not be re-opened, and we need to make sure
1912 // this state is reflected.
1913 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001914
Adam Cohendcd297f2013-06-18 13:13:40 -07001915 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001916 mWaitingForResult) {
1917 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001918 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001919 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1920 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001921 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1922 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1923 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001924 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 }
1926
1927 if (mFolderInfo != null && mWaitingForResult) {
1928 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1929 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1930 }
Michael Jurka946ad472010-07-09 18:05:18 -07001931
Winson Chung785d2eb2011-04-14 16:08:02 -07001932 // Save the current AppsCustomize tab
1933 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001934 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1935 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001936 if (currentTabTag != null) {
1937 outState.putString("apps_customize_currentTab", currentTabTag);
1938 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001939 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1940 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001941 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001942 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 }
1944
1945 @Override
1946 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001948
Winson Chunge7a03942011-08-05 15:05:12 -07001949 // Remove all pending runnables
1950 mHandler.removeMessages(ADVANCE_MSG);
1951 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001952 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001953
Winson Chungcd2b0142011-06-08 16:02:26 -07001954 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001955 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001956 mModel.stopLoader();
1957 app.setLauncher(null);
1958
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001959 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001960 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001962 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001963 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001964 mAppWidgetHost = null;
1965
1966 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967
1968 TextKeyListener.getInstance().release();
1969
Winson Chung81b52252012-08-27 15:34:29 -07001970 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1971 // to prevent leaking Launcher activities on orientation change.
1972 if (mModel != null) {
1973 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1974 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001975
1976 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001977 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001978
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001979 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001980 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001981 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001982 mWorkspace = null;
1983 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001984
Michael Jurka2ecf9952012-06-18 12:52:28 -07001985 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 }
1987
Adam Cohena9cf38f2011-05-02 15:36:58 -07001988 public DragController getDragController() {
1989 return mDragController;
1990 }
1991
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001992 @Override
1993 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001994 if (requestCode >= 0) {
1995 setWaitingForResult(true);
1996 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 super.startActivityForResult(intent, requestCode);
1998 }
1999
Winson Chung70d72102011-08-12 11:24:35 -07002000 /**
2001 * Indicates that we want global search for this activity by setting the globalSearch
2002 * argument for {@link #startSearch} to true.
2003 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002005 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002007
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002008 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002009
Karl Rosaen138a0412009-04-23 19:00:21 -07002010 if (initialQuery == null) {
2011 // Use any text typed in the launcher as the initial query
2012 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002013 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 if (appSearchData == null) {
2015 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002016 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 }
Winson Chungadf0c182012-08-23 14:59:07 -07002018 Rect sourceBounds = new Rect();
2019 if (mSearchDropTargetBar != null) {
2020 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2021 }
Romain Guycbb89e42009-06-08 15:52:54 -07002022
Bjorn Bringertc459e522013-06-07 19:36:01 +01002023 startSearch(initialQuery, selectInitialQuery,
2024 appSearchData, sourceBounds);
2025 }
2026
2027 public void startSearch(String initialQuery,
2028 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002029 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002030 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002031 }
2032
2033 /**
2034 * Starts the global search activity. This code is a copied from SearchManager
2035 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002036 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002037 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002038 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002039 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2040 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2041 if (globalSearchActivity == null) {
2042 Log.w(TAG, "No global search activity found.");
2043 return;
2044 }
2045 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2046 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2047 intent.setComponent(globalSearchActivity);
2048 // Make sure that we have a Bundle to put source in
2049 if (appSearchData == null) {
2050 appSearchData = new Bundle();
2051 } else {
2052 appSearchData = new Bundle(appSearchData);
2053 }
2054 // Set source to package name of app that starts global search, if not set already.
2055 if (!appSearchData.containsKey("source")) {
2056 appSearchData.putString("source", getPackageName());
2057 }
2058 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2059 if (!TextUtils.isEmpty(initialQuery)) {
2060 intent.putExtra(SearchManager.QUERY, initialQuery);
2061 }
2062 if (selectInitialQuery) {
2063 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2064 }
2065 intent.setSourceBounds(sourceBounds);
2066 try {
2067 startActivity(intent);
2068 } catch (ActivityNotFoundException ex) {
2069 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2070 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 }
2072
Yura4f93ec62014-02-04 14:15:21 +00002073 public boolean isOnCustomContent() {
2074 return mWorkspace.isOnOrMovingToCustomContent();
2075 }
2076
Winson Chung70d72102011-08-12 11:24:35 -07002077 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002078 public boolean onPrepareOptionsMenu(Menu menu) {
2079 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002080 if (!isOnCustomContent()) {
2081 // Close any open folders
2082 closeFolder();
2083 // Stop resizing any widgets
2084 mWorkspace.exitWidgetResizeMode();
2085 if (!mWorkspace.isInOverviewMode()) {
2086 // Show the overview mode
2087 showOverviewMode(true);
2088 } else {
2089 showWorkspace(true);
2090 }
Winson Chunge0298742014-01-17 12:03:00 -08002091 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002092 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002093 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002094
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002095 @Override
2096 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002097 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002098 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002099 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002100 }
2101
Joe Onorato9c1289c2009-08-17 11:03:03 -04002102 public boolean isWorkspaceLocked() {
2103 return mWorkspaceLoading || mWaitingForResult;
2104 }
2105
Adam Cohen517a7f52014-03-01 12:12:59 -08002106 public boolean isWorkspaceLoading() {
2107 return mWorkspaceLoading;
2108 }
2109
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002110 private void setWorkspaceLoading(boolean value) {
2111 boolean isLocked = isWorkspaceLocked();
2112 mWorkspaceLoading = value;
2113 if (isLocked != isWorkspaceLocked()) {
2114 onWorkspaceLockedChanged();
2115 }
2116 }
2117
2118 private void setWaitingForResult(boolean value) {
2119 boolean isLocked = isWorkspaceLocked();
2120 mWaitingForResult = value;
2121 if (isLocked != isWorkspaceLocked()) {
2122 onWorkspaceLockedChanged();
2123 }
2124 }
2125
2126 protected void onWorkspaceLockedChanged() { }
2127
Michael Jurka0280c3b2010-09-17 15:00:07 -07002128 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002129 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002130 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002131 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2132 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002133 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002134 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002135 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002136
Adam Cohenad4e15c2013-10-17 16:21:35 -07002137 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2138 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2139 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2140 }
2141
2142 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2143 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2144 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002145 if (appWidgetInfo.configure != null) {
2146 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002147 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002148
Bjorn Bringert7984c942009-12-09 15:38:25 +00002149 // Launch over to configure widget, if needed
2150 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002151 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002152 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002153 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002154 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002155 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002156 Runnable onComplete = new Runnable() {
2157 @Override
2158 public void run() {
2159 // Exit spring loaded mode if necessary after adding the widget
2160 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2161 null);
2162 }
2163 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002164 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002165 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002166 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002167 }
2168 }
Romain Guycbb89e42009-06-08 15:52:54 -07002169
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002170 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002171 // Close any folders that may be open.
2172 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002173 mWorkspace.moveToCustomContentScreen(animate);
2174 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002175 /**
2176 * Process a shortcut drop.
2177 *
2178 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002179 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002180 * @param cell The cell it should be added to, optional
2181 * @param position The location on the screen where it was dropped, optional
2182 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002183 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002184 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002185 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002186 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002187 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002188 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002189
2190 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002191 mPendingAddInfo.cellX = cell[0];
2192 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002193 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002194
2195 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2196 createShortcutIntent.setComponent(componentName);
2197 processShortcut(createShortcutIntent);
2198 }
2199
Adam Cohenfbba09b2011-07-18 21:43:05 -07002200 /**
2201 * Process a widget drop.
2202 *
2203 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002204 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002205 * @param cell The cell it should be added to, optional
2206 * @param position The location on the screen where it was dropped, optional
2207 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002208 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002209 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002210 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002211 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002212 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002213 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002214 mPendingAddInfo.minSpanX = info.minSpanX;
2215 mPendingAddInfo.minSpanY = info.minSpanY;
2216
Adam Cohenfbba09b2011-07-18 21:43:05 -07002217 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002218 mPendingAddInfo.cellX = cell[0];
2219 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002220 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002221 if (span != null) {
2222 mPendingAddInfo.spanX = span[0];
2223 mPendingAddInfo.spanY = span[1];
2224 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002225
Adam Cohened66b2b2012-01-23 17:28:51 -08002226 AppWidgetHostView hostView = info.boundWidget;
2227 int appWidgetId;
2228 if (hostView != null) {
2229 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002230 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002231 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002232 // In this case, we either need to start an activity to get permission to bind
2233 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002234 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002235 Bundle options = info.bindOptions;
2236
2237 boolean success = false;
2238 if (options != null) {
2239 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2240 info.componentName, options);
2241 } else {
2242 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2243 info.componentName);
2244 }
2245 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002246 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002247 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002248 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002249 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2250 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2251 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002252 // TODO: we need to make sure that this accounts for the options bundle.
2253 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002254 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2255 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002256 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 }
2258
Joe Onoratodeb98af2010-02-19 14:59:39 -08002259 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002260 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002261 }
2262
Winson Chung24ab2f12010-09-16 14:10:47 -07002263 void processWallpaper(Intent intent) {
2264 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2265 }
2266
Adam Cohendcd297f2013-06-18 13:13:40 -07002267 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002268 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002269 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002270 folderInfo.title = getText(R.string.folder_name);
2271
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002272 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002273 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002274 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002275 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002276
2277 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002278 FolderIcon newFolder =
2279 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002280 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002281 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002282 // Force measure the new folder icon
2283 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2284 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002285 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002286 }
Romain Guycbb89e42009-06-08 15:52:54 -07002287
Joe Onorato9c1289c2009-08-17 11:03:03 -04002288 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002289 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002290 }
2291
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002292 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002293 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002294 }
2295
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002296 /**
2297 * Registers various content observers. The current implementation registers
2298 * only a favorites observer to keep track of the favorites applications.
2299 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002300 private void registerContentObservers() {
2301 ContentResolver resolver = getContentResolver();
2302 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2303 true, mWidgetObserver);
2304 }
2305
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002306 @Override
2307 public boolean dispatchKeyEvent(KeyEvent event) {
2308 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2309 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002310 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002311 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002312 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002313 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002314 dumpState();
2315 return true;
2316 }
2317 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002318 }
2319 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2320 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002321 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002322 return true;
2323 }
2324 }
2325
2326 return super.dispatchKeyEvent(event);
2327 }
2328
Joe Onorato88ec0992009-11-19 13:16:06 -08002329 @Override
2330 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002331 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002332 if (mAppsCustomizeContent.getContentType() ==
2333 AppsCustomizePagedView.ContentType.Applications) {
2334 showWorkspace(true);
2335 } else {
2336 showOverviewMode(true);
2337 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002338 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002339 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002340 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002341 Folder openFolder = mWorkspace.getOpenFolder();
2342 if (openFolder.isEditingName()) {
2343 openFolder.dismissEditingName();
2344 } else {
2345 closeFolder();
2346 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002347 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002348 mWorkspace.exitWidgetResizeMode();
2349
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002350 // Back button is a no-op here, but give at least some feedback for the button press
2351 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002352 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002353 }
2354
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002355 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002356 * Re-listen when widgets are reset.
2357 */
2358 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002359 if (mAppWidgetHost != null) {
2360 mAppWidgetHost.startListening();
2361 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002362 }
2363
2364 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002365 * Launches the intent referred by the clicked shortcut.
2366 *
2367 * @param v The view representing the clicked shortcut.
2368 */
2369 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002370 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2371 // view has detached (it's possible for this to happen if the view is removed mid touch).
2372 if (v.getWindowToken() == null) {
2373 return;
2374 }
2375
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002376 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002377 return;
2378 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002379
Adam Cohen1697b792013-09-17 19:08:21 -07002380 if (v instanceof Workspace) {
2381 if (mWorkspace.isInOverviewMode()) {
2382 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002383 }
2384 return;
2385 }
2386
2387 if (v instanceof CellLayout) {
2388 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002389 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002390 }
2391 }
2392
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002393 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002394 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002395 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002396 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002397 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002398 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002399 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002400 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002401 onClickAllAppsButton(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002402 }
2403 }
2404
Michael Jurka0e260592010-06-30 17:07:39 -07002405 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002406 return false;
2407 }
2408
Michael Jurkaaf442092010-06-10 17:01:57 -07002409 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002410 * Event handler for the search button
2411 *
2412 * @param v The view that was clicked.
2413 */
2414 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002415 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2416
Amith Yamasania135ba82011-08-09 17:42:01 -07002417 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002418 }
2419
2420 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002421 * Event handler for the voice button
2422 *
2423 * @param v The view that was clicked.
2424 */
2425 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002426 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002427
Bjorn Bringertc459e522013-06-07 19:36:01 +01002428 startVoice();
2429 }
2430
2431 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002432 try {
2433 final SearchManager searchManager =
2434 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2435 ComponentName activityName = searchManager.getGlobalSearchActivity();
2436 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002437 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002438 if (activityName != null) {
2439 intent.setPackage(activityName.getPackageName());
2440 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002441 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002442 } catch (ActivityNotFoundException e) {
2443 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002444 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002445 startActivitySafely(null, intent, "onClickVoiceButton");
2446 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002447 }
2448
2449 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002450 * Event handler for the "grid" button that appears on the home screen, which
2451 * enters all apps mode.
2452 *
2453 * @param v The view that was clicked.
2454 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002455 protected void onClickAllAppsButton(View v) {
2456 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2457 if (isAllAppsVisible()) {
2458 showWorkspace(true);
2459 } else {
2460 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2461 }
2462 }
2463
2464 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002465 * Event handler for a paged view icon click.
2466 * @param v The view that was clicked.
2467 * @param appInfo The {link AppInfo} of the view.
2468 */
2469 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2470 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2471 startActivitySafely(v, appInfo.intent, appInfo);
2472 getStats().recordLaunch(appInfo.intent);
2473 }
2474
2475 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002476 * Event handler for an app shortcut click.
2477 *
2478 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2479 */
2480 protected void onClickAppShortcut(View v) {
2481 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2482 Object tag = v.getTag();
2483 if (!(tag instanceof ShortcutInfo)) {
2484 throw new IllegalArgumentException("Input must be a Shortcut");
2485 }
2486
2487 // Open shortcut
2488 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2489 final Intent intent = shortcut.intent;
2490
2491 // Check for special shortcuts
2492 if (intent.getComponent() != null) {
2493 final String shortcutClass = intent.getComponent().getClassName();
2494
2495 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2496 MemoryDumpActivity.startDump(this);
2497 return;
2498 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2499 toggleShowWeightWatcher();
2500 return;
2501 }
2502 }
2503
2504 // Start activities
2505 int[] pos = new int[2];
2506 v.getLocationOnScreen(pos);
2507 intent.setSourceBounds(new Rect(pos[0], pos[1],
2508 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2509
2510 boolean success = startActivitySafely(v, intent, tag);
2511
2512 mStats.recordLaunch(intent, shortcut);
2513
2514 if (success && v instanceof BubbleTextView) {
2515 mWaitingForResume = (BubbleTextView) v;
2516 mWaitingForResume.setStayPressed(true);
2517 }
2518 }
2519
2520 /**
2521 * Event handler for a folder icon click.
2522 *
2523 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2524 */
2525 protected void onClickFolderIcon(View v) {
2526 if (LOGD) Log.d(TAG, "onClickFolder");
2527 if (!(v instanceof FolderIcon)){
2528 throw new IllegalArgumentException("Input must be a FolderIcon");
2529 }
2530
2531 FolderIcon folderIcon = (FolderIcon) v;
2532 final FolderInfo info = folderIcon.getFolderInfo();
2533 Folder openFolder = mWorkspace.getFolderForTag(info);
2534
2535 // If the folder info reports that the associated folder is open, then verify that
2536 // it is actually opened. There have been a few instances where this gets out of sync.
2537 if (info.opened && openFolder == null) {
2538 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2539 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2540 info.opened = false;
2541 }
2542
2543 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2544 // Close any open folder
2545 closeFolder();
2546 // Open the requested folder
2547 openFolder(folderIcon);
2548 } else {
2549 // Find the open folder...
2550 int folderScreen;
2551 if (openFolder != null) {
2552 folderScreen = mWorkspace.getPageForView(openFolder);
2553 // .. and close it
2554 closeFolder(openFolder);
2555 if (folderScreen != mWorkspace.getCurrentPage()) {
2556 // Close any folder open on the current screen
2557 closeFolder();
2558 // Pull the folder onto this screen
2559 openFolder(folderIcon);
2560 }
2561 }
2562 }
Michael Jurka5130e402011-10-13 04:55:35 -07002563 }
2564
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002565 /**
2566 * Event handler for the (Add) Widgets button that appears after a long press
2567 * on the home screen.
2568 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002569 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002570 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002571 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2572 }
2573
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002574 /**
2575 * Event handler for the wallpaper picker button that appears after a long press
2576 * on the home screen.
2577 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002578 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002579 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2580 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2581 pickWallpaper.setComponent(getWallpaperPickerComponent());
2582 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2583 }
2584
2585 /**
2586 * Event handler for a click on the settings button that appears after a long press
2587 * on the home screen.
2588 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002589 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002590 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2591 }
2592
Michael Jurka5130e402011-10-13 04:55:35 -07002593 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002594 // Provide the same haptic feedback that the system offers for virtual keys.
2595 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002596 }
2597
Adam Cohen61f560d2013-09-30 15:58:20 -07002598 public void performHapticFeedbackOnTouchDown(View v) {
2599 // Provide the same haptic feedback that the system offers for virtual keys.
2600 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2601 }
2602
2603 public View.OnTouchListener getHapticFeedbackTouchListener() {
2604 if (mHapticFeedbackTouchListener == null) {
2605 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2606 @Override
2607 public boolean onTouch(View v, MotionEvent event) {
2608 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2609 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2610 }
2611 return false;
2612 }
2613 };
2614 }
2615 return mHapticFeedbackTouchListener;
2616 }
2617
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002618 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002619 if (!DISABLE_MARKET_BUTTON) {
2620 if (mAppMarketIntent != null) {
2621 startActivitySafely(v, mAppMarketIntent, "app market");
2622 } else {
2623 Log.e(TAG, "Invalid app market intent.");
2624 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002625 }
2626 }
2627
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002628 public void onDragStarted(View view) {}
2629
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002630 /**
2631 * Called when the user stops interacting with the launcher.
2632 * This implies that the user is now on the homescreen and is not doing housekeeping.
2633 */
2634 protected void onInteractionEnd() {}
2635
2636 /**
2637 * Called when the user starts interacting with the launcher.
2638 * The possible interactions are:
2639 * - open all apps
2640 * - reorder an app shortcut, or a widget
2641 * - open the overview mode.
2642 * This is a good time to stop doing things that only make sense
2643 * when the user is on the homescreen and not doing housekeeping.
2644 */
2645 protected void onInteractionBegin() {}
2646
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002647 void startApplicationDetailsActivity(ComponentName componentName) {
2648 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002649 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2650 Uri.fromParts("package", packageName, null));
Adrian Roos850f9132014-01-13 17:44:52 -08002651 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |
2652 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002653 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002654 }
2655
Michael Jurka1e2f4652013-07-08 18:03:46 -07002656 // returns true if the activity was started
2657 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002658 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002659 // System applications cannot be installed. For now, show a toast explaining that.
2660 // We may give them the option of disabling apps this way.
2661 int messageId = R.string.uninstall_system_app_text;
2662 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002663 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002664 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002665 String packageName = componentName.getPackageName();
2666 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002667 Intent intent = new Intent(
2668 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002669 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2670 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002671 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002672 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002673 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002674 }
2675
Michael Jurka86a720e2012-05-09 11:23:23 -07002676 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002677 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002678 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002679 // Only launch using the new animation if the shortcut has not opted out (this is a
2680 // private contract between launcher and may be ignored in the future).
2681 boolean useLaunchAnimation = (v != null) &&
2682 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002683 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2684 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002685
Kenny Guy1317e2d2014-05-08 18:52:50 +01002686 UserHandleCompat user = null;
2687 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2688 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2689 user = userManager.getUserForSerialNumber(serialNumber);
2690 }
2691
2692 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002693 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002694 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2695 v.getMeasuredWidth(), v.getMeasuredHeight());
Kenny Guy1317e2d2014-05-08 18:52:50 +01002696 optsBundle = opts.toBundle();
2697 }
2698
2699 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2700 // Could be launching some bookkeeping activity
2701 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002702 } else {
Kenny Guy1317e2d2014-05-08 18:52:50 +01002703 launcherApps.startActivityForProfile(intent.getComponent(),
2704 intent.getSourceBounds(), optsBundle, user);
Winson Chungc7450e32012-04-17 17:34:08 -07002705 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002706 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002707 } catch (SecurityException e) {
2708 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002709 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002710 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002711 "or use the exported attribute for this activity. "
2712 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002714 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002715 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002716
Michael Jurka86a720e2012-05-09 11:23:23 -07002717 boolean startActivitySafely(View v, Intent intent, Object tag) {
2718 boolean success = false;
2719 try {
2720 success = startActivity(v, intent, tag);
2721 } catch (ActivityNotFoundException e) {
2722 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2723 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2724 }
2725 return success;
2726 }
2727
Adam Cohen268c4752012-06-06 17:47:33 -07002728 /**
2729 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2730 * in the DragLayer in the exact absolute location of the original FolderIcon.
2731 */
2732 private void copyFolderIconToImage(FolderIcon fi) {
2733 final int width = fi.getMeasuredWidth();
2734 final int height = fi.getMeasuredHeight();
2735
2736 // Lazy load ImageView, Bitmap and Canvas
2737 if (mFolderIconImageView == null) {
2738 mFolderIconImageView = new ImageView(this);
2739 }
2740 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2741 mFolderIconBitmap.getHeight() != height) {
2742 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2743 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2744 }
2745
2746 DragLayer.LayoutParams lp;
2747 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2748 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2749 } else {
2750 lp = new DragLayer.LayoutParams(width, height);
2751 }
2752
Adam Cohen307fe232012-08-16 17:55:58 -07002753 // The layout from which the folder is being opened may be scaled, adjust the starting
2754 // view size by this scale factor.
2755 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002756 lp.customPosition = true;
2757 lp.x = mRectForFolderAnimation.left;
2758 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002759 lp.width = (int) (scale * width);
2760 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002761
2762 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2763 fi.draw(mFolderIconCanvas);
2764 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002765 if (fi.getFolder() != null) {
2766 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2767 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002768 }
Adam Cohen268c4752012-06-06 17:47:33 -07002769 // Just in case this image view is still in the drag layer from a previous animation,
2770 // we remove it and re-add it.
2771 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2772 mDragLayer.removeView(mFolderIconImageView);
2773 }
2774 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002775 if (fi.getFolder() != null) {
2776 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002777 }
Adam Cohen268c4752012-06-06 17:47:33 -07002778 }
2779
Adam Cohen2801caf2011-05-13 20:57:39 -07002780 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002781 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002782 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2783 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2784 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2785
Adam Cohenc51934b2011-07-26 21:07:43 -07002786 FolderInfo info = (FolderInfo) fi.getTag();
2787 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2788 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002789 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2790 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002791 }
2792
Adam Cohen268c4752012-06-06 17:47:33 -07002793 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2794 copyFolderIconToImage(fi);
2795 fi.setVisibility(View.INVISIBLE);
2796
Michael Jurka2ecf9952012-06-18 12:52:28 -07002797 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002798 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002799 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2800 oa.start();
2801 }
2802
Adam Cohen268c4752012-06-06 17:47:33 -07002803 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002804 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002805 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2806 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2807 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2808
Adam Cohen268c4752012-06-06 17:47:33 -07002809 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002810
Adam Cohen268c4752012-06-06 17:47:33 -07002811 // We remove and re-draw the FolderIcon in-case it has changed
2812 mDragLayer.removeView(mFolderIconImageView);
2813 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002814 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002815 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002816 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002817 oa.addListener(new AnimatorListenerAdapter() {
2818 @Override
2819 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002820 if (cl != null) {
2821 cl.clearFolderLeaveBehind();
2822 // Remove the ImageView copy of the FolderIcon and make the original visible.
2823 mDragLayer.removeView(mFolderIconImageView);
2824 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002825 }
2826 }
2827 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002828 oa.start();
2829 }
2830
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002831 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002832 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002833 * is animated relative to the specified View. If the View is null, no animation
2834 * is played.
2835 *
2836 * @param folderInfo The FolderInfo describing the folder to open.
2837 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002838 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002839 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002840 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002841
Adam Cohena9cf38f2011-05-02 15:36:58 -07002842 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002843
Adam Cohen4554ee12011-08-03 16:13:21 -07002844 // Just verify that the folder hasn't already been added to the DragLayer.
2845 // There was a one-off crash where the folder had a parent already.
2846 if (folder.getParent() == null) {
2847 mDragLayer.addView(folder);
2848 mDragController.addDropTarget((DropTarget) folder);
2849 } else {
2850 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2851 folder.getParent() + ").");
2852 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002853 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002854 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002855
2856 // Notify the accessibility manager that this folder "window" has appeared and occluded
2857 // the workspace items
2858 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2859 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002860 }
2861
2862 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002863 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002864 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002865 if (folder.isEditingName()) {
2866 folder.dismissEditingName();
2867 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002868 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002869
2870 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002871 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002872 }
2873 }
2874
2875 void closeFolder(Folder folder) {
2876 folder.getInfo().opened = false;
2877
2878 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2879 if (parent != null) {
2880 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2881 shrinkAndFadeInFolderIcon(fi);
2882 }
2883 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002884
2885 // Notify the accessibility manager that this folder "window" has disappeard and no
2886 // longer occludeds the workspace items
2887 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002888 }
2889
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002890 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002891 if (!isDraggingEnabled()) return false;
2892 if (isWorkspaceLocked()) return false;
2893 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894
Adam Cohen1697b792013-09-17 19:08:21 -07002895 if (v instanceof Workspace) {
2896 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002897 if (mWorkspace.enterOverviewMode()) {
2898 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2899 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2900 return true;
2901 } else {
2902 return false;
2903 }
Adam Cohen1697b792013-09-17 19:08:21 -07002904 }
Adam Cohen1697b792013-09-17 19:08:21 -07002905 }
2906
Adam Cohene0aaa0d2014-05-12 12:44:22 -07002907 CellLayout.CellInfo longClickCellInfo = null;
2908 View itemUnderLongClick = null;
2909 if (v.getTag() instanceof ItemInfo) {
2910 ItemInfo info = (ItemInfo) v.getTag();
2911 longClickCellInfo = new CellLayout.CellInfo(v, info);;
2912 itemUnderLongClick = longClickCellInfo.cell;
2913 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002914 }
2915
Winson Chung3d503fb2011-07-13 17:25:49 -07002916 // The hotseat touch handling does not go through Workspace, and we always allow long press
2917 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05002918 final boolean inHotseat = isHotseatLayout(v);
2919 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07002920 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002921 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002922 // User long pressed on empty space
2923 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2924 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2925 // Disabling reordering until we sort out some issues.
2926 if (mWorkspace.isInOverviewMode()) {
2927 mWorkspace.startReordering(v);
2928 } else {
2929 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002930 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002931 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05002932 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
2933 mHotseat.getOrderInHotseat(
2934 longClickCellInfo.cellX,
2935 longClickCellInfo.cellY));
2936 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002937 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002938 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002939 }
2940 }
2941 }
2942 return true;
2943 }
2944
Winson Chung3d503fb2011-07-13 17:25:49 -07002945 boolean isHotseatLayout(View layout) {
2946 return mHotseat != null && layout != null &&
2947 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2948 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002949
Winson Chung3d503fb2011-07-13 17:25:49 -07002950 /**
2951 * Returns the CellLayout of the specified container at the specified screen.
2952 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002953 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002954 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2955 if (mHotseat != null) {
2956 return mHotseat.getLayout();
2957 } else {
2958 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002959 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002960 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002961 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002962 }
2963 }
2964
Daniel Sandler843e8602010-06-07 14:59:01 -04002965 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002966 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002967 }
2968
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002969 /**
2970 * Helper method for the cameraZoomIn/cameraZoomOut animations
2971 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002972 * @param scaleFactor The scale factor used for the zoom
2973 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002974 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002975 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002976 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002977 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002978
Craig Mautner360310b2012-10-26 15:13:08 -07002979 private void setWorkspaceBackground(boolean workspace) {
2980 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002981 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002982 }
2983
Selim Cinek3a8a8f72014-01-16 10:38:38 -08002984 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002985 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2986 int curflags = getWindow().getAttributes().flags
2987 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2988 if (wpflags != curflags) {
2989 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2990 }
Craig Mautner360310b2012-10-26 15:13:08 -07002991 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002992 }
2993
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002994 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2995 if (v instanceof LauncherTransitionable) {
2996 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2997 }
2998 }
2999
Michael Jurkabed61d22012-02-14 22:51:29 -08003000 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3001 if (v instanceof LauncherTransitionable) {
3002 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3003 }
Winson Chung70442722012-02-10 15:43:22 -08003004
3005 // Update the workspace transition step as well
3006 dispatchOnLauncherTransitionStep(v, 0f);
3007 }
3008
3009 private void dispatchOnLauncherTransitionStep(View v, float t) {
3010 if (v instanceof LauncherTransitionable) {
3011 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3012 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003013 }
3014
3015 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3016 if (v instanceof LauncherTransitionable) {
3017 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3018 }
Winson Chung70442722012-02-10 15:43:22 -08003019
3020 // Update the workspace transition step as well
3021 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003022 }
3023
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003024 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003025 * Things to test when changing the following seven functions.
3026 * - Home from workspace
3027 * - from center screen
3028 * - from other screens
3029 * - Home from all apps
3030 * - from center screen
3031 * - from other screens
3032 * - Back from all apps
3033 * - from center screen
3034 * - from other screens
3035 * - Launch app from workspace and quit
3036 * - with back
3037 * - with home
3038 * - Launch app from all apps and quit
3039 * - with back
3040 * - with home
3041 * - Go to a screen that's not the default, then all
3042 * apps, and launch and app, and go back
3043 * - with back
3044 * -with home
3045 * - On workspace, long press power and go back
3046 * - with back
3047 * - with home
3048 * - On all apps, long press power and go back
3049 * - with back
3050 * - with home
3051 * - On workspace, power off
3052 * - On all apps, power off
3053 * - Launch an app and turn off the screen while in that app
3054 * - Go back with home key
3055 * - Go back with back key TODO: make this not go to workspace
3056 * - From all apps
3057 * - From workspace
3058 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3059 * - From all apps
3060 * - From the center workspace
3061 * - From another workspace
3062 */
3063
3064 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003065 * Zoom the camera out from the workspace to reveal 'toView'.
3066 * Assumes that the view to show is anchored at either the very top or very bottom
3067 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003068 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003069 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003070 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3071 showAppsCustomizeHelper(animated, springLoaded, contentType);
3072 }
3073 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3074 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003075 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003076 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003077 mStateAnimation.cancel();
3078 mStateAnimation = null;
3079 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003080 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003081
Winson Chungf0ea4d32011-06-06 14:27:16 -07003082 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3083 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3084 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003085 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003086 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003087 final int startDelay =
3088 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003089
Michael Jurkab3e22d92011-10-31 15:58:33 -07003090 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003091
Michael Jurkad74c9842011-07-10 12:44:21 -07003092 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003093 Animator workspaceAnim =
3094 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003095 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003096 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3097 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003098 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3099 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003100
3101 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003102 toView.setScaleX(scale);
3103 toView.setScaleY(scale);
3104 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
3105 scaleAnim.
3106 scaleX(1f).scaleY(1f).
3107 setDuration(duration).
3108 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08003109
Winson Chungf0ea4d32011-06-06 14:27:16 -07003110 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08003111 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003112 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003113 .ofFloat(toView, "alpha", 0f, 1f)
3114 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003115 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08003116 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3117 @Override
3118 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07003119 if (animation == null) {
3120 throw new RuntimeException("animation is null");
3121 }
Winson Chung70442722012-02-10 15:43:22 -08003122 float t = (Float) animation.getAnimatedValue();
3123 dispatchOnLauncherTransitionStep(fromView, t);
3124 dispatchOnLauncherTransitionStep(toView, t);
3125 }
3126 });
Adam Cohenf16e5712011-01-13 13:31:45 -08003127
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003128 // toView should appear right at the end of the workspace shrink
3129 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07003130 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003131 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08003132 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003133
3134 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003135 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07003136 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003137 // Prepare the position
3138 toView.setTranslationX(0.0f);
3139 toView.setTranslationY(0.0f);
3140 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003141 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003142 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07003143 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003144 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003145 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3146 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07003147
Winson Chungc7d2b602012-05-16 17:02:20 -07003148 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003149 if (mSearchDropTargetBar != null) {
3150 mSearchDropTargetBar.hideSearchBar(false);
3151 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07003152 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003153 });
3154
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003155 if (workspaceAnim != null) {
3156 mStateAnimation.play(workspaceAnim);
3157 }
Michael Jurka1899a362011-11-03 13:50:45 -07003158
3159 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003160
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003161 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3162 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003163
3164 // If any of the objects being animated haven't been measured/laid out
3165 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003166 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003167 (mWorkspace.getMeasuredWidth() == 0) ||
3168 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003169 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003170 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003171
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003172 final AnimatorSet stateAnimation = mStateAnimation;
3173 final Runnable startAnimRunnable = new Runnable() {
3174 public void run() {
3175 // Check that mStateAnimation hasn't changed while
3176 // we waited for a layout/draw pass
3177 if (mStateAnimation != stateAnimation)
3178 return;
3179 setPivotsForZoom(toView, scale);
3180 dispatchOnLauncherTransitionStart(fromView, animated, false);
3181 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003182 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003183 }
3184 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003185 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003186 final ViewTreeObserver observer = toView.getViewTreeObserver();
3187 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3188 public void onGlobalLayout() {
3189 startAnimRunnable.run();
3190 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3191 }
3192 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003193 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003194 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003195 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003196 } else {
3197 toView.setTranslationX(0.0f);
3198 toView.setTranslationY(0.0f);
3199 toView.setScaleX(1.0f);
3200 toView.setScaleY(1.0f);
3201 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003202 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003203
Daniel Sandlere4f98912013-06-25 15:13:26 -04003204 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003205 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003206 if (mSearchDropTargetBar != null) {
3207 mSearchDropTargetBar.hideSearchBar(false);
3208 }
Michael Jurkaabded662011-03-04 12:06:57 -08003209 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003210 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003211 dispatchOnLauncherTransitionStart(fromView, animated, false);
3212 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003213 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003214 dispatchOnLauncherTransitionStart(toView, animated, false);
3215 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003216 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003217 }
3218
3219 /**
3220 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003221 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003222 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003223 */
Adam Cohened307df2013-10-02 09:37:31 -07003224 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003225 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003226
Michael Jurkab3e22d92011-10-31 15:58:33 -07003227 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003228 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003229 mStateAnimation.cancel();
3230 mStateAnimation = null;
3231 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003232 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003233
Winson Chungf0ea4d32011-06-06 14:27:16 -07003234 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003235 final int fadeOutDuration =
3236 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003237 final float scaleFactor = (float)
3238 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3239 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003240 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003241 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003242 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003243 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3244 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003245 toState, animated, stagger, -1);
3246 } else if (toState == Workspace.State.SPRING_LOADED ||
3247 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003248 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003249 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003250 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003251
Michael Jurkab3e22d92011-10-31 15:58:33 -07003252 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003253 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003254 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003255 final LauncherViewPropertyAnimator scaleAnim =
3256 new LauncherViewPropertyAnimator(fromView);
3257 scaleAnim.
3258 scaleX(scaleFactor).scaleY(scaleFactor).
3259 setDuration(duration).
3260 setInterpolator(new Workspace.ZoomInInterpolator());
3261
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003262 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003263 .ofFloat(fromView, "alpha", 1f, 0f)
3264 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003265 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003266 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3267 @Override
3268 public void onAnimationUpdate(ValueAnimator animation) {
3269 float t = 1f - (Float) animation.getAnimatedValue();
3270 dispatchOnLauncherTransitionStep(fromView, t);
3271 dispatchOnLauncherTransitionStep(toView, t);
3272 }
3273 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003274
Michael Jurka2ecf9952012-06-18 12:52:28 -07003275 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003276
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003277 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3278 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003279 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003280
3281 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003282 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003283 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003284 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003285 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3286 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003287 if (onCompleteRunnable != null) {
3288 onCompleteRunnable.run();
3289 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003290 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003291 }
3292 });
3293
Winson Chungf0ea4d32011-06-06 14:27:16 -07003294 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003295 if (workspaceAnim != null) {
3296 mStateAnimation.play(workspaceAnim);
3297 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003298 dispatchOnLauncherTransitionStart(fromView, animated, true);
3299 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003300 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003301 } else {
3302 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003303 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003304 dispatchOnLauncherTransitionStart(fromView, animated, true);
3305 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003306 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003307 dispatchOnLauncherTransitionStart(toView, animated, true);
3308 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003309 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003310 }
3311
Michael Jurkae326f182011-11-21 14:05:46 -08003312 @Override
3313 public void onTrimMemory(int level) {
3314 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003315 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003316 mAppsCustomizeTabHost.onTrimMemory();
3317 }
3318 }
3319
Adam Cohened307df2013-10-02 09:37:31 -07003320 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003321 showWorkspace(animated, null);
3322 }
3323
Adam Cohened307df2013-10-02 09:37:31 -07003324 protected void showWorkspace() {
3325 showWorkspace(true);
3326 }
3327
Adam Cohened66b2b2012-01-23 17:28:51 -08003328 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003329 if (mWorkspace.isInOverviewMode()) {
3330 mWorkspace.exitOverviewMode(animated);
3331 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003332 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003333 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003334 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003335 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003336
Winson Chungc7d2b602012-05-16 17:02:20 -07003337 // Show the search bar (only animate if we were showing the drop target bar in spring
3338 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003339 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003340 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003341 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003342
Michael Jurkab3e22d92011-10-31 15:58:33 -07003343 // Set focus to the AppsCustomize button
3344 if (mAllAppsButton != null) {
3345 mAllAppsButton.requestFocus();
3346 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003347 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003348
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003349 // Change the state *after* we've called all the transition code
3350 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003351
Winson Chung5fb63472011-02-02 17:03:37 -08003352 // Resume the auto-advance of widgets
3353 mUserPresent = true;
3354 updateRunning();
3355
alanv1d4fde62012-10-17 13:15:47 -07003356 // Send an accessibility event to announce the context change
3357 getWindow().getDecorView()
3358 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003359
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003360 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003361 }
3362
Adam Cohened307df2013-10-02 09:37:31 -07003363 void showOverviewMode(boolean animated) {
3364 mWorkspace.setVisibility(View.VISIBLE);
3365 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3366 mState = State.WORKSPACE;
3367 onWorkspaceShown(animated);
3368 }
3369
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003370 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003371 }
3372
Winson Chung82963d52013-10-09 11:20:57 -07003373 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3374 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003375 if (mState != State.WORKSPACE) return;
3376
Winson Chung82963d52013-10-09 11:20:57 -07003377 if (resetPageToZero) {
3378 mAppsCustomizeTabHost.reset();
3379 }
Winson Chungc58497e2013-09-03 17:48:37 -07003380 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003381 mAppsCustomizeTabHost.requestFocus();
3382
Michael Jurkab3e22d92011-10-31 15:58:33 -07003383 // Change the state *after* we've called all the transition code
3384 mState = State.APPS_CUSTOMIZE;
3385
3386 // Pause the auto-advance of widgets until we are out of AllApps
3387 mUserPresent = false;
3388 updateRunning();
3389 closeFolder();
3390
3391 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003392 getWindow().getDecorView()
3393 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003394 }
3395
Adam Cohen7777d962011-08-18 18:58:38 -07003396 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003397 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003398 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003399 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003400 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003401 }
Adam Cohen7777d962011-08-18 18:58:38 -07003402
Adam Cohenad4e15c2013-10-17 16:21:35 -07003403 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003404 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003405 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3406
Winson Chunge7a03942011-08-05 15:05:12 -07003407 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003408 @Override
3409 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003410 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003411 // Before we show workspace, hide all apps again because
3412 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3413 // clean up our state transition functions
3414 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003415 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003416 } else {
3417 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003418 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003419 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003420 }, delay);
3421
Winson Chung557d6ed2011-07-08 15:34:52 -07003422 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003423
Michael Jurkad3ef3062010-11-23 16:23:58 -08003424 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003425 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003426 final boolean animated = true;
3427 final boolean springLoaded = true;
3428 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003429 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003430 }
3431 // Otherwise, we are not in spring loaded mode, so don't do anything.
3432 }
3433
Michael Jurkab3e22d92011-10-31 15:58:33 -07003434 void lockAllApps() {
3435 // TODO
3436 }
3437
3438 void unlockAllApps() {
3439 // TODO
3440 }
3441
Winson Chungf0ea4d32011-06-06 14:27:16 -07003442 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003443 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003444 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003445 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003446 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003447 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003448 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003449 int duration = 0;
3450 if (mSearchDropTargetBar != null) {
3451 duration = mSearchDropTargetBar.getTransitionInDuration();
3452 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003453 mHotseat.animate().alpha(1f).setDuration(duration);
3454 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003455 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003456 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003457 }
3458 }
3459 }
3460
3461 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003462 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003463 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003464 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003465 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003466 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003467 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003468 int duration = 0;
3469 if (mSearchDropTargetBar != null) {
3470 duration = mSearchDropTargetBar.getTransitionOutDuration();
3471 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003472 mHotseat.animate().alpha(0f).setDuration(duration);
3473 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003474 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003475 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003476 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003477 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003478 }
3479
Patrick Dubroy5f445422011-02-18 14:35:21 -08003480 /**
3481 * Add an item from all apps or customize onto the given workspace screen.
3482 * If layout is null, add to the current screen.
3483 */
3484 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003485 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003486 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003487 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003488 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003489
Winson Chungdff8ebb2011-09-08 17:25:31 -07003490 /** Maps the current orientation to an index for referencing orientation correct global icons */
3491 private int getCurrentOrientationIndexForGlobalIcons() {
3492 // default - 0, landscape - 1
3493 switch (getResources().getConfiguration().orientation) {
3494 case Configuration.ORIENTATION_LANDSCAPE:
3495 return 1;
3496 default:
3497 return 0;
3498 }
3499 }
3500
Michael Jurkaae65ee32012-04-30 11:45:54 -07003501 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003502 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003503 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003504 // Look for the toolbar icon specified in the activity meta-data
3505 Bundle metaData = packageManager.getActivityInfo(
3506 activityName, PackageManager.GET_META_DATA).metaData;
3507 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003508 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003509 if (iconResId != 0) {
3510 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003511 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003512 }
3513 }
3514 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003515 // This can happen if the activity defines an invalid drawable
3516 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3517 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003518 } catch (Resources.NotFoundException nfe) {
3519 // This can happen if the activity defines an invalid drawable
3520 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3521 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003522 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003523 return null;
3524 }
3525
3526 // if successful in getting icon, return it; otherwise, set button to use default drawable
3527 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003528 int buttonId, ComponentName activityName, int fallbackDrawableId,
3529 String toolbarResourceName) {
3530 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003531 Resources r = getResources();
3532 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3533 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003534
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003535 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003536 // If we were unable to find the icon via the meta-data, use a generic one
3537 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003538 toolbarIcon = r.getDrawable(fallbackDrawableId);
3539 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003540 if (button != null) {
3541 button.setCompoundDrawables(toolbarIcon, null, null, null);
3542 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003543 return null;
3544 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003545 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003546 if (button != null) {
3547 button.setCompoundDrawables(toolbarIcon, null, null, null);
3548 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003549 return toolbarIcon.getConstantState();
3550 }
3551 }
3552
3553 // if successful in getting icon, return it; otherwise, set button to use default drawable
3554 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003555 int buttonId, ComponentName activityName, int fallbackDrawableId,
3556 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003557 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003558 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003559
Michael Jurka19e0fc52011-07-22 18:00:21 -07003560 if (button != null) {
3561 // If we were unable to find the icon via the meta-data, use a
3562 // generic one
3563 if (toolbarIcon == null) {
3564 button.setImageResource(fallbackDrawableId);
3565 } else {
3566 button.setImageDrawable(toolbarIcon);
3567 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003568 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003569
3570 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3571
Michael Jurka0423dcf2010-10-05 14:56:18 -07003572 }
3573
Winson Chung1b884092012-06-08 17:13:02 -07003574 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003575 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003576 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003577 }
3578
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003579 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003580 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003581 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003582 }
3583
Winson Chungbb185bd2011-11-21 12:31:42 -08003584 private void invalidatePressedFocusedStates(View container, View button) {
3585 if (container instanceof HolographicLinearLayout) {
3586 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3587 layout.invalidatePressedFocusedStates();
3588 } else if (button instanceof HolographicImageView) {
3589 HolographicImageView view = (HolographicImageView) button;
3590 view.invalidatePressedFocusedStates();
3591 }
3592 }
3593
Cristina Stancu476493b2013-08-07 17:20:14 +01003594 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003595 if (mQsb == null) {
3596 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3597 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003598 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003599 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003600 }
3601
3602 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003603 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003604 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003605 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003606 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003607
Winson Chung1cad91e2011-05-25 17:41:01 -07003608 final SearchManager searchManager =
3609 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3610 ComponentName activityName = searchManager.getGlobalSearchActivity();
3611 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003612 int coi = getCurrentOrientationIndexForGlobalIcons();
3613 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003614 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3615 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3616 if (sGlobalSearchIcon[coi] == null) {
3617 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3618 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3619 TOOLBAR_ICON_METADATA_NAME);
3620 }
3621
Winson Chungc51db6a2011-10-05 11:44:49 -07003622 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3623 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003624 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003625 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003626 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003627 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003628 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3629 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003630 if (searchButton != null) searchButton.setVisibility(View.GONE);
3631 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003632 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003633 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003634 }
3635 }
3636
Cristina Stancu476493b2013-08-07 17:20:14 +01003637 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003638 final View searchButtonContainer = findViewById(R.id.search_button_container);
3639 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003640 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003641 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003642 }
3643
Cristina Stancu476493b2013-08-07 17:20:14 +01003644 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003645 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003646 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003647
Winson Chungc51db6a2011-10-05 11:44:49 -07003648 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003649 final SearchManager searchManager =
3650 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3651 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3652
3653 ComponentName activityName = null;
3654 if (globalSearchActivity != null) {
3655 // Check if the global search activity handles voice search
3656 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3657 intent.setPackage(globalSearchActivity.getPackageName());
3658 activityName = intent.resolveActivity(getPackageManager());
3659 }
3660
3661 if (activityName == null) {
3662 // Fallback: check if an activity other than the global search activity
3663 // resolves this
3664 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3665 activityName = intent.resolveActivity(getPackageManager());
3666 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003667 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003668 int coi = getCurrentOrientationIndexForGlobalIcons();
3669 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003670 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3671 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3672 if (sVoiceSearchIcon[coi] == null) {
3673 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3674 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3675 TOOLBAR_ICON_METADATA_NAME);
3676 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003677 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003678 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003679 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003680 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003681 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003682 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003683 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003684 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003685 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003686 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003687 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003688 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003689
Cristina Stancu476493b2013-08-07 17:20:14 +01003690 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003691 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3692 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003693 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003694 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003695 }
3696
Winson Chung5841efa2013-09-30 18:06:44 -07003697 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003698 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3699 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003700 boolean visible = !forceDisableVoiceButtonProxy &&
3701 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003702 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003703 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003704 }
3705 }
Winson Chung5841efa2013-09-30 18:06:44 -07003706
3707 /**
3708 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3709 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3710 */
3711 public void disableVoiceButtonProxy(boolean disabled) {
3712 updateVoiceButtonProxyVisible(disabled);
3713 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003714 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003715 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003716 */
3717 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003718 if (!DISABLE_MARKET_BUTTON) {
3719 final View marketButton = findViewById(R.id.market_button);
3720 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3721 // Find the app market activity by resolving an intent.
3722 // (If multiple app markets are installed, it will return the ResolverActivity.)
3723 ComponentName activityName = intent.resolveActivity(getPackageManager());
3724 if (activityName != null) {
3725 int coi = getCurrentOrientationIndexForGlobalIcons();
3726 mAppMarketIntent = intent;
3727 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3728 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3729 TOOLBAR_ICON_METADATA_NAME);
3730 marketButton.setVisibility(View.VISIBLE);
3731 } else {
3732 // We should hide and disable the view so that we don't try and restore the visibility
3733 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3734 marketButton.setVisibility(View.GONE);
3735 marketButton.setEnabled(false);
3736 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003737 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003738 }
3739
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003740 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003741 if (!DISABLE_MARKET_BUTTON) {
3742 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3743 Resources r = getResources();
3744 Drawable marketIconDrawable = d.newDrawable(r);
3745 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3746 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3747 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003748
Winson Chungd64a6662013-09-30 11:06:59 -07003749 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3750 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003751 }
3752
Michael Jurkad7c28052012-04-27 15:43:36 -07003753 @Override
3754 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003755 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003756 final List<CharSequence> text = event.getText();
3757 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003758 // Populate event with a fake title based on the current state.
3759 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003760 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003761 } else {
3762 text.add(getString(R.string.all_apps_home_button_label));
3763 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003764 return result;
3765 }
3766
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003767 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003768 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003769 */
3770 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3771 @Override
3772 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003773 closeSystemDialogs();
3774 }
3775 }
3776
3777 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003778 * Receives notifications whenever the appwidgets are reset.
3779 */
3780 private class AppWidgetResetObserver extends ContentObserver {
3781 public AppWidgetResetObserver() {
3782 super(new Handler());
3783 }
3784
3785 @Override
3786 public void onChange(boolean selfChange) {
3787 onAppWidgetReset();
3788 }
3789 }
3790
3791 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003792 * If the activity is currently paused, signal that we need to run the passed Runnable
3793 * in onResume.
3794 *
3795 * This needs to be called from incoming places where resources might have been loaded
3796 * while we are paused. That is becaues the Configuration might be wrong
3797 * when we're not running, and if it comes back to what it was when we
3798 * were paused, we are not restarted.
3799 *
3800 * Implementation of the method from LauncherModel.Callbacks.
3801 *
3802 * @return true if we are currently paused. The caller might be able to
3803 * skip some work in that case since we will come back again.
3804 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003805 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003806 if (mPaused) {
3807 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003808 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003809 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003810 }
3811 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003812 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003813 return true;
3814 } else {
3815 return false;
3816 }
3817 }
3818
Michael Jurkac402cd92013-05-20 15:49:32 +02003819 private boolean waitUntilResume(Runnable run) {
3820 return waitUntilResume(run, false);
3821 }
3822
Michael Jurka1e2f4652013-07-08 18:03:46 -07003823 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003824 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003825 }
3826
Michael Jurka7607c2f2013-04-03 14:33:19 -07003827 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003828 * If the activity is currently paused, signal that we need to re-run the loader
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 */
3841 public boolean setLoadOnResume() {
3842 if (mPaused) {
3843 Log.i(TAG, "setLoadOnResume");
3844 mOnResumeNeedsLoad = true;
3845 return true;
3846 } else {
3847 return false;
3848 }
3849 }
3850
3851 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003852 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003853 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003854 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003855 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003856 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003857 } else {
3858 return SCREEN_COUNT / 2;
3859 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003860 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003861
Joe Onorato9c1289c2009-08-17 11:03:03 -04003862 /**
3863 * Refreshes the shortcuts shown on the workspace.
3864 *
3865 * Implementation of the method from LauncherModel.Callbacks.
3866 */
3867 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07003868 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08003869
Michael Jurka7607c2f2013-04-03 14:33:19 -07003870 // If we're starting binding all over again, clear any bind calls we'd postponed in
3871 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3872 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003873 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003874
Winson Chungd64d1762013-08-20 14:37:16 -07003875 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003876 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003877 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003878
Michael Jurka05bf6442011-11-30 20:28:53 -08003879 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003880 if (mHotseat != null) {
3881 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003882 }
3883 }
3884
Adam Cohendcd297f2013-06-18 13:13:40 -07003885 @Override
3886 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003887 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003888
Adam Cohen5084cba2013-09-03 12:01:16 -07003889 // If there are no screens, we need to have an empty screen
3890 if (orderedScreenIds.size() == 0) {
3891 mWorkspace.addExtraEmptyScreen();
3892 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003893
3894 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003895 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05003896 if (hasCustomContentToLeft()) {
3897 mWorkspace.createCustomContentContainer();
3898 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07003899 }
Winson Chung64359a52013-07-08 17:17:08 -07003900 }
3901
3902 @Override
3903 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003904 // Log to disk
3905 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3906 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3907 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003908 int count = orderedScreenIds.size();
3909 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003910 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003911 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003912 }
3913
Adam Cohen39a06042013-07-19 14:30:12 -07003914 private boolean shouldShowWeightWatcher() {
3915 String spKey = LauncherAppState.getSharedPreferencesKey();
3916 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003917 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003918
3919 return show;
3920 }
3921
3922 private void toggleShowWeightWatcher() {
3923 String spKey = LauncherAppState.getSharedPreferencesKey();
3924 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3925 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3926
3927 show = !show;
3928
3929 SharedPreferences.Editor editor = sp.edit();
3930 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3931 editor.commit();
3932
3933 if (mWeightWatcher != null) {
3934 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3935 }
3936 }
3937
Winson Chungd64d1762013-08-20 14:37:16 -07003938 public void bindAppsAdded(final ArrayList<Long> newScreens,
3939 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003940 final ArrayList<ItemInfo> addAnimated,
3941 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003942 Runnable r = new Runnable() {
3943 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003944 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003945 }
3946 };
3947 if (waitUntilResume(r)) {
3948 return;
3949 }
3950
Winson Chungd64d1762013-08-20 14:37:16 -07003951 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08003952 if (newScreens != null) {
3953 bindAddScreens(newScreens);
3954 }
Winson Chungd64d1762013-08-20 14:37:16 -07003955
3956 // We add the items without animation on non-visible pages, and with
3957 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08003958 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003959 bindItems(addNotAnimated, 0,
3960 addNotAnimated.size(), false);
3961 }
Adam Cohen76a47a12014-02-05 11:47:43 -08003962 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07003963 bindItems(addAnimated, 0,
3964 addAnimated.size(), true);
3965 }
Winson Chungc58497e2013-09-03 17:48:37 -07003966
Winson Chung87412982013-10-03 18:34:14 -07003967 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07003968 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07003969
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003970 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003971 addedApps != null && mAppsCustomizeContent != null) {
3972 mAppsCustomizeContent.addApps(addedApps);
3973 }
Winson Chungd64d1762013-08-20 14:37:16 -07003974 }
3975
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003976 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003977 * Bind the items start-end from the list.
3978 *
3979 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003980 */
Winson Chung64359a52013-07-08 17:17:08 -07003981 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3982 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003983 Runnable r = new Runnable() {
3984 public void run() {
3985 bindItems(shortcuts, start, end, forceAnimateIcons);
3986 }
3987 };
3988 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003989 return;
3990 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003991
Winson Chungf0c6ae02012-03-21 16:10:31 -07003992 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003993 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3994 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003995 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003996 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003997 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003998 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003999 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004000
4001 // Short circuit if we are loading dock items for a configuration which has no dock
4002 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4003 mHotseat == null) {
4004 continue;
4005 }
4006
Joe Onorato9c1289c2009-08-17 11:03:03 -04004007 switch (item.itemType) {
4008 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4009 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004010 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004011 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004012
Winson Chung64359a52013-07-08 17:17:08 -07004013 /*
4014 * TODO: FIX collision case
4015 */
Winson Chungce376632013-07-11 16:12:41 -07004016 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4017 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4018 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004019 View v = cl.getChildAt(item.cellX, item.cellY);
4020 Object tag = v.getTag();
4021 String desc = "Collision while binding workspace item: " + item
4022 + ". Collides with " + tag;
4023 if (LauncherAppState.isDogfoodBuild()) {
4024 throw (new RuntimeException(desc));
4025 } else {
4026 Log.d(TAG, desc);
4027 }
Winson Chungce376632013-07-11 16:12:41 -07004028 }
Winson Chung64359a52013-07-08 17:17:08 -07004029 }
4030
Adam Cohendcd297f2013-06-18 13:13:40 -07004031 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4032 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004033 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004034 // Animate all the applications up now
4035 shortcut.setAlpha(0f);
4036 shortcut.setScaleX(0f);
4037 shortcut.setScaleY(0f);
4038 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004039 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004040 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004041 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004042 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004043 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004044 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004045 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004046 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4047 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004048 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004049 default:
4050 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004051 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004052 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004053
Winson Chung997a9232013-07-24 15:33:46 -07004054 if (animateIcons) {
4055 // Animate to the correct page
4056 if (newShortcutsScreenId > -1) {
4057 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004058 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004059 final Runnable startBounceAnimRunnable = new Runnable() {
4060 public void run() {
4061 anim.playTogether(bounceAnims);
4062 anim.start();
4063 }
4064 };
Winson Chung997a9232013-07-24 15:33:46 -07004065 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004066 // We post the animation slightly delayed to prevent slowdowns
4067 // when we are loading right after we return to launcher.
4068 mWorkspace.postDelayed(new Runnable() {
4069 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004070 if (mWorkspace != null) {
4071 mWorkspace.snapToPage(newScreenIndex);
4072 mWorkspace.postDelayed(startBounceAnimRunnable,
4073 NEW_APPS_ANIMATION_DELAY);
4074 }
Winson Chung94d67682013-09-25 16:29:40 -07004075 }
4076 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004077 } else {
4078 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004079 }
4080 }
Winson Chung64359a52013-07-08 17:17:08 -07004081 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004082 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004083 }
4084
Joe Onorato9c1289c2009-08-17 11:03:03 -04004085 /**
4086 * Implementation of the method from LauncherModel.Callbacks.
4087 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004088 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004089 Runnable r = new Runnable() {
4090 public void run() {
4091 bindFolders(folders);
4092 }
4093 };
4094 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004095 return;
4096 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004097 sFolders.clear();
4098 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004099 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004100
4101 /**
4102 * Add the views for a widget to the workspace.
4103 *
4104 * Implementation of the method from LauncherModel.Callbacks.
4105 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004106 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004107 Runnable r = new Runnable() {
4108 public void run() {
4109 bindAppWidget(item);
4110 }
4111 };
4112 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004113 return;
4114 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004115
Daniel Sandler843e8602010-06-07 14:59:01 -04004116 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4117 if (DEBUG_WIDGETS) {
4118 Log.d(TAG, "bindAppWidget: " + item);
4119 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004120 final Workspace workspace = mWorkspace;
4121
4122 final int appWidgetId = item.appWidgetId;
4123 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04004124 if (DEBUG_WIDGETS) {
4125 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4126 }
4127
Joe Onorato9c1289c2009-08-17 11:03:03 -04004128 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4129
Joe Onorato9c1289c2009-08-17 11:03:03 -04004130 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004131 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004132
Adam Cohendcd297f2013-06-18 13:13:40 -07004133 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004134 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004135 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4136
Joe Onorato9c1289c2009-08-17 11:03:03 -04004137 workspace.requestLayout();
4138
Daniel Sandler843e8602010-06-07 14:59:01 -04004139 if (DEBUG_WIDGETS) {
4140 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4141 + (SystemClock.uptimeMillis()-start) + "ms");
4142 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004143 }
4144
Adam Cohen1462de32012-07-24 22:34:36 -07004145 public void onPageBoundSynchronously(int page) {
4146 mSynchronouslyBoundPages.add(page);
4147 }
4148
Joe Onorato9c1289c2009-08-17 11:03:03 -04004149 /**
4150 * Callback saying that there aren't any more items to bind.
4151 *
4152 * Implementation of the method from LauncherModel.Callbacks.
4153 */
Adam Cohene25af792013-06-06 23:08:25 -07004154 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004155 Runnable r = new Runnable() {
4156 public void run() {
4157 finishBindingItems(upgradePath);
4158 }
4159 };
4160 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004161 return;
4162 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004163 if (mSavedState != null) {
4164 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004165 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004166 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004167 mSavedState = null;
4168 }
4169
Adam Cohen1462de32012-07-24 22:34:36 -07004170 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004171
Patrick Dubroy002cbf42011-03-03 16:36:21 -08004172 // If we received the result of any pending adds while the loader was running (e.g. the
4173 // widget configuration forced an orientation change), process them now.
4174 for (int i = 0; i < sPendingAddList.size(); i++) {
4175 completeAdd(sPendingAddList.get(i));
4176 }
4177 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004178
Winson Chungc51db6a2011-10-05 11:44:49 -07004179 // Update the market app icon as necessary (the other icons will be managed in response to
4180 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004181 if (!DISABLE_MARKET_BUTTON) {
4182 updateAppMarketIcon();
4183 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004184
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004185 setWorkspaceLoading(false);
Adam Cohene25af792013-06-06 23:08:25 -07004186 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004187 mWorkspace.getUniqueComponents(true, null);
4188 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004189 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004190 }
4191
Winson Chunga0b7e862013-09-05 16:03:15 -07004192 public boolean isAllAppsButtonRank(int rank) {
4193 if (mHotseat != null) {
4194 return mHotseat.isAllAppsButtonRank(rank);
4195 }
4196 return false;
4197 }
4198
Winson Chunga2413752012-04-03 14:22:34 -07004199 private boolean canRunNewAppsAnimation() {
4200 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4201 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4202 }
4203
Winson Chungc9168342013-06-26 14:54:55 -07004204 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4205 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4206 PropertyValuesHolder.ofFloat("alpha", 1f),
4207 PropertyValuesHolder.ofFloat("scaleX", 1f),
4208 PropertyValuesHolder.ofFloat("scaleY", 1f));
4209 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4210 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4211 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4212 return bounceAnim;
4213 }
4214
Adam Cohen27772732013-11-11 14:00:56 +00004215 public boolean useVerticalBarLayout() {
4216 return LauncherAppState.getInstance().getDynamicGrid().
4217 getDeviceProfile().isVerticalBarLayout();
4218 }
4219
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004220 protected Rect getSearchBarBounds() {
4221 return LauncherAppState.getInstance().getDynamicGrid().
4222 getDeviceProfile().getSearchBarBounds();
4223 }
4224
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004225 @Override
4226 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004227 boolean searchVisible = updateGlobalSearchIcon();
4228 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004229 if (mSearchDropTargetBar != null) {
4230 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4231 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004232 }
4233
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004234 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004235 * Add the icons for all apps.
4236 *
4237 * Implementation of the method from LauncherModel.Callbacks.
4238 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004239 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004240 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004241 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4242 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4243 getHotseat().addAllAppsFolder(mIconCache, apps,
4244 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4245 }
4246 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004247 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004248 if (mAppsCustomizeContent != null) {
4249 mAppsCustomizeContent.onPackagesUpdated(
4250 LauncherModel.getSortedWidgetsAndShortcuts(this));
4251 }
Winson Chungc58497e2013-09-03 17:48:37 -07004252 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004253 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004254 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004255 mAppsCustomizeContent.onPackagesUpdated(
4256 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004257 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004258 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004259 }
4260
4261 /**
4262 * A package was updated.
4263 *
4264 * Implementation of the method from LauncherModel.Callbacks.
4265 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004266 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004267 Runnable r = new Runnable() {
4268 public void run() {
4269 bindAppsUpdated(apps);
4270 }
4271 };
4272 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004273 return;
4274 }
4275
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004276 if (mWorkspace != null) {
4277 mWorkspace.updateShortcuts(apps);
4278 }
Winson Chungc58497e2013-09-03 17:48:37 -07004279
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004280 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004281 mAppsCustomizeContent != null) {
4282 mAppsCustomizeContent.updateApps(apps);
4283 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004284 }
4285
4286 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004287 * Update the state of a package, typically related to install state.
4288 *
4289 * Implementation of the method from LauncherModel.Callbacks.
4290 */
4291 public void updatePackageState(String pkgName, int state) {
4292 if (mWorkspace != null) {
4293 mWorkspace.updatePackageState(pkgName, state);
4294 }
4295 }
4296
4297 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004298 * A package was uninstalled. We take both the super set of packageNames
4299 * in addition to specific applications to remove, the reason being that
4300 * this can be called when a package is updated as well. In that scenario,
4301 * we only remove specific components from the workspace, where as
4302 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004303 *
4304 * Implementation of the method from LauncherModel.Callbacks.
4305 */
Winson Chung83892cc2013-05-01 16:53:33 -07004306 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004307 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004308 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004309 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004310 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004311 }
Winson Chungd64d1762013-08-20 14:37:16 -07004312 };
4313 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004314 return;
4315 }
4316
Winson Chungdf95eb12013-10-16 14:57:07 -07004317 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004318 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004319 }
4320 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004321 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004322 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004323
Winson Chunga1820962011-10-03 16:31:06 -07004324 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004325 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004326
Winson Chungdf95eb12013-10-16 14:57:07 -07004327 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004328 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004329 mAppsCustomizeContent != null) {
4330 mAppsCustomizeContent.removeApps(appInfos);
4331 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004332 }
Joe Onoratobe386092009-11-17 17:32:16 -08004333
4334 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004335 * A number of packages were updated.
4336 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004337 private ArrayList<Object> mWidgetsAndShortcuts;
4338 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004339 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004340 bindPackagesUpdated(mWidgetsAndShortcuts);
4341 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004342 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004343 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004344 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4345 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4346 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004347 return;
4348 }
4349
Winson Chung64359a52013-07-08 17:17:08 -07004350 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004351 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004352 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004353 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004354 }
4355
Winson Chung400438b2011-01-16 17:53:48 -08004356 private int mapConfigurationOriActivityInfoOri(int configOri) {
4357 final Display d = getWindowManager().getDefaultDisplay();
4358 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4359 switch (d.getRotation()) {
4360 case Surface.ROTATION_0:
4361 case Surface.ROTATION_180:
4362 // We are currently in the same basic orientation as the natural orientation
4363 naturalOri = configOri;
4364 break;
4365 case Surface.ROTATION_90:
4366 case Surface.ROTATION_270:
4367 // We are currently in the other basic orientation to the natural orientation
4368 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4369 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4370 break;
4371 }
4372
4373 int[] oriMap = {
4374 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4375 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4376 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4377 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4378 };
4379 // Since the map starts at portrait, we need to offset if this device's natural orientation
4380 // is landscape.
4381 int indexOffset = 0;
4382 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4383 indexOffset = 1;
4384 }
4385 return oriMap[(d.getRotation() + indexOffset) % 4];
4386 }
Adam Cohen446e9402011-09-15 18:21:21 -07004387
Winson Chung4b919f82012-05-01 10:44:08 -07004388 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004389 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004390 getResources().getBoolean(R.bool.allow_rotation);
4391 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004392 }
Winson Chung4b919f82012-05-01 10:44:08 -07004393 public void lockScreenOrientation() {
4394 if (isRotationEnabled()) {
4395 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4396 .getConfiguration().orientation));
4397 }
4398 }
4399 public void unlockScreenOrientation(boolean immediate) {
4400 if (isRotationEnabled()) {
4401 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004402 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004403 } else {
4404 mHandler.postDelayed(new Runnable() {
4405 public void run() {
4406 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4407 }
4408 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004409 }
Winson Chung4b919f82012-05-01 10:44:08 -07004410 }
Winson Chung400438b2011-01-16 17:53:48 -08004411 }
4412
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004413 /**
4414 * Called when the SearchBar hint should be changed.
4415 *
4416 * @param hint the hint to be displayed in the search bar.
4417 */
4418 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004419 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004420 }
4421
Winson Chunge43a1e72014-01-15 10:33:02 -08004422 protected boolean isLauncherPreinstalled() {
4423 PackageManager pm = getPackageManager();
4424 try {
4425 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4426 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4427 return true;
4428 } else {
4429 return false;
4430 }
4431 } catch (NameNotFoundException e) {
4432 e.printStackTrace();
4433 return false;
4434 }
4435 }
4436
Adam Cohen5eed5d82014-05-19 13:12:13 -07004437 protected boolean shouldClingFocusHotseatApp() {
4438 return false;
4439 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004440 protected String getFirstRunClingSearchBarHint() {
4441 return "";
4442 }
4443 protected String getFirstRunCustomContentHint() {
4444 return "";
4445 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004446 protected int getFirstRunFocusedHotseatAppDrawableId() {
4447 return -1;
4448 }
4449 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4450 return null;
4451 }
4452 protected int getFirstRunFocusedHotseatAppRank() {
4453 return -1;
4454 }
4455 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4456 return "";
4457 }
4458 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4459 return "";
4460 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004461
Winson Chungaf40f202013-09-18 18:26:31 -07004462 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004463 mLauncherClings.dismissFirstRunCling(v);
4464 }
4465 public void dismissMigrationClingCopyApps(View v) {
4466 mLauncherClings.dismissMigrationClingCopyApps(v);
4467 }
4468 public void dismissMigrationClingUseDefault(View v) {
4469 mLauncherClings.dismissMigrationClingUseDefault(v);
4470 }
4471 public void dismissMigrationWorkspaceCling(View v) {
4472 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004473 }
Winson Chung82f55532011-08-09 14:14:23 -07004474 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004475 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004476 }
4477 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004478 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004479 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004480 public void markFolderClingDismissedIfNecessary() {
4481 mLauncherClings.markFolderClingDismissedIfNecessary();
4482 }
Adam Cohen432609a2014-03-13 17:03:22 -07004483
4484 /**
4485 * To be overridden by subclasses to indicate that there is an activity to launch
4486 * before showing the standard launcher experience.
4487 */
4488 protected boolean hasFirstRunActivity() {
4489 return false;
4490 }
4491
4492 /**
4493 * To be overridden by subclasses to launch any first run activity
4494 */
4495 protected Intent getFirstRunActivity() {
4496 return null;
4497 }
4498
Winson Chunga6945242014-01-08 14:04:34 -08004499 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004500 return !ActivityManager.isRunningInTestHarness() &&
4501 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004502 }
4503
Adam Cohen4a9423d2014-03-28 14:22:31 -07004504 protected boolean hasRunFirstRunActivity() {
4505 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4506 }
4507
Adam Cohen432609a2014-03-13 17:03:22 -07004508 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004509 if (shouldRunFirstRunActivity() &&
4510 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004511 Intent firstRunIntent = getFirstRunActivity();
4512 if (firstRunIntent != null) {
4513 startActivity(firstRunIntent);
4514 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004515 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004516 }
4517 }
Adam Cohen432609a2014-03-13 17:03:22 -07004518 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004519 }
4520
4521 private void markFirstRunActivityShown() {
4522 SharedPreferences.Editor editor = mSharedPrefs.edit();
4523 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4524 editor.apply();
4525 }
4526
Adam Cohen432609a2014-03-13 17:03:22 -07004527 /**
4528 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4529 * screen that must be displayed and dismissed.
4530 */
4531 protected boolean hasDismissableIntroScreen() {
4532 return false;
4533 }
4534
4535 /**
4536 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4537 */
4538 protected View getIntroScreen() {
4539 return null;
4540 }
4541
4542 /**
4543 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4544 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4545 */
4546 private boolean shouldShowIntroScreen() {
4547 return hasDismissableIntroScreen() &&
4548 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4549 }
4550
4551 protected void showIntroScreen() {
4552 View introScreen = getIntroScreen();
4553 changeWallpaperVisiblity(false);
4554 if (introScreen != null) {
4555 mDragLayer.showOverlayView(introScreen);
4556 }
4557 }
4558
4559 public void dismissIntroScreen() {
4560 markIntroScreenDismissed();
4561 if (showFirstRunActivity()) {
4562 // We delay hiding the intro view until the first run activity is showing. This
4563 // avoids a blip.
4564 mWorkspace.postDelayed(new Runnable() {
4565 @Override
4566 public void run() {
4567 mDragLayer.dismissOverlayView();
4568 }
4569 }, ACTIVITY_START_DELAY);
4570 } else {
4571 mDragLayer.dismissOverlayView();
4572 }
4573 changeWallpaperVisiblity(true);
4574 }
4575
4576 private void markIntroScreenDismissed() {
4577 SharedPreferences.Editor editor = mSharedPrefs.edit();
4578 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4579 editor.apply();
4580 }
4581
Winson Chunga6945242014-01-08 14:04:34 -08004582 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004583 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4584 if (mHotseat != null) mHotseat.setAlpha(1f);
4585 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4586 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004587 }
4588
4589 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004590 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4591 if (mHotseat != null) mHotseat.setAlpha(0f);
4592 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4593 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004594 }
4595
Mathew Inwood72fbec12013-11-19 15:45:07 +00004596 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004597 // Called from search suggestion, not supported in other profiles.
4598 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4599 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4600 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4601 myUser);
4602 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004603 return null;
4604 }
Kenny Guyed131872014-04-30 03:02:21 +01004605 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004606 }
4607
4608 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4609 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004610 // Called from search suggestion, not supported in other profiles.
4611 return createShortcutDragInfo(shortcutIntent, caption, icon,
4612 UserHandleCompat.myUserHandle());
4613 }
4614
4615 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4616 Bitmap icon, UserHandleCompat user) {
4617 return new ShortcutInfo(shortcutIntent, caption, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004618 }
4619
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004620 protected void moveWorkspaceToDefaultScreen() {
4621 mWorkspace.moveToDefaultScreen(false);
4622 }
4623
Mathew Inwood72fbec12013-11-19 15:45:07 +00004624 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4625 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004626 mWorkspace.onExternalDragStartedWithItem(dragView);
4627 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004628 }
4629
Anjali Koppalf5d29132014-02-28 13:33:27 -08004630 @Override
4631 public void onPageSwitch(View newPage, int newPageIndex) {
4632 }
4633
Winson Chung80baf5a2010-08-09 16:03:15 -07004634 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004635 * Prints out out state for debugging.
4636 */
4637 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004638 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004639 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004640 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4641 Log.d(TAG, "mRestoring=" + mRestoring);
4642 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4643 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004644 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004645 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004646
Winson Chung785d2eb2011-04-14 16:08:02 -07004647 if (mAppsCustomizeContent != null) {
4648 mAppsCustomizeContent.dumpState();
4649 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004650 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004651 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004652
4653 @Override
4654 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4655 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004656 synchronized (sDumpLogs) {
4657 writer.println(" ");
4658 writer.println("Debug logs: ");
4659 for (int i = 0; i < sDumpLogs.size(); i++) {
4660 writer.println(" " + sDumpLogs.get(i));
4661 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004662 }
4663 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004664
4665 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004666 if (DEBUG_DUMP_LOG) {
4667 synchronized (sDumpLogs) {
4668 Log.d(TAG, "");
4669 Log.d(TAG, "*********************");
4670 Log.d(TAG, "Launcher debug logs: ");
4671 for (int i = 0; i < sDumpLogs.size(); i++) {
4672 Log.d(TAG, " " + sDumpLogs.get(i));
4673 }
4674 Log.d(TAG, "*********************");
4675 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004676 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004677 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004678 }
4679
4680 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004681 addDumpLog(tag, log, null, debugLog);
4682 }
4683
4684 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004685 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004686 if (e != null) {
4687 Log.d(tag, log, e);
4688 } else {
4689 Log.d(tag, log);
4690 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004691 }
Winson Chungede41292013-09-19 16:27:36 -07004692 if (DEBUG_DUMP_LOG) {
4693 sDateStamp.setTime(System.currentTimeMillis());
4694 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004695 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4696 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004697 }
Winson Chungede41292013-09-19 16:27:36 -07004698 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004699 }
4700
Winson Chungede41292013-09-19 16:27:36 -07004701 public void dumpLogsToLocalData() {
4702 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004703 new AsyncTask<Void, Void, Void>() {
4704 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004705 boolean success = false;
4706 sDateStamp.setTime(sRunStart);
4707 String FILENAME = sDateStamp.getMonth() + "-"
4708 + sDateStamp.getDay() + "_"
4709 + sDateStamp.getHours() + "-"
4710 + sDateStamp.getMinutes() + "_"
4711 + sDateStamp.getSeconds() + ".txt";
4712
4713 FileOutputStream fos = null;
4714 File outFile = null;
4715 try {
4716 outFile = new File(getFilesDir(), FILENAME);
4717 outFile.createNewFile();
4718 fos = new FileOutputStream(outFile);
4719 } catch (Exception e) {
4720 e.printStackTrace();
4721 }
4722 if (fos != null) {
4723 PrintWriter writer = new PrintWriter(fos);
4724
4725 writer.println(" ");
4726 writer.println("Debug logs: ");
4727 synchronized (sDumpLogs) {
4728 for (int i = 0; i < sDumpLogs.size(); i++) {
4729 writer.println(" " + sDumpLogs.get(i));
4730 }
4731 }
4732 writer.close();
4733 }
4734 try {
4735 if (fos != null) {
4736 fos.close();
4737 success = true;
4738 }
4739 } catch (IOException e) {
4740 e.printStackTrace();
4741 }
Michael Jurka43467462013-11-14 12:03:58 +01004742 return null;
Winson Chungede41292013-09-19 16:27:36 -07004743 }
Michael Jurka43467462013-11-14 12:03:58 +01004744 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004745 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004747}
Michael Jurka2763be32011-02-24 11:19:57 -08004748
Michael Jurkaabded662011-03-04 12:06:57 -08004749interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004750 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004751 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004752 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004753 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004754 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004755}
Dan Sandlerd5024042014-01-09 15:01:33 -05004756
4757interface DebugIntents {
4758 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4759 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00004760}