blob: 681ed24a0f005226fb75dda17315054189d8cdde [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
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
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;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
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;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080091import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.Advanceable;
94import android.widget.FrameLayout;
95import android.widget.ImageView;
96import android.widget.TextView;
97import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070098
Daniel Sandler325dc232013-06-05 22:57:57 -040099import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800100
Adam Cohenc0dcf592011-06-01 15:30:43 -0700101import java.io.DataInputStream;
102import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700103import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700108import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700109import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700111import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700114import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116/**
117 * Default launcher application.
118 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100119public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700120 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700121 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800122 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700123 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124
Daniel Sandlerf061f822013-06-27 13:59:36 -0400125 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400126 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700127 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400128 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700129 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700132 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 private static final int REQUEST_PICK_APPLICATION = 6;
134 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700135 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700136 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
Michael Jurka8b805b12012-04-18 14:23:14 -0700138 private static final int REQUEST_BIND_APPWIDGET = 11;
139
Mathew Inwood876a8462013-06-14 14:12:41 +0100140 /**
141 * IntentStarter uses request codes starting with this. This must be greater than all activity
142 * request codes used internally.
143 */
144 protected static final int REQUEST_LAST = 100;
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
147
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800148 static final int SCREEN_COUNT = 5;
149 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Romain Guy98d01652009-06-30 16:21:04 -0700151 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800152 // To turn on these properties, type
153 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
154 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
155 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
Winson Chung2672ff92012-05-04 16:22:30 -0700157 // The Intent extra that defines whether to ignore the launch animation
158 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400159 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700160
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 // Type: int
162 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700163 // Type: int
164 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700166 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
167 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
169 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700172 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 // Type: boolean
174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
175 // Type: long
176 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700177 // Type: int
178 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
179 // Type: int
180 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
181 // Type: parcelable
182 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100184 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700185 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100186 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700187 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700189
Adam Cohen39a06042013-07-19 14:30:12 -0700190 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700191 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700192
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700193 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700194 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700195 private State mState = State.WORKSPACE;
196 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197
Joe Onorato9c1289c2009-08-17 11:03:03 -0400198 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700199 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
200 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700201 private static final int SHOW_CLING_DURATION = 250;
202 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800203
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800205 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206
Winson Chunga2413752012-04-03 14:22:34 -0700207 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700208 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
209 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700210 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700211
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800212 private final BroadcastReceiver mCloseSystemDialogsReceiver
213 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800214 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
215
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216 private LayoutInflater mInflater;
217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700219 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800220 private DragLayer mDragLayer;
221 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700222 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700223
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700224 private AppWidgetManager mAppWidgetManager;
225 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700226
Michael Jurkac9d95c52011-08-29 14:03:34 -0700227 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700228 private AppWidgetProviderInfo mPendingAddWidgetInfo;
229
Michael Jurka0280c3b2010-09-17 15:00:07 -0700230 private int[] mTmpAddItemCellCoordinates = new int[2];
231
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232 private FolderInfo mFolderInfo;
233
Winson Chung3d503fb2011-07-13 17:25:49 -0700234 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700235 private View mOverviewPanel;
236
Michael Jurka838a4ca2011-02-07 13:33:06 -0800237 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700238
Winson Chungc51db6a2011-10-05 11:44:49 -0700239 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700240 private AppsCustomizeTabHost mAppsCustomizeTabHost;
241 private AppsCustomizePagedView mAppsCustomizeContent;
242 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100243 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700246 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
247 // scroll issues (because the workspace may not have been measured yet) and extra work.
248 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
249 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250
251 private SpannableStringBuilder mDefaultKeySsb = null;
252
Joe Onorato9c1289c2009-08-17 11:03:03 -0400253 private boolean mWorkspaceLoading = true;
254
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800255 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 private boolean mRestoring;
257 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700258 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259
Michael Jurka1e2f4652013-07-08 18:03:46 -0700260 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700261 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
262
Winson Chung4a2afa32012-07-19 14:53:05 -0700263 // Keep track of whether the user has left launcher
264 private static boolean sPausedFromUserAction = false;
265
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 private Bundle mSavedInstanceState;
267
Joe Onorato9c1289c2009-08-17 11:03:03 -0400268 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800269 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800270 private boolean mUserPresent = true;
271 private boolean mVisible = false;
272 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700273 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700274 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400275
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700276 private static LocaleConfiguration sLocaleConfiguration = null;
277
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700278 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700279
Adam Cohen61f560d2013-09-30 15:58:20 -0700280 private View.OnTouchListener mHapticFeedbackTouchListener;
281
Adam Cohended9f8d2010-11-03 13:25:16 -0700282 // Related to the auto-advancing of widgets
283 private final int ADVANCE_MSG = 1;
284 private final int mAdvanceInterval = 20000;
285 private final int mAdvanceStagger = 250;
286 private long mAutoAdvanceSentTime;
287 private long mAutoAdvanceTimeLeft = -1;
288 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
289 new HashMap<View, AppWidgetProviderInfo>();
290
Winson Chung400438b2011-01-16 17:53:48 -0800291 // Determines how long to wait after a rotation before restoring the screen orientation to
292 // match the sensor state.
293 private final int mRestoreScreenOrientationDelay = 500;
294
Michael Jurka4ef207b2010-11-29 17:05:45 -0800295 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700296 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
297 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
298 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299
Winson Chungd64a6662013-09-30 11:06:59 -0700300 private Intent mAppMarketIntent = null;
301 private static final boolean DISABLE_MARKET_BUTTON = true;
302
Craig Mautner360310b2012-10-26 15:13:08 -0700303 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700304
Adam Cohen1462de32012-07-24 22:34:36 -0700305 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
306
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700307 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700308 static Date sDateStamp = new Date();
309 static DateFormat sDateFormat =
310 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
311 static long sRunStart = System.currentTimeMillis();
312 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700313
Winson Chung46353de2012-02-16 14:05:10 -0800314 // We only want to get the SharedPreferences once since it does an FS stat each time we get
315 // it from the context.
316 private SharedPreferences mSharedPrefs;
317
Adam Cohene25af792013-06-06 23:08:25 -0700318 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
319
Winson Chungf0c6ae02012-03-21 16:10:31 -0700320 // Holds the page that we need to animate to, and the icon views that we need to animate up
321 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700322 private ImageView mFolderIconImageView;
323 private Bitmap mFolderIconBitmap;
324 private Canvas mFolderIconCanvas;
325 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700326
Michael Jurkaddd62e92011-02-16 17:49:14 -0800327 private BubbleTextView mWaitingForResume;
328
Michael Jurka7267fa52013-09-26 15:29:57 -0700329 protected TransparentBars mTransparentBars;
330
Michael Jurka22143132012-10-04 17:42:38 +0200331 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
332 = new HideFromAccessibilityHelper();
333
Michael Jurkac1f5d262011-09-30 19:32:27 -0700334 private Runnable mBuildLayersRunnable = new Runnable() {
335 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700336 if (mWorkspace != null) {
337 mWorkspace.buildPageHardwareLayers();
338 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700339 }
340 };
341
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800342 private static ArrayList<PendingAddArguments> sPendingAddList
343 = new ArrayList<PendingAddArguments>();
344
Michael Jurka7267fa52013-09-26 15:29:57 -0700345 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800346
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800347 private static class PendingAddArguments {
348 int requestCode;
349 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700350 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700351 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800352 int cellX;
353 int cellY;
354 }
355
Daniel Sandlerff02d492013-08-05 02:12:05 -0400356 private Stats mStats;
357
Michael Jurka0a457bf2012-11-19 14:05:05 -0800358 private static boolean isPropertyEnabled(String propertyName) {
359 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700360 }
361
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 @Override
363 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700364 if (DEBUG_STRICT_MODE) {
365 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
366 .detectDiskReads()
367 .detectDiskWrites()
368 .detectNetwork() // or .detectAll() for all detectable problems
369 .penaltyLog()
370 .build());
371 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
372 .detectLeakedSqlLiteObjects()
373 .detectLeakedClosableObjects()
374 .penaltyLog()
375 .penaltyDeath()
376 .build());
377 }
378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400381 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400382 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700383
384 // Determine the dynamic grid properties
385 Point smallestSize = new Point();
386 Point largestSize = new Point();
387 Point realSize = new Point();
388 Display display = getWindowManager().getDefaultDisplay();
389 display.getCurrentSizeRange(smallestSize, largestSize);
390 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700391 DisplayMetrics dm = new DisplayMetrics();
392 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700393 // Lazy-initialize the dynamic grid
394 DeviceProfile grid = app.initDynamicGrid(this,
395 Math.min(smallestSize.x, smallestSize.y),
396 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700397 realSize.x, realSize.y,
398 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700399
400 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400401 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700402 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800403 mModel = app.setLauncher(this);
404 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400405 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700407
Daniel Sandlerff02d492013-08-05 02:12:05 -0400408 mStats = new Stats(this);
409
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700411 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
412 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700413
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700414 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
415 // this also ensures that any synchronous binding below doesn't re-trigger another
416 // LauncherModel load.
417 mPaused = false;
418
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200420 android.os.Debug.startMethodTracing(
421 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 }
423
424 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700426
427 mTransparentBars = new TransparentBars(findViewById(R.id.launcher));
428 mTransparentBars.requestTransparentBars(true);
429
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100431 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800433 registerContentObservers();
434
Joe Onorato7c312c12009-08-13 21:36:53 -0700435 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700436
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 mSavedState = savedInstanceState;
438 restoreState(mSavedState);
439
Winson Chunga12a2502010-12-20 14:41:35 -0800440 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700441 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200442 mAppsCustomizeContent.onPackagesUpdated(
443 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700444 }
Winson Chunga12a2502010-12-20 14:41:35 -0800445
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 if (PROFILE_STARTUP) {
447 android.os.Debug.stopMethodTracing();
448 }
449
450 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700451 if (sPausedFromUserAction) {
452 // If the user leaves launcher, then we should just load items asynchronously when
453 // they return.
454 mModel.startLoader(true, -1);
455 } else {
456 // We only load the page synchronously if the user rotates (or triggers a
457 // configuration change) while launcher is in the foreground
458 mModel.startLoader(true, mWorkspace.getCurrentPage());
459 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 }
461
462 // For handling default keys
463 mDefaultKeySsb = new SpannableStringBuilder();
464 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800465
466 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
467 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800468
Adam Cohenf9426d52012-06-04 17:26:21 -0700469 updateGlobalIcons();
470
471 // On large interfaces, we want the screen to auto-rotate based on the current orientation
472 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700473
474 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700475 }
476
Winson Chung4a2afa32012-07-19 14:53:05 -0700477 protected void onUserLeaveHint() {
478 super.onUserLeaveHint();
479 sPausedFromUserAction = true;
480 }
481
Winson Chung98ca0f72013-07-29 12:58:51 -0700482 /** To be overriden by subclasses to hint to Launcher that we have custom content */
483 protected boolean hasCustomContentToLeft() {
484 return false;
485 }
486
Dave Hawkeya8881582013-09-17 15:55:33 -0600487 /**
488 * To be overridden by subclasses to create the custom content and call
489 * {@link #addToCustomContentPage}. This will only be invoked if
490 * {@link #hasCustomContentToLeft()} is {@code true}.
491 */
492 protected void addCustomContentToLeft() {
493 }
494
495 /**
496 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
497 * ensure the custom content page is added or removed if necessary.
498 */
499 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600500 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600501 // Not bound yet, wait for bindScreens to be called.
502 return;
503 }
504
505 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
506 // Create the custom content page and call the subclass to populate it.
507 mWorkspace.createCustomContentPage();
508 addCustomContentToLeft();
509 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
510 mWorkspace.removeCustomContentPage();
511 }
512 }
513
Adam Cohenf9426d52012-06-04 17:26:21 -0700514 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700515 boolean searchVisible = false;
516 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800517 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700518 int coi = getCurrentOrientationIndexForGlobalIcons();
519 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
520 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700521 if (!DISABLE_MARKET_BUTTON) {
522 updateAppMarketIcon();
523 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700524 searchVisible = updateGlobalSearchIcon();
525 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700526 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700527 if (sGlobalSearchIcon[coi] != null) {
528 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700529 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700530 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700531 if (sVoiceSearchIcon[coi] != null) {
532 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700533 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700534 }
Winson Chungd64a6662013-09-30 11:06:59 -0700535 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700536 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800537 }
Winson Chungadf0c182012-08-23 14:59:07 -0700538 if (mSearchDropTargetBar != null) {
539 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
540 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800541 }
Romain Guycbb89e42009-06-08 15:52:54 -0700542
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800543 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700544 if (sLocaleConfiguration == null) {
545 new AsyncTask<Void, Void, LocaleConfiguration>() {
546 @Override
547 protected LocaleConfiguration doInBackground(Void... unused) {
548 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
549 readConfiguration(Launcher.this, localeConfiguration);
550 return localeConfiguration;
551 }
552
553 @Override
554 protected void onPostExecute(LocaleConfiguration result) {
555 sLocaleConfiguration = result;
556 checkForLocaleChange(); // recursive, but now with a locale configuration
557 }
558 }.execute();
559 return;
560 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700561
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800562 final Configuration configuration = getResources().getConfiguration();
563
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700564 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800565 final String locale = configuration.locale.toString();
566
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700567 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800568 final int mcc = configuration.mcc;
569
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700570 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 final int mnc = configuration.mnc;
572
Romain Guy84f296c2009-11-04 15:00:44 -0800573 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800574
Romain Guy84f296c2009-11-04 15:00:44 -0800575 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 sLocaleConfiguration.locale = locale;
577 sLocaleConfiguration.mcc = mcc;
578 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700579
Joe Onorato0589f0f2010-02-08 13:44:00 -0800580 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700581
582 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
583 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700584 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585 public void run() {
586 writeConfiguration(Launcher.this, localeConfiguration);
587 }
588 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700589 }
590 }
591
592 private static class LocaleConfiguration {
593 public String locale;
594 public int mcc = -1;
595 public int mnc = -1;
596 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700597
Romain Guy98d01652009-06-30 16:21:04 -0700598 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
599 DataInputStream in = null;
600 try {
601 in = new DataInputStream(context.openFileInput(PREFERENCES));
602 configuration.locale = in.readUTF();
603 configuration.mcc = in.readInt();
604 configuration.mnc = in.readInt();
605 } catch (FileNotFoundException e) {
606 // Ignore
607 } catch (IOException e) {
608 // Ignore
609 } finally {
610 if (in != null) {
611 try {
612 in.close();
613 } catch (IOException e) {
614 // Ignore
615 }
616 }
617 }
618 }
619
620 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
621 DataOutputStream out = null;
622 try {
623 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
624 out.writeUTF(configuration.locale);
625 out.writeInt(configuration.mcc);
626 out.writeInt(configuration.mnc);
627 out.flush();
628 } catch (FileNotFoundException e) {
629 // Ignore
630 } catch (IOException e) {
631 //noinspection ResultOfMethodCallIgnored
632 context.getFileStreamPath(PREFERENCES).delete();
633 } finally {
634 if (out != null) {
635 try {
636 out.close();
637 } catch (IOException e) {
638 // Ignore
639 }
640 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800641 }
642 }
643
Anton Hanssona2f665f2013-09-26 12:18:32 +0100644 public Stats getStats() {
645 return mStats;
646 }
647
Bjorn Bringertc459e522013-06-07 19:36:01 +0100648 public LayoutInflater getInflater() {
649 return mInflater;
650 }
651
Adam Cohen716b51e2011-06-30 12:09:54 -0700652 public DragLayer getDragLayer() {
653 return mDragLayer;
654 }
655
Winson Chung36a62fe2012-05-06 18:04:42 -0700656 boolean isDraggingEnabled() {
657 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
658 // that is subsequently removed from the workspace in startBinding().
659 return !mModel.isLoadingWorkspace();
660 }
661
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 static int getScreen() {
663 synchronized (sLock) {
664 return sScreen;
665 }
666 }
667
668 static void setScreen(int screen) {
669 synchronized (sLock) {
670 sScreen = screen;
671 }
672 }
673
Winson Chung557d6ed2011-07-08 15:34:52 -0700674 /**
675 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
676 * a configuration step, this allows the proper animations to run after other transitions.
677 */
678 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700679 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800680 switch (args.requestCode) {
681 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700682 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700683 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800684 break;
685 case REQUEST_PICK_SHORTCUT:
686 processShortcut(args.intent);
687 break;
688 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700689 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700690 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700691 result = true;
692 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800693 case REQUEST_CREATE_APPWIDGET:
694 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700695 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700696 result = true;
697 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800698 }
Michael Jurka27614d22012-04-02 06:40:22 -0700699 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
700 // if you turned the screen off and then back while in All Apps, Launcher would not
701 // return to the workspace. Clearing mAddInfo.container here fixes this issue
702 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700703 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800704 }
705
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700707 protected void onActivityResult(
708 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700709 // Reset the startActivity waiting flag
710 mWaitingForResult = false;
711
Michael Jurka8b805b12012-04-18 14:23:14 -0700712 if (requestCode == REQUEST_BIND_APPWIDGET) {
713 int appWidgetId = data != null ?
714 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
715 if (resultCode == RESULT_CANCELED) {
716 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
717 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700718 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700719 }
720 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200721 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
722 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
723 mWorkspace.exitOverviewMode(false);
724 }
725 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700726 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200727
Winson Chung557d6ed2011-07-08 15:34:52 -0700728 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800729 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
730 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700731
Adam Cohened66b2b2012-01-23 17:28:51 -0800732 // We have special handling for widgets
733 if (isWidgetDrop) {
734 int appWidgetId = data != null ?
735 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700736 if (appWidgetId < 0) {
737 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
738 "widget configuration activity.");
739 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
740 } else {
741 completeTwoStageWidgetDrop(resultCode, appWidgetId);
742 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800743 return;
744 }
745
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800746 // The pattern used here is that a user PICKs a specific application,
747 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700748
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800749 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
750 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700751 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800752 final PendingAddArguments args = new PendingAddArguments();
753 args.requestCode = requestCode;
754 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700755 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700756 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700757 args.cellX = mPendingAddInfo.cellX;
758 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800759 if (isWorkspaceLocked()) {
760 sPendingAddList.add(args);
761 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700762 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800763 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800764 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800765 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700766 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
768 null);
769 }
770
771 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700772 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700773 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800774 Runnable onCompleteRunnable = null;
775 int animationType = 0;
776
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700777 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800778 if (resultCode == RESULT_OK) {
779 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
780 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700781 mPendingAddWidgetInfo);
782 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800783 onCompleteRunnable = new Runnable() {
784 @Override
785 public void run() {
786 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700787 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800788 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
789 null);
790 }
791 };
792 } else if (resultCode == RESULT_CANCELED) {
793 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
794 onCompleteRunnable = new Runnable() {
795 @Override
796 public void run() {
797 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
798 null);
799 }
800 };
801 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700802 if (mDragLayer.getAnimatedView() != null) {
803 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
804 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
805 animationType, boundWidget, true);
806 } else {
807 // The animated view may be null in the case of a rotation during widget configuration
808 onCompleteRunnable.run();
809 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800810 }
811
812 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700813 protected void onStop() {
814 super.onStop();
815 FirstFrameAnimatorHelper.setIsVisible(false);
816 }
817
818 @Override
819 protected void onStart() {
820 super.onStart();
821 FirstFrameAnimatorHelper.setIsVisible(true);
822 }
823
824 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800825 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200826 long startTime = 0;
827 if (DEBUG_RESUME_TIME) {
828 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400829 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200830 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800831 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700832
Winson Chung4a2afa32012-07-19 14:53:05 -0700833 // Restore the previous launcher state
834 if (mOnResumeState == State.WORKSPACE) {
835 showWorkspace(false);
836 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700837 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700838 }
839 mOnResumeState = State.NONE;
840
Craig Mautner360310b2012-10-26 15:13:08 -0700841 // Background was set to gradient in onPause(), restore to black if in all apps.
842 setWorkspaceBackground(mState == State.WORKSPACE);
843
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800844 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700845 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700846 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400847 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700848 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400849 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700850 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800851 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700852 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200853 // We might have postponed some bind calls until onResume (see waitUntilResume) --
854 // execute them here
855 long startTimeCallbacks = 0;
856 if (DEBUG_RESUME_TIME) {
857 startTimeCallbacks = System.currentTimeMillis();
858 }
859
860 if (mAppsCustomizeContent != null) {
861 mAppsCustomizeContent.setBulkBind(true);
862 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700863 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
864 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200865 }
866 if (mAppsCustomizeContent != null) {
867 mAppsCustomizeContent.setBulkBind(false);
868 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700869 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200870 if (DEBUG_RESUME_TIME) {
871 Log.d(TAG, "Time spent processing callbacks in onResume: " +
872 (System.currentTimeMillis() - startTimeCallbacks));
873 }
Michael Jurka447bf842013-05-15 14:52:15 +0200874 }
Michael Jurka54554252013-08-01 12:52:23 +0200875 if (mOnResumeCallbacks.size() > 0) {
876 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
877 mOnResumeCallbacks.get(i).run();
878 }
879 mOnResumeCallbacks.clear();
880 }
Winson Chunge4e50662012-01-23 14:45:13 -0800881
882 // Reset the pressed state of icons that were locked in the press state while activities
883 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800884 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800885 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800886 mWaitingForResume.setStayPressed(false);
887 }
Winson Chunge4e50662012-01-23 14:45:13 -0800888 if (mAppsCustomizeContent != null) {
889 // Resets the previous all apps icon press state
890 mAppsCustomizeContent.resetDrawableState();
891 }
Winson Chung780fe592013-09-26 14:48:44 -0700892 // Reset AllApps to its initial state
893 if (mAppsCustomizeTabHost != null) {
894 mAppsCustomizeTabHost.reset();
895 }
Adam Cohen06dff352012-06-01 17:17:08 -0700896 // It is possible that widgets can receive updates while launcher is not in the foreground.
897 // Consequently, the widgets will be inflated in the orientation of the foreground activity
898 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
899 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700900 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700901
Winson Chung780fe592013-09-26 14:48:44 -0700902 // Process any items that were added while Launcher was away.
903 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
904
Winson Chung5841efa2013-09-30 18:06:44 -0700905 // Update the voice search button proxy
906 updateVoiceButtonProxyVisible(false);
907
Adam Cohenf9426d52012-06-04 17:26:21 -0700908 // Again, as with the above scenario, it's possible that one or more of the global icons
909 // were updated in the wrong orientation.
910 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200911 if (DEBUG_RESUME_TIME) {
912 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
913 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700914
915 if (mWorkspace.getCustomContentCallbacks() != null) {
916 // If we are resuming and the custom content is the current page, we call onShow().
917 // It is also poassible that onShow will instead be called slightly after first layout
918 // if PagedView#setRestorePage was set to the custom content page in onCreate().
919 if (mWorkspace.isOnOrMovingToCustomContent()) {
920 mWorkspace.getCustomContentCallbacks().onShow();
921 }
922 }
923
Adam Cohenedaaa302013-10-01 17:33:27 -0700924 mWorkspace.updateInteractionForState();
Adam Cohen06dff352012-06-01 17:17:08 -0700925 }
926
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800927 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700928 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700929 // Ensure that items added to Launcher are queued until Launcher returns
930 InstallShortcutReceiver.enableInstallQueue();
931
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700932 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700933 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800934 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700935 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700936
937 // We call onHide() aggressively. The custom content callbacks should be able to
938 // debounce excess onHide calls.
939 if (mWorkspace.getCustomContentCallbacks() != null) {
940 mWorkspace.getCustomContentCallbacks().onHide();
941 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700942 }
Romain Guycbb89e42009-06-08 15:52:54 -0700943
Adam Cohen66a01fd2013-06-11 12:48:00 -0700944 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700945 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600946 addCustomContentToLeft();
947 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700948 }
949
Adam Cohenbffe7452013-07-22 18:21:45 -0700950 QSBScroller mQsbScroller = new QSBScroller() {
951 int scrollY = 0;
952
953 @Override
954 public void setScrollY(int scroll) {
955 scrollY = scroll;
956
957 if (mWorkspace.isOnOrMovingToCustomContent()) {
958 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100959 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700960 }
961 }
962 };
963
964 public void resetQSBScroll() {
965 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100966 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700967 }
968
969 public interface CustomContentCallbacks {
970 // Custom content is completely shown
971 public void onShow();
972
973 // Custom content is completely hidden
974 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700975
976 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
977 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700978 }
979
Adam Cohen30bacb22013-08-29 14:25:25 -0700980 protected void startSettings() {
981 }
982
Adam Cohenbffe7452013-07-22 18:21:45 -0700983 public interface QSBScroller {
984 public void setScrollY(int scrollY);
985 }
986
Adam Cohen66a01fd2013-06-11 12:48:00 -0700987 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700988 public QSBScroller addToCustomContentPage(View customContent) {
989 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700990 }
991
Winson Chung98ca0f72013-07-29 12:58:51 -0700992 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700993 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700994 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700995 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700996 }
997
Adam Cohenedb40762013-07-18 16:45:45 -0700998 // The custom content needs to offset its content to account for the QSB
999 public int getTopOffsetForCustomContent() {
1000 return mWorkspace.getPaddingTop();
1001 }
1002
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001003 @Override
1004 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001005 // Flag the loader to stop early before switching
1006 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001007 if (mAppsCustomizeContent != null) {
1008 mAppsCustomizeContent.surrender();
1009 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001010 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001011 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001012
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001013 // We can't hide the IME if it was forced open. So don't bother
1014 /*
1015 @Override
1016 public void onWindowFocusChanged(boolean hasFocus) {
1017 super.onWindowFocusChanged(hasFocus);
1018
1019 if (hasFocus) {
1020 final InputMethodManager inputManager = (InputMethodManager)
1021 getSystemService(Context.INPUT_METHOD_SERVICE);
1022 WindowManager.LayoutParams lp = getWindow().getAttributes();
1023 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1024 android.os.Handler()) {
1025 protected void onReceiveResult(int resultCode, Bundle resultData) {
1026 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1027 }
1028 });
1029 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1030 }
1031 }
1032 */
1033
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001034 private boolean acceptFilter() {
1035 final InputMethodManager inputManager = (InputMethodManager)
1036 getSystemService(Context.INPUT_METHOD_SERVICE);
1037 return !inputManager.isFullscreenMode();
1038 }
1039
1040 @Override
1041 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001042 final int uniChar = event.getUnicodeChar();
1043 final boolean handled = super.onKeyDown(keyCode, event);
1044 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1045 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1047 keyCode, event);
1048 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001049 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001050 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001051 // showSearchDialog()
1052 // If there are multiple keystrokes before the search dialog takes focus,
1053 // onSearchRequested() will be called for every keystroke,
1054 // but it is idempotent, so it's fine.
1055 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001056 }
1057 }
1058
Joe Onorato8a9625e2010-01-28 15:55:35 -08001059 // Eat the long press event so the keyboard doesn't come up.
1060 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1061 return true;
1062 }
1063
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001064 return handled;
1065 }
1066
Karl Rosaen138a0412009-04-23 19:00:21 -07001067 private String getTypedText() {
1068 return mDefaultKeySsb.toString();
1069 }
1070
1071 private void clearTypedText() {
1072 mDefaultKeySsb.clear();
1073 mDefaultKeySsb.clearSpans();
1074 Selection.setSelection(mDefaultKeySsb, 0);
1075 }
1076
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001078 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1079 * State
1080 */
1081 private static State intToState(int stateOrdinal) {
1082 State state = State.WORKSPACE;
1083 final State[] stateValues = State.values();
1084 for (int i = 0; i < stateValues.length; i++) {
1085 if (stateValues[i].ordinal() == stateOrdinal) {
1086 state = stateValues[i];
1087 break;
1088 }
1089 }
1090 return state;
1091 }
1092
1093 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 * Restores the previous state, if it exists.
1095 *
1096 * @param savedState The previous state.
1097 */
1098 private void restoreState(Bundle savedState) {
1099 if (savedState == null) {
1100 return;
1101 }
1102
Michael Jurka883f55b2010-10-21 15:47:14 -07001103 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001104 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001105 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001106 }
1107
Winson Chungf0c6ae02012-03-21 16:10:31 -07001108 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001109 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001110 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 }
1112
Winson Chung3d503fb2011-07-13 17:25:49 -07001113 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001114 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001115
Winson Chung3d503fb2011-07-13 17:25:49 -07001116 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1117 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001118 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001119 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1120 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001121 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1122 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1123 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001124 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125 mRestoring = true;
1126 }
1127
1128 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1129 if (renameFolder) {
1130 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001131 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132 mRestoring = true;
1133 }
Winson Chunga12a2502010-12-20 14:41:35 -08001134
Winson Chung785d2eb2011-04-14 16:08:02 -07001135 // Restore the AppsCustomize tab
1136 if (mAppsCustomizeTabHost != null) {
1137 String curTab = savedState.getString("apps_customize_currentTab");
1138 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001139 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001140 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001141 mAppsCustomizeContent.loadAssociatedPages(
1142 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001143 }
1144
Winson Chung5afbf7b2011-07-25 11:53:08 -07001145 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1146 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001147 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148 }
1149
1150 /**
1151 * Finds all the views we need and configure them properly.
1152 */
1153 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001154 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001155
Craig Mautner360310b2012-10-26 15:13:08 -07001156 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001157 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1158 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001159
John Spurlock77e1f472013-09-11 10:09:51 -04001160 mLauncherView.setSystemUiVisibility(
1161 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001162 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163
Winson Chung4c98d922011-05-31 16:50:48 -07001164 // Setup the drag layer
1165 mDragLayer.setup(this, dragController);
1166
Winson Chung3d503fb2011-07-13 17:25:49 -07001167 // Setup the hotseat
1168 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1169 if (mHotseat != null) {
1170 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001171 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001172 }
1173
Adam Cohenf358a4b2013-07-23 16:47:31 -07001174 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001175 View widgetButton = findViewById(R.id.widget_button);
1176 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001177 @Override
1178 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001179 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001180 }
1181 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001182 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1183
1184 View wallpaperButton = findViewById(R.id.wallpaper_button);
1185 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001186 @Override
1187 public void onClick(View arg0) {
1188 startWallpaper();
1189 }
1190 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001191 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1192
1193 View settingsButton = findViewById(R.id.settings_button);
1194 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001195 @Override
1196 public void onClick(View arg0) {
1197 startSettings();
1198 }
1199 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001200 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001201 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001202
Winson Chung4c98d922011-05-31 16:50:48 -07001203 // Setup the workspace
1204 mWorkspace.setHapticFeedbackEnabled(false);
1205 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001206 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001207 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001208
Winson Chungf0ea4d32011-06-06 14:27:16 -07001209 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001210 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001211
Winson Chungf0ea4d32011-06-06 14:27:16 -07001212 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001213 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001214 mAppsCustomizeContent = (AppsCustomizePagedView)
1215 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1216 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001217
Winson Chung3d503fb2011-07-13 17:25:49 -07001218 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001219 dragController.setDragScoller(mWorkspace);
1220 dragController.setScrollView(mDragLayer);
1221 dragController.setMoveTarget(mWorkspace);
1222 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001223 if (mSearchDropTargetBar != null) {
1224 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001225 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001226
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001227 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001228 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001229 mWeightWatcher = new WeightWatcher(this);
1230 mWeightWatcher.setAlpha(0.5f);
1231 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001232 new FrameLayout.LayoutParams(
1233 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001234 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001235 Gravity.BOTTOM)
1236 );
Adam Cohen39a06042013-07-19 14:30:12 -07001237
1238 boolean show = shouldShowWeightWatcher();
1239 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001240 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 }
1242
1243 /**
1244 * Creates a view representing a shortcut.
1245 *
1246 * @param info The data structure describing the shortcut.
1247 *
1248 * @return A View inflated from R.layout.application.
1249 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001250 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001252 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 }
1254
1255 /**
1256 * Creates a view representing a shortcut inflated from the specified resource.
1257 *
1258 * @param layoutResId The id of the XML layout used to create the shortcut.
1259 * @param parent The group the shortcut belongs to.
1260 * @param info The data structure describing the shortcut.
1261 *
1262 * @return A View inflated from layoutResId.
1263 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001264 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001265 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1266 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 return favorite;
1269 }
1270
1271 /**
1272 * Add an application shortcut to the workspace.
1273 *
1274 * @param data The intent describing the application.
1275 * @param cellInfo The position on screen where to create the shortcut.
1276 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001277 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001278 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001279 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001280
Adam Cohenfbba09b2011-07-18 21:43:05 -07001281 // First we check if we already know the exact location where we want to add this item.
1282 if (cellX >= 0 && cellY >= 0) {
1283 cellXY[0] = cellX;
1284 cellXY[1] = cellY;
1285 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001286 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001287 return;
1288 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001290 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001291
Romain Guy73b979d2009-06-09 12:57:21 -07001292 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001293 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001294 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001295 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001296 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001297 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001298 } else {
1299 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 }
1301 }
Romain Guycbb89e42009-06-08 15:52:54 -07001302
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303 /**
1304 * Add a shortcut to the workspace.
1305 *
1306 * @param data The intent describing the shortcut.
1307 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001309 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001310 int cellY) {
1311 int[] cellXY = mTmpAddItemCellCoordinates;
1312 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001313 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001314
Michael Jurkad3ef3062010-11-23 16:23:58 -08001315 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001316
Adam Cohen558baaf2011-08-15 15:22:57 -07001317 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001318 if (info == null) {
1319 return;
1320 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001321 final View view = createShortcut(info);
1322
Adam Cohenfbba09b2011-07-18 21:43:05 -07001323 // First we check if we already know the exact location where we want to add this item.
1324 if (cellX >= 0 && cellY >= 0) {
1325 cellXY[0] = cellX;
1326 cellXY[1] = cellY;
1327 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001328
1329 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001330 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001331 true, null,null)) {
1332 return;
1333 }
1334 DragObject dragObject = new DragObject();
1335 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001336 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1337 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001338 return;
1339 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001340 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001341 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001342 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001343 foundCellSpan = (result != null);
1344 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001345 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001346 }
1347
1348 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001349 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001350 return;
1351 }
1352
Adam Cohendcd297f2013-06-18 13:13:40 -07001353 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354
1355 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001356 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001357 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 }
1359 }
1360
Adam Cohen2f093b62012-04-30 18:59:53 -07001361 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1362 int minHeight) {
1363 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001364 // We want to account for the extra amount of padding that we are adding to the widget
1365 // to ensure that it gets the full amount of space that it has requested
1366 int requiredWidth = minWidth + padding.left + padding.right;
1367 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001368 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001369 }
1370
Adam Cohen2f093b62012-04-30 18:59:53 -07001371 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1372 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001373 }
1374
Adam Cohen2f093b62012-04-30 18:59:53 -07001375 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1376 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001377 }
1378
Adam Cohen2f093b62012-04-30 18:59:53 -07001379 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1380 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001381 }
1382
Adam Cohen2f093b62012-04-30 18:59:53 -07001383 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1384 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001385 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001386 }
1387
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001389 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001390 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001391 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001392 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001394 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001395 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1396 if (appWidgetInfo == null) {
1397 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1398 }
Romain Guycbb89e42009-06-08 15:52:54 -07001399
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001400 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001401 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001402
Adam Cohen2f093b62012-04-30 18:59:53 -07001403 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1404 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001405
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001406 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001407 // We have saved the position to which the widget was dragged-- this really only matters
1408 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001409 int[] cellXY = mTmpAddItemCellCoordinates;
1410 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001411 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001413 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1414 cellXY[0] = mPendingAddInfo.cellX;
1415 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001416 spanXY[0] = mPendingAddInfo.spanX;
1417 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001418 foundCellSpan = true;
1419 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001420 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001421 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001422 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1423 spanXY[1], cellXY, finalSpan);
1424 spanXY[0] = finalSpan[0];
1425 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001426 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001427 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001428 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001429 }
1430
Michael Jurka0280c3b2010-09-17 15:00:07 -07001431 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001432 if (appWidgetId != -1) {
1433 // Deleting an app widget ID is a void call but writes to disk before returning
1434 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001435 new Thread("deleteAppWidgetId") {
1436 public void run() {
1437 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1438 }
1439 }.start();
1440 }
Winson Chung93eef082012-03-23 15:59:27 -07001441 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001442 return;
1443 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001445 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001446 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1447 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001448 launcherInfo.spanX = spanXY[0];
1449 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001450 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1451 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001452
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001454 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455
1456 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001457 if (hostView == null) {
1458 // Perform actual inflation because we're live
1459 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1460 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1461 } else {
1462 // The AppWidgetHostView has already been inflated and instantiated
1463 launcherInfo.hostView = hostView;
1464 }
Romain Guycbb89e42009-06-08 15:52:54 -07001465
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001467 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001468 launcherInfo.notifyWidgetSizeChanged(this);
1469
Adam Cohendcd297f2013-06-18 13:13:40 -07001470 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001471 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001472
1473 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001475 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 }
Romain Guycbb89e42009-06-08 15:52:54 -07001477
Adam Cohended9f8d2010-11-03 13:25:16 -07001478 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1479 @Override
1480 public void onReceive(Context context, Intent intent) {
1481 final String action = intent.getAction();
1482 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1483 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001484 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001485 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001486
Winson Chungc100e8e2011-08-09 16:02:43 -07001487 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001488 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001489 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001490 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001491 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001492 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1493 mUserPresent = true;
1494 updateRunning();
1495 }
1496 }
1497 };
1498
1499 @Override
1500 public void onAttachedToWindow() {
1501 super.onAttachedToWindow();
1502
1503 // Listen for broadcasts related to user-presence
1504 final IntentFilter filter = new IntentFilter();
1505 filter.addAction(Intent.ACTION_SCREEN_OFF);
1506 filter.addAction(Intent.ACTION_USER_PRESENT);
1507 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001508 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001509 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001510 mVisible = true;
1511 }
1512
1513 @Override
1514 public void onDetachedFromWindow() {
1515 super.onDetachedFromWindow();
1516 mVisible = false;
1517
Adam Cohend113e0c2010-11-11 10:48:05 -08001518 if (mAttached) {
1519 unregisterReceiver(mReceiver);
1520 mAttached = false;
1521 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001522 updateRunning();
1523 }
1524
1525 public void onWindowVisibilityChanged(int visibility) {
1526 mVisible = visibility == View.VISIBLE;
1527 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001528 // The following code used to be in onResume, but it turns out onResume is called when
1529 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1530 // is a more appropriate event to handle
1531 if (mVisible) {
1532 mAppsCustomizeTabHost.onWindowVisible();
1533 if (!mWorkspaceLoading) {
1534 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001535 // We want to let Launcher draw itself at least once before we force it to build
1536 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001537 // apps is nice and speedy.
1538 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001539 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001540 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001541 if (mStarted) return;
1542 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001543 // We delay the layer building a bit in order to give
1544 // other message processing a time to run. In particular
1545 // this avoids a delay in hiding the IME if it was
1546 // currently shown, because doing that may involve
1547 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001548 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001549 final ViewTreeObserver.OnDrawListener listener = this;
1550 mWorkspace.post(new Runnable() {
1551 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001552 if (mWorkspace != null &&
1553 mWorkspace.getViewTreeObserver() != null) {
1554 mWorkspace.getViewTreeObserver().
1555 removeOnDrawListener(listener);
1556 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001557 }
1558 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001559 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001560 }
1561 });
1562 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001563 // When Launcher comes back to foreground, a different Activity might be responsible for
1564 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001565 if (!DISABLE_MARKET_BUTTON) {
1566 updateAppMarketIcon();
1567 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001568 clearTypedText();
1569 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001570 }
1571
1572 private void sendAdvanceMessage(long delay) {
1573 mHandler.removeMessages(ADVANCE_MSG);
1574 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1575 mHandler.sendMessageDelayed(msg, delay);
1576 mAutoAdvanceSentTime = System.currentTimeMillis();
1577 }
1578
1579 private void updateRunning() {
1580 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1581 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1582 mAutoAdvanceRunning = autoAdvanceRunning;
1583 if (autoAdvanceRunning) {
1584 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1585 sendAdvanceMessage(delay);
1586 } else {
1587 if (!mWidgetsToAdvance.isEmpty()) {
1588 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1589 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1590 }
1591 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001592 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001593 }
1594 }
1595 }
1596
1597 private final Handler mHandler = new Handler() {
1598 @Override
1599 public void handleMessage(Message msg) {
1600 if (msg.what == ADVANCE_MSG) {
1601 int i = 0;
1602 for (View key: mWidgetsToAdvance.keySet()) {
1603 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1604 final int delay = mAdvanceStagger * i;
1605 if (v instanceof Advanceable) {
1606 postDelayed(new Runnable() {
1607 public void run() {
1608 ((Advanceable) v).advance();
1609 }
1610 }, delay);
1611 }
1612 i++;
1613 }
1614 sendAdvanceMessage(mAdvanceInterval);
1615 }
1616 }
1617 };
1618
1619 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001620 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001621 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1622 if (v instanceof Advanceable) {
1623 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001624 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001625 updateRunning();
1626 }
1627 }
1628
1629 void removeWidgetToAutoAdvance(View hostView) {
1630 if (mWidgetsToAdvance.containsKey(hostView)) {
1631 mWidgetsToAdvance.remove(hostView);
1632 updateRunning();
1633 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001634 }
1635
Joe Onorato9c1289c2009-08-17 11:03:03 -04001636 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001637 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001638 launcherInfo.hostView = null;
1639 }
1640
Winson Chung93eef082012-03-23 15:59:27 -07001641 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1642 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1643 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001644 }
1645
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001646 public LauncherAppWidgetHost getAppWidgetHost() {
1647 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001648 }
Romain Guycbb89e42009-06-08 15:52:54 -07001649
Winson Chunga9abd0e2010-10-27 17:18:37 -07001650 public LauncherModel getModel() {
1651 return mModel;
1652 }
1653
Bjorn Bringertc459e522013-06-07 19:36:01 +01001654 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001655 getWindow().closeAllPanels();
1656
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001657 // Whatever we were doing is hereby canceled.
1658 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001659 }
1660
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001661 @Override
1662 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001663 long startTime = 0;
1664 if (DEBUG_RESUME_TIME) {
1665 startTime = System.currentTimeMillis();
1666 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001667 super.onNewIntent(intent);
1668
1669 // Close the menu
1670 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001671 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001672 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001673
Jamie Genniscb222e82012-10-23 15:44:26 -07001674 final boolean alreadyOnHome =
1675 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001676 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001677
Adam Cohen6fecd412013-10-02 17:41:50 -07001678 if (mWorkspace == null) {
1679 // Can be cases where mWorkspace is null, this prevents a NPE
1680 return;
1681 }
1682 Folder openFolder = mWorkspace.getOpenFolder();
1683 // In all these cases, only animate if we're already on home
1684 mWorkspace.exitWidgetResizeMode();
1685 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1686 openFolder == null) {
1687 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001688 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001689
Adam Cohen6fecd412013-10-02 17:41:50 -07001690 closeFolder();
1691 exitSpringLoadedDragMode();
1692
1693 // If we are already on home, then just animate back to the workspace,
1694 // otherwise, just wait until onResume to set the state back to Workspace
1695 if (alreadyOnHome) {
1696 showWorkspaceAndExitOverviewMode(true);
1697 } else {
1698 mOnResumeState = State.WORKSPACE;
1699 }
1700
1701 final View v = getWindow().peekDecorView();
1702 if (v != null && v.getWindowToken() != null) {
1703 InputMethodManager imm = (InputMethodManager)getSystemService(
1704 INPUT_METHOD_SERVICE);
1705 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1706 }
1707
1708 // Reset the apps customize page
1709 if (mAppsCustomizeTabHost != null) {
1710 mAppsCustomizeTabHost.reset();
1711 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 }
Michael Jurka447bf842013-05-15 14:52:15 +02001713 if (DEBUG_RESUME_TIME) {
1714 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1715 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716 }
1717
Adam Cohen040a5d22013-09-16 17:09:33 -07001718 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1719 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001720 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001721 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001722 }
1723 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001724 protected void showWorkspaceAndExitOverviewMode() {
Allan Wojciechowskifdc43022013-10-02 11:13:17 -04001725 showWorkspaceAndExitOverviewMode(false);
Adam Cohen040a5d22013-09-16 17:09:33 -07001726 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001727
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001729 public void onRestoreInstanceState(Bundle state) {
1730 super.onRestoreInstanceState(state);
1731 for (int page: mSynchronouslyBoundPages) {
1732 mWorkspace.restoreInstanceStateForChild(page);
1733 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001734 }
1735
1736 @Override
1737 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001738 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001739 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740
Michael Jurka883f55b2010-10-21 15:47:14 -07001741 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001742 // We close any open folder since it will not be re-opened, and we need to make sure
1743 // this state is reflected.
1744 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001745
Adam Cohendcd297f2013-06-18 13:13:40 -07001746 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001747 mWaitingForResult) {
1748 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001749 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001750 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1751 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001752 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1753 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1754 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001755 }
1756
1757 if (mFolderInfo != null && mWaitingForResult) {
1758 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1759 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1760 }
Michael Jurka946ad472010-07-09 18:05:18 -07001761
Winson Chung785d2eb2011-04-14 16:08:02 -07001762 // Save the current AppsCustomize tab
1763 if (mAppsCustomizeTabHost != null) {
1764 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1765 if (currentTabTag != null) {
1766 outState.putString("apps_customize_currentTab", currentTabTag);
1767 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001768 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1769 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001770 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001771 }
1772
1773 @Override
1774 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001776
Winson Chunge7a03942011-08-05 15:05:12 -07001777 // Remove all pending runnables
1778 mHandler.removeMessages(ADVANCE_MSG);
1779 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001780 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001781
Winson Chungcd2b0142011-06-08 16:02:26 -07001782 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001783 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001784 mModel.stopLoader();
1785 app.setLauncher(null);
1786
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001787 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001788 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001790 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001792 mAppWidgetHost = null;
1793
1794 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795
1796 TextKeyListener.getInstance().release();
1797
Winson Chung81b52252012-08-27 15:34:29 -07001798 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1799 // to prevent leaking Launcher activities on orientation change.
1800 if (mModel != null) {
1801 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1802 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001803
1804 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001805 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001806
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001807 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001808 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1809 mWorkspace.removeAllViews();
1810 mWorkspace = null;
1811 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001812
Michael Jurka2ecf9952012-06-18 12:52:28 -07001813 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 }
1815
Adam Cohena9cf38f2011-05-02 15:36:58 -07001816 public DragController getDragController() {
1817 return mDragController;
1818 }
1819
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 @Override
1821 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001822 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 super.startActivityForResult(intent, requestCode);
1824 }
1825
Winson Chung70d72102011-08-12 11:24:35 -07001826 /**
1827 * Indicates that we want global search for this activity by setting the globalSearch
1828 * argument for {@link #startSearch} to true.
1829 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001831 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001833
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001834 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001835
Karl Rosaen138a0412009-04-23 19:00:21 -07001836 if (initialQuery == null) {
1837 // Use any text typed in the launcher as the initial query
1838 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001839 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001840 if (appSearchData == null) {
1841 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001842 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843 }
Winson Chungadf0c182012-08-23 14:59:07 -07001844 Rect sourceBounds = new Rect();
1845 if (mSearchDropTargetBar != null) {
1846 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1847 }
Romain Guycbb89e42009-06-08 15:52:54 -07001848
Bjorn Bringertc459e522013-06-07 19:36:01 +01001849 startSearch(initialQuery, selectInitialQuery,
1850 appSearchData, sourceBounds);
1851 }
1852
1853 public void startSearch(String initialQuery,
1854 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001855 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001856 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001857 }
1858
1859 /**
1860 * Starts the global search activity. This code is a copied from SearchManager
1861 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001862 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001863 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001864 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001865 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1866 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1867 if (globalSearchActivity == null) {
1868 Log.w(TAG, "No global search activity found.");
1869 return;
1870 }
1871 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1872 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1873 intent.setComponent(globalSearchActivity);
1874 // Make sure that we have a Bundle to put source in
1875 if (appSearchData == null) {
1876 appSearchData = new Bundle();
1877 } else {
1878 appSearchData = new Bundle(appSearchData);
1879 }
1880 // Set source to package name of app that starts global search, if not set already.
1881 if (!appSearchData.containsKey("source")) {
1882 appSearchData.putString("source", getPackageName());
1883 }
1884 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1885 if (!TextUtils.isEmpty(initialQuery)) {
1886 intent.putExtra(SearchManager.QUERY, initialQuery);
1887 }
1888 if (selectInitialQuery) {
1889 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1890 }
1891 intent.setSourceBounds(sourceBounds);
1892 try {
1893 startActivity(intent);
1894 } catch (ActivityNotFoundException ex) {
1895 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1896 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 }
1898
Winson Chung70d72102011-08-12 11:24:35 -07001899 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001900 public boolean onPrepareOptionsMenu(Menu menu) {
1901 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001902 if (!mWorkspace.isInOverviewMode()) {
1903 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001904 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001905 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001906 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001907
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001908 @Override
1909 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001910 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001911 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001912 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001913 }
1914
Joe Onorato9c1289c2009-08-17 11:03:03 -04001915 public boolean isWorkspaceLocked() {
1916 return mWorkspaceLoading || mWaitingForResult;
1917 }
1918
Michael Jurka0280c3b2010-09-17 15:00:07 -07001919 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001920 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001921 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001922 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1923 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001924 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001925 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001926 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001927
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001928 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1929 AppWidgetProviderInfo appWidgetInfo) {
1930 if (appWidgetInfo.configure != null) {
1931 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001932
Bjorn Bringert7984c942009-12-09 15:38:25 +00001933 // Launch over to configure widget, if needed
1934 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001935 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001936 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001937 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001938 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001939 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001940 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001941 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001942 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001943 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 }
1945 }
Romain Guycbb89e42009-06-08 15:52:54 -07001946
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001947 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001948 // Close any folders that may be open.
1949 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001950 mWorkspace.moveToCustomContentScreen(animate);
1951 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001952 /**
1953 * Process a shortcut drop.
1954 *
1955 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001957 * @param cell The cell it should be added to, optional
1958 * @param position The location on the screen where it was dropped, optional
1959 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001960 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001961 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001962 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001964 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001966
1967 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001968 mPendingAddInfo.cellX = cell[0];
1969 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001970 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001971
1972 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1973 createShortcutIntent.setComponent(componentName);
1974 processShortcut(createShortcutIntent);
1975 }
1976
Adam Cohenfbba09b2011-07-18 21:43:05 -07001977 /**
1978 * Process a widget drop.
1979 *
1980 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001981 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001982 * @param cell The cell it should be added to, optional
1983 * @param position The location on the screen where it was dropped, optional
1984 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001985 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001986 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001987 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001988 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001989 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001990 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001991 mPendingAddInfo.minSpanX = info.minSpanX;
1992 mPendingAddInfo.minSpanY = info.minSpanY;
1993
Adam Cohenfbba09b2011-07-18 21:43:05 -07001994 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001995 mPendingAddInfo.cellX = cell[0];
1996 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001997 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001998 if (span != null) {
1999 mPendingAddInfo.spanX = span[0];
2000 mPendingAddInfo.spanY = span[1];
2001 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002002
Adam Cohened66b2b2012-01-23 17:28:51 -08002003 AppWidgetHostView hostView = info.boundWidget;
2004 int appWidgetId;
2005 if (hostView != null) {
2006 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002007 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002008 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002009 // In this case, we either need to start an activity to get permission to bind
2010 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002011 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002012 Bundle options = info.bindOptions;
2013
2014 boolean success = false;
2015 if (options != null) {
2016 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2017 info.componentName, options);
2018 } else {
2019 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2020 info.componentName);
2021 }
2022 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002023 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002024 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002025 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002026 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2027 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2028 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002029 // TODO: we need to make sure that this accounts for the options bundle.
2030 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002031 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2032 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002033 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002034 }
2035
Joe Onoratodeb98af2010-02-19 14:59:39 -08002036 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002037 // Handle case where user selected "Applications"
2038 String applicationName = getResources().getString(R.string.group_applications);
2039 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002040
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002041 if (applicationName != null && applicationName.equals(shortcutName)) {
2042 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2043 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002044
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002045 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2046 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002047 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002048 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002049 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002050 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002051 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 }
2053
Winson Chung24ab2f12010-09-16 14:10:47 -07002054 void processWallpaper(Intent intent) {
2055 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2056 }
2057
Adam Cohendcd297f2013-06-18 13:13:40 -07002058 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002059 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002060 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 folderInfo.title = getText(R.string.folder_name);
2062
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002064 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002065 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002066 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067
2068 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002069 FolderIcon newFolder =
2070 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002071 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002072 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002073 // Force measure the new folder icon
2074 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2075 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002076 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 }
Romain Guycbb89e42009-06-08 15:52:54 -07002078
Joe Onorato9c1289c2009-08-17 11:03:03 -04002079 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002080 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002081 }
2082
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002083 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002084 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002085 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002086 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002087 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002088 }
2089
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002090 protected ComponentName getWallpaperPickerComponent() {
2091 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2092 }
2093
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002094 /**
2095 * Registers various content observers. The current implementation registers
2096 * only a favorites observer to keep track of the favorites applications.
2097 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002098 private void registerContentObservers() {
2099 ContentResolver resolver = getContentResolver();
2100 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2101 true, mWidgetObserver);
2102 }
2103
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002104 @Override
2105 public boolean dispatchKeyEvent(KeyEvent event) {
2106 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2107 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002108 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002109 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002110 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002111 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002112 dumpState();
2113 return true;
2114 }
2115 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002116 }
2117 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2118 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002119 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 return true;
2121 }
2122 }
2123
2124 return super.dispatchKeyEvent(event);
2125 }
2126
Joe Onorato88ec0992009-11-19 13:16:06 -08002127 @Override
2128 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002129 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002130 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002131 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002132 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002133 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002134 Folder openFolder = mWorkspace.getOpenFolder();
2135 if (openFolder.isEditingName()) {
2136 openFolder.dismissEditingName();
2137 } else {
2138 closeFolder();
2139 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002140 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002141 mWorkspace.exitWidgetResizeMode();
2142
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002143 // Back button is a no-op here, but give at least some feedback for the button press
2144 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002145 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002146 }
2147
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002148 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002149 * Re-listen when widgets are reset.
2150 */
2151 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002152 if (mAppWidgetHost != null) {
2153 mAppWidgetHost.startListening();
2154 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002155 }
2156
2157 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158 * Launches the intent referred by the clicked shortcut.
2159 *
2160 * @param v The view representing the clicked shortcut.
2161 */
2162 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002163 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2164 // view has detached (it's possible for this to happen if the view is removed mid touch).
2165 if (v.getWindowToken() == null) {
2166 return;
2167 }
2168
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002169 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002170 return;
2171 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002172
Adam Cohen1697b792013-09-17 19:08:21 -07002173 if (v instanceof Workspace) {
2174 if (mWorkspace.isInOverviewMode()) {
2175 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002176 }
2177 return;
2178 }
2179
2180 if (v instanceof CellLayout) {
2181 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002182 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002183 }
2184 }
2185
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002186 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002187 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002189 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2190 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002191
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002192 // Check for special shortcuts
2193 if (intent.getComponent() != null) {
2194 final String shortcutClass = intent.getComponent().getClassName();
2195
2196 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002197 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002198 return;
2199 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2200 MemoryDumpActivity.startDump(this);
2201 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002202 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2203 toggleShowWeightWatcher();
2204 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002205 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002206 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002207
2208 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002209 int[] pos = new int[2];
2210 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002211 intent.setSourceBounds(new Rect(pos[0], pos[1],
2212 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002213
2214 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002215
Daniel Sandlerff02d492013-08-05 02:12:05 -04002216 mStats.recordLaunch(intent, shortcut);
2217
Michael Jurkaddd62e92011-02-16 17:49:14 -08002218 if (success && v instanceof BubbleTextView) {
2219 mWaitingForResume = (BubbleTextView) v;
2220 mWaitingForResume.setStayPressed(true);
2221 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002222 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002223 if (v instanceof FolderIcon) {
2224 FolderIcon fi = (FolderIcon) v;
2225 handleFolderClick(fi);
2226 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002227 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002228 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002229 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002230 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002231 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002232 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002233 }
2234 }
2235
Michael Jurka0e260592010-06-30 17:07:39 -07002236 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002237 return false;
2238 }
2239
Michael Jurkaaf442092010-06-10 17:01:57 -07002240 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002241 * Event handler for the search button
2242 *
2243 * @param v The view that was clicked.
2244 */
2245 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002246 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2247
Amith Yamasania135ba82011-08-09 17:42:01 -07002248 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002249 }
2250
2251 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002252 * Event handler for the voice button
2253 *
2254 * @param v The view that was clicked.
2255 */
2256 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002257 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002258
Bjorn Bringertc459e522013-06-07 19:36:01 +01002259 startVoice();
2260 }
2261
2262 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002263 try {
2264 final SearchManager searchManager =
2265 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2266 ComponentName activityName = searchManager.getGlobalSearchActivity();
2267 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002268 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002269 if (activityName != null) {
2270 intent.setPackage(activityName.getPackageName());
2271 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002272 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002273 } catch (ActivityNotFoundException e) {
2274 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002275 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002276 startActivitySafely(null, intent, "onClickVoiceButton");
2277 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002278 }
2279
2280 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002281 * Event handler for the "grid" button that appears on the home screen, which
2282 * enters all apps mode.
2283 *
2284 * @param v The view that was clicked.
2285 */
2286 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002287 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002288 }
2289
2290 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002291 // Provide the same haptic feedback that the system offers for virtual keys.
2292 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002293 }
2294
Adam Cohen61f560d2013-09-30 15:58:20 -07002295 public void performHapticFeedbackOnTouchDown(View v) {
2296 // Provide the same haptic feedback that the system offers for virtual keys.
2297 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2298 }
2299
2300 public View.OnTouchListener getHapticFeedbackTouchListener() {
2301 if (mHapticFeedbackTouchListener == null) {
2302 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2303 @Override
2304 public boolean onTouch(View v, MotionEvent event) {
2305 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2306 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2307 }
2308 return false;
2309 }
2310 };
2311 }
2312 return mHapticFeedbackTouchListener;
2313 }
2314
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002315 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002316 if (!DISABLE_MARKET_BUTTON) {
2317 if (mAppMarketIntent != null) {
2318 startActivitySafely(v, mAppMarketIntent, "app market");
2319 } else {
2320 Log.e(TAG, "Invalid app market intent.");
2321 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002322 }
2323 }
2324
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002325 /**
2326 * Called when the user stops interacting with the launcher.
2327 * This implies that the user is now on the homescreen and is not doing housekeeping.
2328 */
2329 protected void onInteractionEnd() {}
2330
2331 /**
2332 * Called when the user starts interacting with the launcher.
2333 * The possible interactions are:
2334 * - open all apps
2335 * - reorder an app shortcut, or a widget
2336 * - open the overview mode.
2337 * This is a good time to stop doing things that only make sense
2338 * when the user is on the homescreen and not doing housekeeping.
2339 */
2340 protected void onInteractionBegin() {}
2341
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002342 void startApplicationDetailsActivity(ComponentName componentName) {
2343 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002344 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2345 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002346 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002347 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002348 }
2349
Michael Jurka1e2f4652013-07-08 18:03:46 -07002350 // returns true if the activity was started
2351 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002352 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002353 // System applications cannot be installed. For now, show a toast explaining that.
2354 // We may give them the option of disabling apps this way.
2355 int messageId = R.string.uninstall_system_app_text;
2356 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002357 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002358 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002359 String packageName = componentName.getPackageName();
2360 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002361 Intent intent = new Intent(
2362 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002363 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2364 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002365 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002366 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002367 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002368 }
2369
Michael Jurka86a720e2012-05-09 11:23:23 -07002370 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002372
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002374 // Only launch using the new animation if the shortcut has not opted out (this is a
2375 // private contract between launcher and may be ignored in the future).
2376 boolean useLaunchAnimation = (v != null) &&
2377 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2378 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002379 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2380 v.getMeasuredWidth(), v.getMeasuredHeight());
2381
2382 startActivity(intent, opts.toBundle());
2383 } else {
2384 startActivity(intent);
2385 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002386 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 } catch (SecurityException e) {
2388 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002389 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002391 "or use the exported attribute for this activity. "
2392 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002393 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002394 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002395 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002396
Michael Jurka86a720e2012-05-09 11:23:23 -07002397 boolean startActivitySafely(View v, Intent intent, Object tag) {
2398 boolean success = false;
2399 try {
2400 success = startActivity(v, intent, tag);
2401 } catch (ActivityNotFoundException e) {
2402 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2403 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2404 }
2405 return success;
2406 }
2407
Adam Cohena9cf38f2011-05-02 15:36:58 -07002408 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002409 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002410 Folder openFolder = mWorkspace.getFolderForTag(info);
2411
2412 // If the folder info reports that the associated folder is open, then verify that
2413 // it is actually opened. There have been a few instances where this gets out of sync.
2414 if (info.opened && openFolder == null) {
2415 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002416 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002417 info.opened = false;
2418 }
2419
Adam Cohenfb91f302012-06-11 15:45:18 -07002420 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002421 // Close any open folder
2422 closeFolder();
2423 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002424 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002425 } else {
2426 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002427 int folderScreen;
2428 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002429 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430 // .. and close it
2431 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002432 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002433 // Close any folder open on the current screen
2434 closeFolder();
2435 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002436 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002437 }
2438 }
2439 }
2440 }
2441
Adam Cohen268c4752012-06-06 17:47:33 -07002442 /**
2443 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2444 * in the DragLayer in the exact absolute location of the original FolderIcon.
2445 */
2446 private void copyFolderIconToImage(FolderIcon fi) {
2447 final int width = fi.getMeasuredWidth();
2448 final int height = fi.getMeasuredHeight();
2449
2450 // Lazy load ImageView, Bitmap and Canvas
2451 if (mFolderIconImageView == null) {
2452 mFolderIconImageView = new ImageView(this);
2453 }
2454 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2455 mFolderIconBitmap.getHeight() != height) {
2456 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2457 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2458 }
2459
2460 DragLayer.LayoutParams lp;
2461 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2462 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2463 } else {
2464 lp = new DragLayer.LayoutParams(width, height);
2465 }
2466
Adam Cohen307fe232012-08-16 17:55:58 -07002467 // The layout from which the folder is being opened may be scaled, adjust the starting
2468 // view size by this scale factor.
2469 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002470 lp.customPosition = true;
2471 lp.x = mRectForFolderAnimation.left;
2472 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002473 lp.width = (int) (scale * width);
2474 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002475
2476 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2477 fi.draw(mFolderIconCanvas);
2478 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002479 if (fi.getFolder() != null) {
2480 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2481 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002482 }
Adam Cohen268c4752012-06-06 17:47:33 -07002483 // Just in case this image view is still in the drag layer from a previous animation,
2484 // we remove it and re-add it.
2485 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2486 mDragLayer.removeView(mFolderIconImageView);
2487 }
2488 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002489 if (fi.getFolder() != null) {
2490 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002491 }
Adam Cohen268c4752012-06-06 17:47:33 -07002492 }
2493
Adam Cohen2801caf2011-05-13 20:57:39 -07002494 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002495 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002496 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2497 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2498 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2499
Adam Cohenc51934b2011-07-26 21:07:43 -07002500 FolderInfo info = (FolderInfo) fi.getTag();
2501 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2502 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002503 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2504 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002505 }
2506
Adam Cohen268c4752012-06-06 17:47:33 -07002507 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2508 copyFolderIconToImage(fi);
2509 fi.setVisibility(View.INVISIBLE);
2510
Michael Jurka2ecf9952012-06-18 12:52:28 -07002511 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002512 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002513 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2514 oa.start();
2515 }
2516
Adam Cohen268c4752012-06-06 17:47:33 -07002517 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002518 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002519 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2520 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2521 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2522
Adam Cohen268c4752012-06-06 17:47:33 -07002523 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002524
Adam Cohen268c4752012-06-06 17:47:33 -07002525 // We remove and re-draw the FolderIcon in-case it has changed
2526 mDragLayer.removeView(mFolderIconImageView);
2527 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002528 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002529 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002530 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002531 oa.addListener(new AnimatorListenerAdapter() {
2532 @Override
2533 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002534 if (cl != null) {
2535 cl.clearFolderLeaveBehind();
2536 // Remove the ImageView copy of the FolderIcon and make the original visible.
2537 mDragLayer.removeView(mFolderIconImageView);
2538 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002539 }
2540 }
2541 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002542 oa.start();
2543 }
2544
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002545 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002546 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002547 * is animated relative to the specified View. If the View is null, no animation
2548 * is played.
2549 *
2550 * @param folderInfo The FolderInfo describing the folder to open.
2551 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002552 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002553 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002554 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555
Adam Cohena9cf38f2011-05-02 15:36:58 -07002556 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557
Adam Cohen4554ee12011-08-03 16:13:21 -07002558 // Just verify that the folder hasn't already been added to the DragLayer.
2559 // There was a one-off crash where the folder had a parent already.
2560 if (folder.getParent() == null) {
2561 mDragLayer.addView(folder);
2562 mDragController.addDropTarget((DropTarget) folder);
2563 } else {
2564 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2565 folder.getParent() + ").");
2566 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002567 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002568 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002569
2570 // Notify the accessibility manager that this folder "window" has appeared and occluded
2571 // the workspace items
2572 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2573 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002574 }
2575
2576 public void closeFolder() {
2577 Folder folder = mWorkspace.getOpenFolder();
2578 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002579 if (folder.isEditingName()) {
2580 folder.dismissEditingName();
2581 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002582 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002583
2584 // Dismiss the folder cling
2585 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002586 }
2587 }
2588
2589 void closeFolder(Folder folder) {
2590 folder.getInfo().opened = false;
2591
2592 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2593 if (parent != null) {
2594 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2595 shrinkAndFadeInFolderIcon(fi);
2596 }
2597 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002598
2599 // Notify the accessibility manager that this folder "window" has disappeard and no
2600 // longer occludeds the workspace items
2601 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002602 }
2603
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002604 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002605 if (!isDraggingEnabled()) return false;
2606 if (isWorkspaceLocked()) return false;
2607 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002608
Adam Cohen1697b792013-09-17 19:08:21 -07002609 if (v instanceof Workspace) {
2610 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002611 if (mWorkspace.enterOverviewMode()) {
2612 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2613 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2614 return true;
2615 } else {
2616 return false;
2617 }
Adam Cohen1697b792013-09-17 19:08:21 -07002618 }
Adam Cohen1697b792013-09-17 19:08:21 -07002619 }
2620
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002621 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002622 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002623 }
2624
Michael Jurka0280c3b2010-09-17 15:00:07 -07002625 resetAddInfo();
2626 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002627 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002628 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002629 return true;
2630 }
2631
Winson Chung3d503fb2011-07-13 17:25:49 -07002632 // The hotseat touch handling does not go through Workspace, and we always allow long press
2633 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002634 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002635 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2636 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002637 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002638 // User long pressed on empty space
2639 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2640 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2641 // Disabling reordering until we sort out some issues.
2642 if (mWorkspace.isInOverviewMode()) {
2643 mWorkspace.startReordering(v);
2644 } else {
2645 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002646 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002647 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002648 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002649 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002650 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002651 }
2652 }
2653 }
2654 return true;
2655 }
2656
Winson Chung3d503fb2011-07-13 17:25:49 -07002657 boolean isHotseatLayout(View layout) {
2658 return mHotseat != null && layout != null &&
2659 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2660 }
2661 Hotseat getHotseat() {
2662 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002663 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002664 View getOverviewPanel() {
2665 return mOverviewPanel;
2666 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002667 SearchDropTargetBar getSearchBar() {
2668 return mSearchDropTargetBar;
2669 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002670
Winson Chung3d503fb2011-07-13 17:25:49 -07002671 /**
2672 * Returns the CellLayout of the specified container at the specified screen.
2673 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002674 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002675 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2676 if (mHotseat != null) {
2677 return mHotseat.getLayout();
2678 } else {
2679 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002680 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002681 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002682 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002683 }
2684 }
2685
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002686 Workspace getWorkspace() {
2687 return mWorkspace;
2688 }
2689
Daniel Sandler843e8602010-06-07 14:59:01 -04002690 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002691 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002692 }
2693
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002694 /**
2695 * Helper method for the cameraZoomIn/cameraZoomOut animations
2696 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002697 * @param scaleFactor The scale factor used for the zoom
2698 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002699 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002700 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002701 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002702 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002703
Craig Mautner360310b2012-10-26 15:13:08 -07002704 private void setWorkspaceBackground(boolean workspace) {
2705 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002706 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002707 }
2708
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002709 void updateWallpaperVisibility(boolean visible) {
2710 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2711 int curflags = getWindow().getAttributes().flags
2712 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2713 if (wpflags != curflags) {
2714 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2715 }
Craig Mautner360310b2012-10-26 15:13:08 -07002716 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002717 }
2718
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002719 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2720 if (v instanceof LauncherTransitionable) {
2721 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2722 }
2723 }
2724
Michael Jurkabed61d22012-02-14 22:51:29 -08002725 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2726 if (v instanceof LauncherTransitionable) {
2727 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2728 }
Winson Chung70442722012-02-10 15:43:22 -08002729
2730 // Update the workspace transition step as well
2731 dispatchOnLauncherTransitionStep(v, 0f);
2732 }
2733
2734 private void dispatchOnLauncherTransitionStep(View v, float t) {
2735 if (v instanceof LauncherTransitionable) {
2736 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2737 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002738 }
2739
2740 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2741 if (v instanceof LauncherTransitionable) {
2742 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2743 }
Winson Chung70442722012-02-10 15:43:22 -08002744
2745 // Update the workspace transition step as well
2746 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002747 }
2748
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002749 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002750 * Things to test when changing the following seven functions.
2751 * - Home from workspace
2752 * - from center screen
2753 * - from other screens
2754 * - Home from all apps
2755 * - from center screen
2756 * - from other screens
2757 * - Back from all apps
2758 * - from center screen
2759 * - from other screens
2760 * - Launch app from workspace and quit
2761 * - with back
2762 * - with home
2763 * - Launch app from all apps and quit
2764 * - with back
2765 * - with home
2766 * - Go to a screen that's not the default, then all
2767 * apps, and launch and app, and go back
2768 * - with back
2769 * -with home
2770 * - On workspace, long press power and go back
2771 * - with back
2772 * - with home
2773 * - On all apps, long press power and go back
2774 * - with back
2775 * - with home
2776 * - On workspace, power off
2777 * - On all apps, power off
2778 * - Launch an app and turn off the screen while in that app
2779 * - Go back with home key
2780 * - Go back with back key TODO: make this not go to workspace
2781 * - From all apps
2782 * - From workspace
2783 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2784 * - From all apps
2785 * - From the center workspace
2786 * - From another workspace
2787 */
2788
2789 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002790 * Zoom the camera out from the workspace to reveal 'toView'.
2791 * Assumes that the view to show is anchored at either the very top or very bottom
2792 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002793 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002794 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002795 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2796 showAppsCustomizeHelper(animated, springLoaded, contentType);
2797 }
2798 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2799 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002800 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002801 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002802 mStateAnimation.cancel();
2803 mStateAnimation = null;
2804 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002805 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002806
Winson Chungf0ea4d32011-06-06 14:27:16 -07002807 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2808 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2809 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002810 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002811 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002812 final int startDelay =
2813 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002814
Michael Jurkab3e22d92011-10-31 15:58:33 -07002815 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002816
Michael Jurkad74c9842011-07-10 12:44:21 -07002817 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002818 Animator workspaceAnim =
2819 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002820 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2821 // Set the content type for the all apps space
2822 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2823 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002824
2825 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002826 toView.setScaleX(scale);
2827 toView.setScaleY(scale);
2828 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2829 scaleAnim.
2830 scaleX(1f).scaleY(1f).
2831 setDuration(duration).
2832 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002833
Winson Chungf0ea4d32011-06-06 14:27:16 -07002834 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002835 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002836 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002837 .ofFloat(toView, "alpha", 0f, 1f)
2838 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002839 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002840 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2841 @Override
2842 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002843 if (animation == null) {
2844 throw new RuntimeException("animation is null");
2845 }
Winson Chung70442722012-02-10 15:43:22 -08002846 float t = (Float) animation.getAnimatedValue();
2847 dispatchOnLauncherTransitionStep(fromView, t);
2848 dispatchOnLauncherTransitionStep(toView, t);
2849 }
2850 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002851
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002852 // toView should appear right at the end of the workspace shrink
2853 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002854 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002856 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002857
2858 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002859 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002860 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002861 // Prepare the position
2862 toView.setTranslationX(0.0f);
2863 toView.setTranslationY(0.0f);
2864 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002865 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002866 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002867 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002868 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002869 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2870 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002871
Winson Chungc7d2b602012-05-16 17:02:20 -07002872 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002873 if (mSearchDropTargetBar != null) {
2874 mSearchDropTargetBar.hideSearchBar(false);
2875 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002876 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002877 });
2878
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002879 if (workspaceAnim != null) {
2880 mStateAnimation.play(workspaceAnim);
2881 }
Michael Jurka1899a362011-11-03 13:50:45 -07002882
2883 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002884
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002885 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2886 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002887
2888 // If any of the objects being animated haven't been measured/laid out
2889 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002890 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002891 (mWorkspace.getMeasuredWidth() == 0) ||
2892 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002893 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002894 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002895
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002896 final AnimatorSet stateAnimation = mStateAnimation;
2897 final Runnable startAnimRunnable = new Runnable() {
2898 public void run() {
2899 // Check that mStateAnimation hasn't changed while
2900 // we waited for a layout/draw pass
2901 if (mStateAnimation != stateAnimation)
2902 return;
2903 setPivotsForZoom(toView, scale);
2904 dispatchOnLauncherTransitionStart(fromView, animated, false);
2905 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002906 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002907 }
2908 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002909 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002910 final ViewTreeObserver observer = toView.getViewTreeObserver();
2911 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2912 public void onGlobalLayout() {
2913 startAnimRunnable.run();
2914 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2915 }
2916 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002917 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002918 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002919 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002920 } else {
2921 toView.setTranslationX(0.0f);
2922 toView.setTranslationY(0.0f);
2923 toView.setScaleX(1.0f);
2924 toView.setScaleY(1.0f);
2925 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002926 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002927
Daniel Sandlere4f98912013-06-25 15:13:26 -04002928 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002929 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002930 if (mSearchDropTargetBar != null) {
2931 mSearchDropTargetBar.hideSearchBar(false);
2932 }
Michael Jurkaabded662011-03-04 12:06:57 -08002933 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002934 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002935 dispatchOnLauncherTransitionStart(fromView, animated, false);
2936 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002937 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002938 dispatchOnLauncherTransitionStart(toView, animated, false);
2939 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002940 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002941 }
2942
2943 /**
2944 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002945 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002946 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002947 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002948 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2949 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002950
Michael Jurkab3e22d92011-10-31 15:58:33 -07002951 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002952 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002953 mStateAnimation.cancel();
2954 mStateAnimation = null;
2955 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002956 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002957
Winson Chungf0ea4d32011-06-06 14:27:16 -07002958 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002959 final int fadeOutDuration =
2960 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002961 final float scaleFactor = (float)
2962 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2963 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002964 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002965 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002966 if (toState == State.WORKSPACE) {
2967 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2968 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002969 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002970 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2971 workspaceAnim = mWorkspace.getChangeStateAnimation(
2972 Workspace.State.SPRING_LOADED, animated);
2973 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002974
Michael Jurkab3e22d92011-10-31 15:58:33 -07002975 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002976 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002977 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002978 final LauncherViewPropertyAnimator scaleAnim =
2979 new LauncherViewPropertyAnimator(fromView);
2980 scaleAnim.
2981 scaleX(scaleFactor).scaleY(scaleFactor).
2982 setDuration(duration).
2983 setInterpolator(new Workspace.ZoomInInterpolator());
2984
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002985 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002986 .ofFloat(fromView, "alpha", 1f, 0f)
2987 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002988 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002989 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2990 @Override
2991 public void onAnimationUpdate(ValueAnimator animation) {
2992 float t = 1f - (Float) animation.getAnimatedValue();
2993 dispatchOnLauncherTransitionStep(fromView, t);
2994 dispatchOnLauncherTransitionStep(toView, t);
2995 }
2996 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002997
Michael Jurka2ecf9952012-06-18 12:52:28 -07002998 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002999
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003000 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3001 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003002 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003003
3004 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003005 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003006 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003007 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003008 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3009 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003010 if (onCompleteRunnable != null) {
3011 onCompleteRunnable.run();
3012 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003013 mAppsCustomizeContent.updateCurrentPageScroll();
3014 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003015 }
3016 });
3017
Winson Chungf0ea4d32011-06-06 14:27:16 -07003018 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003019 if (workspaceAnim != null) {
3020 mStateAnimation.play(workspaceAnim);
3021 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003022 dispatchOnLauncherTransitionStart(fromView, animated, true);
3023 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003024 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003025 } else {
3026 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003027 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003028 dispatchOnLauncherTransitionStart(fromView, animated, true);
3029 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003030 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003031 dispatchOnLauncherTransitionStart(toView, animated, true);
3032 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003033 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003034 }
3035
Michael Jurkae326f182011-11-21 14:05:46 -08003036 @Override
3037 public void onTrimMemory(int level) {
3038 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003039 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003040 mAppsCustomizeTabHost.onTrimMemory();
3041 }
3042 }
3043
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003044 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003045 showWorkspace(animated, null);
3046 }
3047
3048 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003049 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003050 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003051 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003052 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003053
Winson Chungc7d2b602012-05-16 17:02:20 -07003054 // Show the search bar (only animate if we were showing the drop target bar in spring
3055 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003056 if (mSearchDropTargetBar != null) {
3057 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3058 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003059
Michael Jurkab3e22d92011-10-31 15:58:33 -07003060 // Set focus to the AppsCustomize button
3061 if (mAllAppsButton != null) {
3062 mAllAppsButton.requestFocus();
3063 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003064 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003065
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003066 // Change the state *after* we've called all the transition code
3067 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003068
Winson Chung5fb63472011-02-02 17:03:37 -08003069 // Resume the auto-advance of widgets
3070 mUserPresent = true;
3071 updateRunning();
3072
alanv1d4fde62012-10-17 13:15:47 -07003073 // Send an accessibility event to announce the context change
3074 getWindow().getDecorView()
3075 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003076
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003077 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003078 }
3079
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003080 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003081 }
3082
Winson Chungc58497e2013-09-03 17:48:37 -07003083 void showAllApps(boolean animated,
3084 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 if (mState != State.WORKSPACE) return;
3086
Winson Chungc58497e2013-09-03 17:48:37 -07003087 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003088 mAppsCustomizeTabHost.requestFocus();
3089
Michael Jurkab3e22d92011-10-31 15:58:33 -07003090 // Change the state *after* we've called all the transition code
3091 mState = State.APPS_CUSTOMIZE;
3092
3093 // Pause the auto-advance of widgets until we are out of AllApps
3094 mUserPresent = false;
3095 updateRunning();
3096 closeFolder();
3097
3098 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003099 getWindow().getDecorView()
3100 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003101 }
3102
Adam Cohen7777d962011-08-18 18:58:38 -07003103 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003104 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003105 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003106 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003107 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003108 }
Adam Cohen7777d962011-08-18 18:58:38 -07003109
Adam Cohened66b2b2012-01-23 17:28:51 -08003110 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3111 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003112 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3113
Winson Chunge7a03942011-08-05 15:05:12 -07003114 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003115 @Override
3116 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003117 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003118 // Before we show workspace, hide all apps again because
3119 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3120 // clean up our state transition functions
3121 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003122 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003123 } else {
3124 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003125 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003126 }
3127 }, (extendedDelay ?
3128 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3129 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3130 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003131
Michael Jurkad3ef3062010-11-23 16:23:58 -08003132 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003133 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003134 final boolean animated = true;
3135 final boolean springLoaded = true;
3136 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003137 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003138 }
3139 // Otherwise, we are not in spring loaded mode, so don't do anything.
3140 }
3141
Michael Jurkab3e22d92011-10-31 15:58:33 -07003142 void lockAllApps() {
3143 // TODO
3144 }
3145
3146 void unlockAllApps() {
3147 // TODO
3148 }
3149
Winson Chungf0ea4d32011-06-06 14:27:16 -07003150 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003151 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003152 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003153 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003154 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003155 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003156 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003157 int duration = 0;
3158 if (mSearchDropTargetBar != null) {
3159 duration = mSearchDropTargetBar.getTransitionInDuration();
3160 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003161 mHotseat.animate().alpha(1f).setDuration(duration);
3162 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003163 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003164 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003165 }
3166 }
3167 }
3168
3169 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003170 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003171 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003172 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003173 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003174 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003175 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003176 int duration = 0;
3177 if (mSearchDropTargetBar != null) {
3178 duration = mSearchDropTargetBar.getTransitionOutDuration();
3179 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003180 mHotseat.animate().alpha(0f).setDuration(duration);
3181 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003182 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003183 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003184 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003185 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003186 }
3187
Patrick Dubroy5f445422011-02-18 14:35:21 -08003188 /**
3189 * Add an item from all apps or customize onto the given workspace screen.
3190 * If layout is null, add to the current screen.
3191 */
3192 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003193 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003194 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003195 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003196 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003197
Winson Chungdff8ebb2011-09-08 17:25:31 -07003198 /** Maps the current orientation to an index for referencing orientation correct global icons */
3199 private int getCurrentOrientationIndexForGlobalIcons() {
3200 // default - 0, landscape - 1
3201 switch (getResources().getConfiguration().orientation) {
3202 case Configuration.ORIENTATION_LANDSCAPE:
3203 return 1;
3204 default:
3205 return 0;
3206 }
3207 }
3208
Michael Jurkaae65ee32012-04-30 11:45:54 -07003209 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003210 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003211 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003212 // Look for the toolbar icon specified in the activity meta-data
3213 Bundle metaData = packageManager.getActivityInfo(
3214 activityName, PackageManager.GET_META_DATA).metaData;
3215 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003216 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003217 if (iconResId != 0) {
3218 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003219 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003220 }
3221 }
3222 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003223 // This can happen if the activity defines an invalid drawable
3224 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3225 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003226 } catch (Resources.NotFoundException nfe) {
3227 // This can happen if the activity defines an invalid drawable
3228 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3229 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003230 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003231 return null;
3232 }
3233
3234 // if successful in getting icon, return it; otherwise, set button to use default drawable
3235 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003236 int buttonId, ComponentName activityName, int fallbackDrawableId,
3237 String toolbarResourceName) {
3238 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003239 Resources r = getResources();
3240 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3241 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003242
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003243 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003244 // If we were unable to find the icon via the meta-data, use a generic one
3245 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003246 toolbarIcon = r.getDrawable(fallbackDrawableId);
3247 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003248 if (button != null) {
3249 button.setCompoundDrawables(toolbarIcon, null, null, null);
3250 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003251 return null;
3252 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003253 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003254 if (button != null) {
3255 button.setCompoundDrawables(toolbarIcon, null, null, null);
3256 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003257 return toolbarIcon.getConstantState();
3258 }
3259 }
3260
3261 // if successful in getting icon, return it; otherwise, set button to use default drawable
3262 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003263 int buttonId, ComponentName activityName, int fallbackDrawableId,
3264 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003265 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003266 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003267
Michael Jurka19e0fc52011-07-22 18:00:21 -07003268 if (button != null) {
3269 // If we were unable to find the icon via the meta-data, use a
3270 // generic one
3271 if (toolbarIcon == null) {
3272 button.setImageResource(fallbackDrawableId);
3273 } else {
3274 button.setImageDrawable(toolbarIcon);
3275 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003276 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003277
3278 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3279
Michael Jurka0423dcf2010-10-05 14:56:18 -07003280 }
3281
Winson Chung1b884092012-06-08 17:13:02 -07003282 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003283 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003284 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003285 }
3286
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003287 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003288 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003289 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003290 }
3291
Winson Chungbb185bd2011-11-21 12:31:42 -08003292 private void invalidatePressedFocusedStates(View container, View button) {
3293 if (container instanceof HolographicLinearLayout) {
3294 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3295 layout.invalidatePressedFocusedStates();
3296 } else if (button instanceof HolographicImageView) {
3297 HolographicImageView view = (HolographicImageView) button;
3298 view.invalidatePressedFocusedStates();
3299 }
3300 }
3301
Cristina Stancu476493b2013-08-07 17:20:14 +01003302 public View getQsbBar() {
3303 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003304 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3305 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003306 }
3307 return mQsbBar;
3308 }
3309
3310 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003311 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003312 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003313 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003314 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003315
Winson Chung1cad91e2011-05-25 17:41:01 -07003316 final SearchManager searchManager =
3317 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3318 ComponentName activityName = searchManager.getGlobalSearchActivity();
3319 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003320 int coi = getCurrentOrientationIndexForGlobalIcons();
3321 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003322 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3323 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3324 if (sGlobalSearchIcon[coi] == null) {
3325 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3326 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3327 TOOLBAR_ICON_METADATA_NAME);
3328 }
3329
Winson Chungc51db6a2011-10-05 11:44:49 -07003330 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3331 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003332 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003333 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003334 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003335 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003336 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3337 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003338 if (searchButton != null) searchButton.setVisibility(View.GONE);
3339 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003340 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003341 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003342 }
3343 }
3344
Cristina Stancu476493b2013-08-07 17:20:14 +01003345 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003346 final View searchButtonContainer = findViewById(R.id.search_button_container);
3347 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003348 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003349 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003350 }
3351
Cristina Stancu476493b2013-08-07 17:20:14 +01003352 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003353 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003354 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003355
Winson Chungc51db6a2011-10-05 11:44:49 -07003356 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003357 final SearchManager searchManager =
3358 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3359 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3360
3361 ComponentName activityName = null;
3362 if (globalSearchActivity != null) {
3363 // Check if the global search activity handles voice search
3364 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3365 intent.setPackage(globalSearchActivity.getPackageName());
3366 activityName = intent.resolveActivity(getPackageManager());
3367 }
3368
3369 if (activityName == null) {
3370 // Fallback: check if an activity other than the global search activity
3371 // resolves this
3372 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3373 activityName = intent.resolveActivity(getPackageManager());
3374 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003375 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003376 int coi = getCurrentOrientationIndexForGlobalIcons();
3377 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003378 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3379 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3380 if (sVoiceSearchIcon[coi] == null) {
3381 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3382 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3383 TOOLBAR_ICON_METADATA_NAME);
3384 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003385 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003386 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003387 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003388 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003389 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003390 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003391 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003392 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003393 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003394 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003395 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003396 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003397
Cristina Stancu476493b2013-08-07 17:20:14 +01003398 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003399 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3400 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003401 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003402 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003403 }
3404
Winson Chung5841efa2013-09-30 18:06:44 -07003405 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003406 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3407 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003408 boolean visible = !forceDisableVoiceButtonProxy &&
3409 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003410 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003411 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003412 }
3413 }
Winson Chung5841efa2013-09-30 18:06:44 -07003414
3415 /**
3416 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3417 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3418 */
3419 public void disableVoiceButtonProxy(boolean disabled) {
3420 updateVoiceButtonProxyVisible(disabled);
3421 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003422 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003423 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003424 */
3425 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003426 if (!DISABLE_MARKET_BUTTON) {
3427 final View marketButton = findViewById(R.id.market_button);
3428 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3429 // Find the app market activity by resolving an intent.
3430 // (If multiple app markets are installed, it will return the ResolverActivity.)
3431 ComponentName activityName = intent.resolveActivity(getPackageManager());
3432 if (activityName != null) {
3433 int coi = getCurrentOrientationIndexForGlobalIcons();
3434 mAppMarketIntent = intent;
3435 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3436 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3437 TOOLBAR_ICON_METADATA_NAME);
3438 marketButton.setVisibility(View.VISIBLE);
3439 } else {
3440 // We should hide and disable the view so that we don't try and restore the visibility
3441 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3442 marketButton.setVisibility(View.GONE);
3443 marketButton.setEnabled(false);
3444 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003445 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003446 }
3447
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003448 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003449 if (!DISABLE_MARKET_BUTTON) {
3450 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3451 Resources r = getResources();
3452 Drawable marketIconDrawable = d.newDrawable(r);
3453 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3454 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3455 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003456
Winson Chungd64a6662013-09-30 11:06:59 -07003457 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3458 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003459 }
3460
Michael Jurkad7c28052012-04-27 15:43:36 -07003461 @Override
3462 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003463 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003464 final List<CharSequence> text = event.getText();
3465 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003466 // Populate event with a fake title based on the current state.
3467 if (mState == State.APPS_CUSTOMIZE) {
3468 text.add(getString(R.string.all_apps_button_label));
3469 } else {
3470 text.add(getString(R.string.all_apps_home_button_label));
3471 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003472 return result;
3473 }
3474
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003475 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003476 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003477 */
3478 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3479 @Override
3480 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003481 closeSystemDialogs();
3482 }
3483 }
3484
3485 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003486 * Receives notifications whenever the appwidgets are reset.
3487 */
3488 private class AppWidgetResetObserver extends ContentObserver {
3489 public AppWidgetResetObserver() {
3490 super(new Handler());
3491 }
3492
3493 @Override
3494 public void onChange(boolean selfChange) {
3495 onAppWidgetReset();
3496 }
3497 }
3498
3499 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003500 * If the activity is currently paused, signal that we need to run the passed Runnable
3501 * in onResume.
3502 *
3503 * This needs to be called from incoming places where resources might have been loaded
3504 * while we are paused. That is becaues the Configuration might be wrong
3505 * when we're not running, and if it comes back to what it was when we
3506 * were paused, we are not restarted.
3507 *
3508 * Implementation of the method from LauncherModel.Callbacks.
3509 *
3510 * @return true if we are currently paused. The caller might be able to
3511 * skip some work in that case since we will come back again.
3512 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003513 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003514 if (mPaused) {
3515 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003516 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003517 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003518 }
3519 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003520 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003521 return true;
3522 } else {
3523 return false;
3524 }
3525 }
3526
Michael Jurkac402cd92013-05-20 15:49:32 +02003527 private boolean waitUntilResume(Runnable run) {
3528 return waitUntilResume(run, false);
3529 }
3530
Michael Jurka1e2f4652013-07-08 18:03:46 -07003531 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003532 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003533 }
3534
Michael Jurka7607c2f2013-04-03 14:33:19 -07003535 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003536 * If the activity is currently paused, signal that we need to re-run the loader
3537 * in onResume.
3538 *
3539 * This needs to be called from incoming places where resources might have been loaded
3540 * while we are paused. That is becaues the Configuration might be wrong
3541 * when we're not running, and if it comes back to what it was when we
3542 * were paused, we are not restarted.
3543 *
3544 * Implementation of the method from LauncherModel.Callbacks.
3545 *
3546 * @return true if we are currently paused. The caller might be able to
3547 * skip some work in that case since we will come back again.
3548 */
3549 public boolean setLoadOnResume() {
3550 if (mPaused) {
3551 Log.i(TAG, "setLoadOnResume");
3552 mOnResumeNeedsLoad = true;
3553 return true;
3554 } else {
3555 return false;
3556 }
3557 }
3558
3559 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003560 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003561 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003562 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003563 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003564 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003565 } else {
3566 return SCREEN_COUNT / 2;
3567 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003568 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003569
Joe Onorato9c1289c2009-08-17 11:03:03 -04003570 /**
3571 * Refreshes the shortcuts shown on the workspace.
3572 *
3573 * Implementation of the method from LauncherModel.Callbacks.
3574 */
3575 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003576 // If we're starting binding all over again, clear any bind calls we'd postponed in
3577 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3578 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003579 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003580
Winson Chungd64d1762013-08-20 14:37:16 -07003581 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003582 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003583 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003584
Michael Jurka05bf644e2011-11-30 20:28:53 -08003585 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003586 if (mHotseat != null) {
3587 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003588 }
3589 }
3590
Adam Cohendcd297f2013-06-18 13:13:40 -07003591 @Override
3592 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003593 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003594
Adam Cohen5084cba2013-09-03 12:01:16 -07003595 // If there are no screens, we need to have an empty screen
3596 if (orderedScreenIds.size() == 0) {
3597 mWorkspace.addExtraEmptyScreen();
3598 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003599
3600 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003601 // setCurrentPage() so ensure that all pages are added before calling this).
3602 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003603 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3604 mWorkspace.createCustomContentPage();
3605 }
Winson Chung64359a52013-07-08 17:17:08 -07003606 }
3607
3608 @Override
3609 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003610 int count = orderedScreenIds.size();
3611 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003612 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003613 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003614 }
3615
Adam Cohen39a06042013-07-19 14:30:12 -07003616 private boolean shouldShowWeightWatcher() {
3617 String spKey = LauncherAppState.getSharedPreferencesKey();
3618 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003619 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003620
3621 return show;
3622 }
3623
3624 private void toggleShowWeightWatcher() {
3625 String spKey = LauncherAppState.getSharedPreferencesKey();
3626 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3627 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3628
3629 show = !show;
3630
3631 SharedPreferences.Editor editor = sp.edit();
3632 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3633 editor.commit();
3634
3635 if (mWeightWatcher != null) {
3636 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3637 }
3638 }
3639
Winson Chungd64d1762013-08-20 14:37:16 -07003640 public void bindAppsAdded(final ArrayList<Long> newScreens,
3641 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003642 final ArrayList<ItemInfo> addAnimated,
3643 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003644 Runnable r = new Runnable() {
3645 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003646 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003647 }
3648 };
3649 if (waitUntilResume(r)) {
3650 return;
3651 }
3652
Winson Chungd64d1762013-08-20 14:37:16 -07003653 // Add the new screens
3654 bindAddScreens(newScreens);
3655
3656 // We add the items without animation on non-visible pages, and with
3657 // animations on the new page (which we will try and snap to).
3658 if (!addNotAnimated.isEmpty()) {
3659 bindItems(addNotAnimated, 0,
3660 addNotAnimated.size(), false);
3661 }
3662 if (!addAnimated.isEmpty()) {
3663 bindItems(addAnimated, 0,
3664 addAnimated.size(), true);
3665 }
Winson Chungc58497e2013-09-03 17:48:37 -07003666
3667 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3668 addedApps != null && mAppsCustomizeContent != null) {
3669 mAppsCustomizeContent.addApps(addedApps);
3670 }
Winson Chungd64d1762013-08-20 14:37:16 -07003671 }
3672
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003673 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003674 * Bind the items start-end from the list.
3675 *
3676 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003677 */
Winson Chung64359a52013-07-08 17:17:08 -07003678 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3679 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003680 Runnable r = new Runnable() {
3681 public void run() {
3682 bindItems(shortcuts, start, end, forceAnimateIcons);
3683 }
3684 };
3685 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003686 return;
3687 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003688
Winson Chungf0c6ae02012-03-21 16:10:31 -07003689 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003690 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3691 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003692 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003693 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003694 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003695 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003696 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003697
3698 // Short circuit if we are loading dock items for a configuration which has no dock
3699 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3700 mHotseat == null) {
3701 continue;
3702 }
3703
Joe Onorato9c1289c2009-08-17 11:03:03 -04003704 switch (item.itemType) {
3705 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3706 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003707 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003708 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003709
Winson Chung64359a52013-07-08 17:17:08 -07003710 /*
3711 * TODO: FIX collision case
3712 */
Winson Chungce376632013-07-11 16:12:41 -07003713 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3714 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3715 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3716 throw new RuntimeException("OCCUPIED");
3717 }
Winson Chung64359a52013-07-08 17:17:08 -07003718 }
3719
Adam Cohendcd297f2013-06-18 13:13:40 -07003720 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3721 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003722 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003723 // Animate all the applications up now
3724 shortcut.setAlpha(0f);
3725 shortcut.setScaleX(0f);
3726 shortcut.setScaleY(0f);
3727 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003728 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003729 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003730 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003731 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003732 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003733 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003734 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003735 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3736 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003737 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003738 default:
3739 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003741 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003742
Winson Chung997a9232013-07-24 15:33:46 -07003743 if (animateIcons) {
3744 // Animate to the correct page
3745 if (newShortcutsScreenId > -1) {
3746 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003747 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003748 final Runnable startBounceAnimRunnable = new Runnable() {
3749 public void run() {
3750 anim.playTogether(bounceAnims);
3751 anim.start();
3752 }
3753 };
Winson Chung997a9232013-07-24 15:33:46 -07003754 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003755 // We post the animation slightly delayed to prevent slowdowns
3756 // when we are loading right after we return to launcher.
3757 mWorkspace.postDelayed(new Runnable() {
3758 public void run() {
3759 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003760 mWorkspace.postDelayed(startBounceAnimRunnable,
3761 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003762 }
3763 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003764 } else {
3765 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003766 }
3767 }
Winson Chung64359a52013-07-08 17:17:08 -07003768 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003769 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003770 }
3771
Joe Onorato9c1289c2009-08-17 11:03:03 -04003772 /**
3773 * Implementation of the method from LauncherModel.Callbacks.
3774 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003775 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003776 Runnable r = new Runnable() {
3777 public void run() {
3778 bindFolders(folders);
3779 }
3780 };
3781 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003782 return;
3783 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003784 sFolders.clear();
3785 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003786 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003787
3788 /**
3789 * Add the views for a widget to the workspace.
3790 *
3791 * Implementation of the method from LauncherModel.Callbacks.
3792 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003793 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003794 Runnable r = new Runnable() {
3795 public void run() {
3796 bindAppWidget(item);
3797 }
3798 };
3799 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003800 return;
3801 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003802
Daniel Sandler843e8602010-06-07 14:59:01 -04003803 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3804 if (DEBUG_WIDGETS) {
3805 Log.d(TAG, "bindAppWidget: " + item);
3806 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003807 final Workspace workspace = mWorkspace;
3808
3809 final int appWidgetId = item.appWidgetId;
3810 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003811 if (DEBUG_WIDGETS) {
3812 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3813 }
3814
Joe Onorato9c1289c2009-08-17 11:03:03 -04003815 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3816
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003818 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819
Adam Cohendcd297f2013-06-18 13:13:40 -07003820 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003821 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003822 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3823
Joe Onorato9c1289c2009-08-17 11:03:03 -04003824 workspace.requestLayout();
3825
Daniel Sandler843e8602010-06-07 14:59:01 -04003826 if (DEBUG_WIDGETS) {
3827 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3828 + (SystemClock.uptimeMillis()-start) + "ms");
3829 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003830 }
3831
Adam Cohen1462de32012-07-24 22:34:36 -07003832 public void onPageBoundSynchronously(int page) {
3833 mSynchronouslyBoundPages.add(page);
3834 }
3835
Joe Onorato9c1289c2009-08-17 11:03:03 -04003836 /**
3837 * Callback saying that there aren't any more items to bind.
3838 *
3839 * Implementation of the method from LauncherModel.Callbacks.
3840 */
Adam Cohene25af792013-06-06 23:08:25 -07003841 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003842 Runnable r = new Runnable() {
3843 public void run() {
3844 finishBindingItems(upgradePath);
3845 }
3846 };
3847 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003848 return;
3849 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003850 if (mSavedState != null) {
3851 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003852 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003853 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003854 mSavedState = null;
3855 }
3856
Adam Cohen1462de32012-07-24 22:34:36 -07003857 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003858
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003859 // If we received the result of any pending adds while the loader was running (e.g. the
3860 // widget configuration forced an orientation change), process them now.
3861 for (int i = 0; i < sPendingAddList.size(); i++) {
3862 completeAdd(sPendingAddList.get(i));
3863 }
3864 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003865
Winson Chungc51db6a2011-10-05 11:44:49 -07003866 // Update the market app icon as necessary (the other icons will be managed in response to
3867 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003868 if (!DISABLE_MARKET_BUTTON) {
3869 updateAppMarketIcon();
3870 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003871
Winson Chungf0c6ae02012-03-21 16:10:31 -07003872 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003873 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003874 mWorkspace.getUniqueComponents(true, null);
3875 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003876 }
Adam Cohen99894d92013-06-14 11:22:59 -07003877
Adam Cohen66a01fd2013-06-11 12:48:00 -07003878 mWorkspace.post(new Runnable() {
3879 @Override
3880 public void run() {
3881 onFinishBindingItems();
3882 }
3883 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003884 }
3885
Winson Chunga0b7e862013-09-05 16:03:15 -07003886 public boolean isAllAppsButtonRank(int rank) {
3887 if (mHotseat != null) {
3888 return mHotseat.isAllAppsButtonRank(rank);
3889 }
3890 return false;
3891 }
3892
Winson Chunga2413752012-04-03 14:22:34 -07003893 private boolean canRunNewAppsAnimation() {
3894 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3895 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3896 }
3897
Winson Chungc9168342013-06-26 14:54:55 -07003898 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3899 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3900 PropertyValuesHolder.ofFloat("alpha", 1f),
3901 PropertyValuesHolder.ofFloat("scaleX", 1f),
3902 PropertyValuesHolder.ofFloat("scaleY", 1f));
3903 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3904 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3905 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3906 return bounceAnim;
3907 }
3908
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003909 @Override
3910 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003911 boolean searchVisible = updateGlobalSearchIcon();
3912 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003913 if (mSearchDropTargetBar != null) {
3914 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3915 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003916 }
3917
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003918 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003919 * Add the icons for all apps.
3920 *
3921 * Implementation of the method from LauncherModel.Callbacks.
3922 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003923 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003924 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3925 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3926 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3927 getHotseat().addAllAppsFolder(mIconCache, apps,
3928 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3929 }
3930 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003931 }
Winson Chungc58497e2013-09-03 17:48:37 -07003932 } else {
3933 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3934 mAppsCustomizeContent != null) {
3935 mAppsCustomizeContent.setApps(apps);
3936 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003937 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003938 }
3939
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003940 @Override
3941 public boolean shouldShowApp(ResolveInfo app) {
3942 return true;
3943 }
3944
Joe Onorato9c1289c2009-08-17 11:03:03 -04003945 /**
3946 * A package was updated.
3947 *
3948 * Implementation of the method from LauncherModel.Callbacks.
3949 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003950 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003951 Runnable r = new Runnable() {
3952 public void run() {
3953 bindAppsUpdated(apps);
3954 }
3955 };
3956 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003957 return;
3958 }
3959
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003960 if (mWorkspace != null) {
3961 mWorkspace.updateShortcuts(apps);
3962 }
Winson Chungc58497e2013-09-03 17:48:37 -07003963
3964 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3965 mAppsCustomizeContent != null) {
3966 mAppsCustomizeContent.updateApps(apps);
3967 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003968 }
3969
3970 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003971 * A package was uninstalled. We take both the super set of packageNames
3972 * in addition to specific applications to remove, the reason being that
3973 * this can be called when a package is updated as well. In that scenario,
3974 * we only remove specific components from the workspace, where as
3975 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003976 *
3977 * Implementation of the method from LauncherModel.Callbacks.
3978 */
Winson Chung83892cc2013-05-01 16:53:33 -07003979 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003980 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003981 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003982 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003983 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003984 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003985 }
Winson Chungd64d1762013-08-20 14:37:16 -07003986 };
3987 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003988 return;
3989 }
3990
Winson Chung64359a52013-07-08 17:17:08 -07003991 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003992 mWorkspace.removeItemsByPackageName(packageNames);
3993 } else {
3994 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003995 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003996
Winson Chunga1820962011-10-03 16:31:06 -07003997 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003998 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003999
4000 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4001 mAppsCustomizeContent != null) {
4002 mAppsCustomizeContent.removeApps(appInfos);
4003 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004004 }
Joe Onoratobe386092009-11-17 17:32:16 -08004005
4006 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004007 * A number of packages were updated.
4008 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004009 private ArrayList<Object> mWidgetsAndShortcuts;
4010 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004011 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004012 bindPackagesUpdated(mWidgetsAndShortcuts);
4013 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004014 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004015 };
4016
4017 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4018 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4019 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004020 return;
4021 }
4022
Winson Chung64359a52013-07-08 17:17:08 -07004023 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004024 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4025 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004026 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004027 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004028 }
4029
Winson Chung400438b2011-01-16 17:53:48 -08004030 private int mapConfigurationOriActivityInfoOri(int configOri) {
4031 final Display d = getWindowManager().getDefaultDisplay();
4032 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4033 switch (d.getRotation()) {
4034 case Surface.ROTATION_0:
4035 case Surface.ROTATION_180:
4036 // We are currently in the same basic orientation as the natural orientation
4037 naturalOri = configOri;
4038 break;
4039 case Surface.ROTATION_90:
4040 case Surface.ROTATION_270:
4041 // We are currently in the other basic orientation to the natural orientation
4042 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4043 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4044 break;
4045 }
4046
4047 int[] oriMap = {
4048 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4049 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4050 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4051 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4052 };
4053 // Since the map starts at portrait, we need to offset if this device's natural orientation
4054 // is landscape.
4055 int indexOffset = 0;
4056 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4057 indexOffset = 1;
4058 }
4059 return oriMap[(d.getRotation() + indexOffset) % 4];
4060 }
Adam Cohen446e9402011-09-15 18:21:21 -07004061
Winson Chung4b919f82012-05-01 10:44:08 -07004062 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004063 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004064 getResources().getBoolean(R.bool.allow_rotation);
4065 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004066 }
Winson Chung4b919f82012-05-01 10:44:08 -07004067 public void lockScreenOrientation() {
4068 if (isRotationEnabled()) {
4069 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4070 .getConfiguration().orientation));
4071 }
4072 }
4073 public void unlockScreenOrientation(boolean immediate) {
4074 if (isRotationEnabled()) {
4075 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004076 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004077 } else {
4078 mHandler.postDelayed(new Runnable() {
4079 public void run() {
4080 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4081 }
4082 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004083 }
Winson Chung4b919f82012-05-01 10:44:08 -07004084 }
Winson Chung400438b2011-01-16 17:53:48 -08004085 }
4086
Winson Chung82f55532011-08-09 14:14:23 -07004087 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004088 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004089 if (DISABLE_CLINGS) {
4090 return false;
4091 }
4092
Brett Chabot2a9e2282011-08-23 15:03:13 -07004093 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004094 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004095
Michael Jurkae233a8b2013-03-19 13:49:20 +01004096 // Restricted secondary users (child mode) will potentially have very few apps
4097 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004098// boolean supportsLimitedUsers =
4099// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4100// Account[] accounts = AccountManager.get(this).getAccounts();
4101// if (supportsLimitedUsers && accounts.length == 0) {
4102// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4103// Bundle restrictions = um.getUserRestrictions();
4104// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4105// return false;
4106// }
4107// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004108 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004109 }
Michael Jurka22143132012-10-04 17:42:38 +02004110
Winson Chungfa545132013-09-26 17:45:32 -07004111 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004112 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004113 Cling cling = (Cling) findViewById(clingId);
4114 View scrim = null;
4115 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004116 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004117 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004118 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004119 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004120 cling.show(animate, SHOW_CLING_DURATION);
4121
4122 if (dimNavBarVisibilty) {
4123 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4124 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004125 }
4126 }
4127 return cling;
4128 }
Michael Jurka22143132012-10-04 17:42:38 +02004129
Winson Chungaf40f202013-09-18 18:26:31 -07004130 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4131 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004132 // To catch cases where siblings of top-level views are made invisible, just check whether
4133 // the cling is directly set to GONE before dismissing it.
4134 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004135 final Runnable cleanUpClingCb = new Runnable() {
4136 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004137 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004138 // We should update the shared preferences on a background thread
4139 new Thread("dismissClingThread") {
4140 public void run() {
4141 SharedPreferences.Editor editor = mSharedPrefs.edit();
4142 editor.putBoolean(flag, true);
4143 editor.commit();
4144 }
4145 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004146 if (postAnimationCb != null) {
4147 postAnimationCb.run();
4148 }
4149 }
4150 };
4151 if (duration <= 0) {
4152 cleanUpClingCb.run();
4153 } else {
4154 cling.hide(duration, cleanUpClingCb);
4155 }
Michael Jurka22143132012-10-04 17:42:38 +02004156 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004157
4158 if (restoreNavBarVisibilty) {
4159 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4160 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4161 }
Winson Chung82f55532011-08-09 14:14:23 -07004162 }
4163 }
Michael Jurka22143132012-10-04 17:42:38 +02004164
Winson Chung9d9d74f2011-09-19 11:49:12 -07004165 private void removeCling(int id) {
4166 final View cling = findViewById(id);
4167 if (cling != null) {
4168 final ViewGroup parent = (ViewGroup) cling.getParent();
4169 parent.post(new Runnable() {
4170 @Override
4171 public void run() {
4172 parent.removeView(cling);
4173 }
4174 });
Michael Jurka22143132012-10-04 17:42:38 +02004175 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004176 }
4177 }
Michael Jurka974c3862012-05-22 22:00:31 -07004178
4179 private boolean skipCustomClingIfNoAccounts() {
4180 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4181 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4182 if (customCling) {
4183 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004184 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004185 Account[] accounts = am.getAccountsByType("com.google");
4186 return accounts.length == 0;
4187 }
4188 return false;
4189 }
4190
Winson Chungaf40f202013-09-18 18:26:31 -07004191 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004192 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004193 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004194 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004195 // If we're not using the default workspace layout, replace workspace cling
4196 // with a custom workspace cling (usually specified in an overlay)
4197 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004198 if (!DISABLE_CUSTOM_CLINGS) {
4199 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4200 getResources().getBoolean(R.bool.config_useCustomClings)) {
4201 // Use a custom cling
4202 View cling = findViewById(R.id.workspace_cling);
4203 ViewGroup clingParent = (ViewGroup) cling.getParent();
4204 int clingIndex = clingParent.indexOfChild(cling);
4205 clingParent.removeViewAt(clingIndex);
4206 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4207 clingParent.addView(customCling, clingIndex);
4208 customCling.setId(R.id.workspace_cling);
4209 }
4210 }
4211 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4212 if (cling != null) {
4213 String sbHintStr = getFirstRunClingSearchBarHint();
4214 String ccHintStr = getFirstRunCustomContentHint();
4215 if (!sbHintStr.isEmpty()) {
4216 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4217 sbHint.setText(sbHintStr);
4218 sbHint.setVisibility(View.VISIBLE);
4219 }
4220 if (!ccHintStr.isEmpty()) {
4221 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4222 ccHint.setText(ccHintStr);
4223 ccHint.setVisibility(View.VISIBLE);
4224 }
Michael Jurka45355c42012-10-08 13:21:35 +02004225 }
Winson Chungfa545132013-09-26 17:45:32 -07004226 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004227 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004228 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004229 }
4230 }
Winson Chungaf40f202013-09-18 18:26:31 -07004231
Winson Chunge6eabff2013-09-24 11:01:23 -07004232 protected String getFirstRunClingSearchBarHint() {
4233 return "";
4234 }
4235 protected String getFirstRunCustomContentHint() {
4236 return "";
4237 }
4238
Winson Chungaf40f202013-09-18 18:26:31 -07004239 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004240 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004241 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004242 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004243 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004244 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004245 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004246 }
4247 }
4248 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004249 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004250 if (isClingsEnabled() &&
4251 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004252 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4253 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004254 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004255 } else {
4256 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004257 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004258 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004259 }
Michael Jurka104c4562013-07-08 18:03:46 -07004260 protected SharedPreferences getSharedPrefs() {
4261 return mSharedPrefs;
4262 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004263 public boolean isFolderClingVisible() {
4264 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004265 if (cling != null) {
4266 return cling.getVisibility() == View.VISIBLE;
4267 }
4268 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004269 }
Winson Chungaf40f202013-09-18 18:26:31 -07004270 public void dismissFirstRunCling(View v) {
4271 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4272 Runnable cb = new Runnable() {
4273 public void run() {
4274 // Show the workspace cling next
4275 showFirstRunWorkspaceCling();
4276 }
4277 };
4278 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4279 DISMISS_CLING_DURATION, false);
4280 }
Winson Chung82f55532011-08-09 14:14:23 -07004281 public void dismissWorkspaceCling(View v) {
4282 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004283 Runnable cb = null;
4284 if (v == null) {
4285 cb = new Runnable() {
4286 public void run() {
4287 mWorkspace.enterOverviewMode();
4288 }
4289 };
4290 }
4291 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4292 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004293 }
4294 public void dismissFolderCling(View v) {
4295 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004296 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4297 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004298 }
4299
Winson Chung80baf5a2010-08-09 16:03:15 -07004300 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004301 * Prints out out state for debugging.
4302 */
4303 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004304 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004305 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004306 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4307 Log.d(TAG, "mRestoring=" + mRestoring);
4308 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4309 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004310 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004311 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004312
Winson Chung785d2eb2011-04-14 16:08:02 -07004313 if (mAppsCustomizeContent != null) {
4314 mAppsCustomizeContent.dumpState();
4315 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004316 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004317 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004318
4319 @Override
4320 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4321 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004322 synchronized (sDumpLogs) {
4323 writer.println(" ");
4324 writer.println("Debug logs: ");
4325 for (int i = 0; i < sDumpLogs.size(); i++) {
4326 writer.println(" " + sDumpLogs.get(i));
4327 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004328 }
4329 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004330
4331 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004332 if (DEBUG_DUMP_LOG) {
4333 synchronized (sDumpLogs) {
4334 Log.d(TAG, "");
4335 Log.d(TAG, "*********************");
4336 Log.d(TAG, "Launcher debug logs: ");
4337 for (int i = 0; i < sDumpLogs.size(); i++) {
4338 Log.d(TAG, " " + sDumpLogs.get(i));
4339 }
4340 Log.d(TAG, "*********************");
4341 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004342 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004343 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004344 }
4345
4346 public static void addDumpLog(String tag, String log, boolean debugLog) {
4347 if (debugLog) {
4348 Log.d(tag, log);
4349 }
Winson Chungede41292013-09-19 16:27:36 -07004350 if (DEBUG_DUMP_LOG) {
4351 sDateStamp.setTime(System.currentTimeMillis());
4352 synchronized (sDumpLogs) {
4353 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004354 }
Winson Chungede41292013-09-19 16:27:36 -07004355 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004356 }
4357
Winson Chungede41292013-09-19 16:27:36 -07004358 public void dumpLogsToLocalData() {
4359 if (DEBUG_DUMP_LOG) {
4360 new Thread("DumpLogsToLocalData") {
4361 @Override
4362 public void run() {
4363 boolean success = false;
4364 sDateStamp.setTime(sRunStart);
4365 String FILENAME = sDateStamp.getMonth() + "-"
4366 + sDateStamp.getDay() + "_"
4367 + sDateStamp.getHours() + "-"
4368 + sDateStamp.getMinutes() + "_"
4369 + sDateStamp.getSeconds() + ".txt";
4370
4371 FileOutputStream fos = null;
4372 File outFile = null;
4373 try {
4374 outFile = new File(getFilesDir(), FILENAME);
4375 outFile.createNewFile();
4376 fos = new FileOutputStream(outFile);
4377 } catch (Exception e) {
4378 e.printStackTrace();
4379 }
4380 if (fos != null) {
4381 PrintWriter writer = new PrintWriter(fos);
4382
4383 writer.println(" ");
4384 writer.println("Debug logs: ");
4385 synchronized (sDumpLogs) {
4386 for (int i = 0; i < sDumpLogs.size(); i++) {
4387 writer.println(" " + sDumpLogs.get(i));
4388 }
4389 }
4390 writer.close();
4391 }
4392 try {
4393 if (fos != null) {
4394 fos.close();
4395 success = true;
4396 }
4397 } catch (IOException e) {
4398 e.printStackTrace();
4399 }
4400 }
4401 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004402 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004404}
Michael Jurka2763be32011-02-24 11:19:57 -08004405
Michael Jurkaabded662011-03-04 12:06:57 -08004406interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004407 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004408 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004409 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004410 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004411 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004412}