blob: 3bbb39ee354b16d8027bf49abc0c6d62702880c6 [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;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700133 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700189 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100190 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700191 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700193
Adam Cohen39a06042013-07-19 14:30:12 -0700194 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700195 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700196
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700198 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700199 private State mState = State.WORKSPACE;
200 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201
Joe Onorato9c1289c2009-08-17 11:03:03 -0400202 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700203 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
204 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700205 private static final int SHOW_CLING_DURATION = 250;
206 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800209 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
Winson Chunga2413752012-04-03 14:22:34 -0700211 // How long to wait before the new-shortcut animation automatically pans the workspace
212 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700213 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700214
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800215 private final BroadcastReceiver mCloseSystemDialogsReceiver
216 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800217 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private LayoutInflater mInflater;
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700222 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800223 private DragLayer mDragLayer;
224 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700225 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700226
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700227 private AppWidgetManager mAppWidgetManager;
228 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700229
Michael Jurkac9d95c52011-08-29 14:03:34 -0700230 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700231 private AppWidgetProviderInfo mPendingAddWidgetInfo;
232
Michael Jurka0280c3b2010-09-17 15:00:07 -0700233 private int[] mTmpAddItemCellCoordinates = new int[2];
234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private FolderInfo mFolderInfo;
236
Winson Chung3d503fb2011-07-13 17:25:49 -0700237 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700238 private View mOverviewPanel;
239
Michael Jurka838a4ca2011-02-07 13:33:06 -0800240 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700241
Winson Chungc51db6a2011-10-05 11:44:49 -0700242 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700243 private AppsCustomizeTabHost mAppsCustomizeTabHost;
244 private AppsCustomizePagedView mAppsCustomizeContent;
245 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100246 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700249 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
250 // scroll issues (because the workspace may not have been measured yet) and extra work.
251 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
252 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253
254 private SpannableStringBuilder mDefaultKeySsb = null;
255
Joe Onorato9c1289c2009-08-17 11:03:03 -0400256 private boolean mWorkspaceLoading = true;
257
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800258 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 private boolean mRestoring;
260 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700261 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262
Michael Jurka1e2f4652013-07-08 18:03:46 -0700263 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700264 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
265
Winson Chung4a2afa32012-07-19 14:53:05 -0700266 // Keep track of whether the user has left launcher
267 private static boolean sPausedFromUserAction = false;
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private Bundle mSavedInstanceState;
270
Joe Onorato9c1289c2009-08-17 11:03:03 -0400271 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800272 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800273 private boolean mUserPresent = true;
274 private boolean mVisible = false;
275 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700276 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700278 private static LocaleConfiguration sLocaleConfiguration = null;
279
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700280 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700282 private Intent mAppMarketIntent = null;
283
Adam Cohended9f8d2010-11-03 13:25:16 -0700284 // Related to the auto-advancing of widgets
285 private final int ADVANCE_MSG = 1;
286 private final int mAdvanceInterval = 20000;
287 private final int mAdvanceStagger = 250;
288 private long mAutoAdvanceSentTime;
289 private long mAutoAdvanceTimeLeft = -1;
290 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
291 new HashMap<View, AppWidgetProviderInfo>();
292
Winson Chung400438b2011-01-16 17:53:48 -0800293 // Determines how long to wait after a rotation before restoring the screen orientation to
294 // match the sensor state.
295 private final int mRestoreScreenOrientationDelay = 500;
296
Michael Jurka4ef207b2010-11-29 17:05:45 -0800297 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700298 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
300 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800301
Craig Mautner360310b2012-10-26 15:13:08 -0700302 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700303
Adam Cohen1462de32012-07-24 22:34:36 -0700304 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
305
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700306 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700307 static Date sDateStamp = new Date();
308 static DateFormat sDateFormat =
309 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
310 static long sRunStart = System.currentTimeMillis();
311 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700312
Winson Chung46353de2012-02-16 14:05:10 -0800313 // We only want to get the SharedPreferences once since it does an FS stat each time we get
314 // it from the context.
315 private SharedPreferences mSharedPrefs;
316
Adam Cohene25af792013-06-06 23:08:25 -0700317 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
318
Winson Chungf0c6ae02012-03-21 16:10:31 -0700319 // Holds the page that we need to animate to, and the icon views that we need to animate up
320 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700321 private ImageView mFolderIconImageView;
322 private Bitmap mFolderIconBitmap;
323 private Canvas mFolderIconCanvas;
324 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700325
Michael Jurkaddd62e92011-02-16 17:49:14 -0800326 private BubbleTextView mWaitingForResume;
327
Michael Jurka22143132012-10-04 17:42:38 +0200328 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
329 = new HideFromAccessibilityHelper();
330
Michael Jurkac1f5d262011-09-30 19:32:27 -0700331 private Runnable mBuildLayersRunnable = new Runnable() {
332 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700333 if (mWorkspace != null) {
334 mWorkspace.buildPageHardwareLayers();
335 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 }
337 };
338
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800339 private static ArrayList<PendingAddArguments> sPendingAddList
340 = new ArrayList<PendingAddArguments>();
341
Michael Jurka0a457bf2012-11-19 14:05:05 -0800342 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static class PendingAddArguments {
345 int requestCode;
346 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700347 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700348 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 int cellX;
350 int cellY;
351 }
352
Daniel Sandlerff02d492013-08-05 02:12:05 -0400353 private Stats mStats;
354
Michael Jurka0a457bf2012-11-19 14:05:05 -0800355 private static boolean isPropertyEnabled(String propertyName) {
356 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700357 }
358
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 @Override
360 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700361 if (DEBUG_STRICT_MODE) {
362 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
363 .detectDiskReads()
364 .detectDiskWrites()
365 .detectNetwork() // or .detectAll() for all detectable problems
366 .penaltyLog()
367 .build());
368 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
369 .detectLeakedSqlLiteObjects()
370 .detectLeakedClosableObjects()
371 .penaltyLog()
372 .penaltyDeath()
373 .build());
374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400377
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400378 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400379 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700380
381 // Determine the dynamic grid properties
382 Point smallestSize = new Point();
383 Point largestSize = new Point();
384 Point realSize = new Point();
385 Display display = getWindowManager().getDefaultDisplay();
386 display.getCurrentSizeRange(smallestSize, largestSize);
387 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700388 DisplayMetrics dm = new DisplayMetrics();
389 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700390 // Lazy-initialize the dynamic grid
391 DeviceProfile grid = app.initDynamicGrid(this,
392 Math.min(smallestSize.x, smallestSize.y),
393 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700394 realSize.x, realSize.y,
395 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700396
397 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400398 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700399 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800400 mModel = app.setLauncher(this);
401 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400402 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700404
Daniel Sandlerff02d492013-08-05 02:12:05 -0400405 mStats = new Stats(this);
406
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700407 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700408 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
409 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700410
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700411 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
412 // this also ensures that any synchronous binding below doesn't re-trigger another
413 // LauncherModel load.
414 mPaused = false;
415
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200417 android.os.Debug.startMethodTracing(
418 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 }
420
421 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 setContentView(R.layout.launcher);
423 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100424 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800426 registerContentObservers();
427
Joe Onorato7c312c12009-08-13 21:36:53 -0700428 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700429
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430 mSavedState = savedInstanceState;
431 restoreState(mSavedState);
432
Winson Chunga12a2502010-12-20 14:41:35 -0800433 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700434 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200435 mAppsCustomizeContent.onPackagesUpdated(
436 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700437 }
Winson Chunga12a2502010-12-20 14:41:35 -0800438
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 if (PROFILE_STARTUP) {
440 android.os.Debug.stopMethodTracing();
441 }
442
443 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700444 if (sPausedFromUserAction) {
445 // If the user leaves launcher, then we should just load items asynchronously when
446 // they return.
447 mModel.startLoader(true, -1);
448 } else {
449 // We only load the page synchronously if the user rotates (or triggers a
450 // configuration change) while launcher is in the foreground
451 mModel.startLoader(true, mWorkspace.getCurrentPage());
452 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453 }
454
455 // For handling default keys
456 mDefaultKeySsb = new SpannableStringBuilder();
457 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800458
459 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
460 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800461
Adam Cohenf9426d52012-06-04 17:26:21 -0700462 updateGlobalIcons();
463
464 // On large interfaces, we want the screen to auto-rotate based on the current orientation
465 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700466
467 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700468 }
469
Winson Chung4a2afa32012-07-19 14:53:05 -0700470 protected void onUserLeaveHint() {
471 super.onUserLeaveHint();
472 sPausedFromUserAction = true;
473 }
474
Winson Chung98ca0f72013-07-29 12:58:51 -0700475 /** To be overriden by subclasses to hint to Launcher that we have custom content */
476 protected boolean hasCustomContentToLeft() {
477 return false;
478 }
479
Dave Hawkeya8881582013-09-17 15:55:33 -0600480 /**
481 * To be overridden by subclasses to create the custom content and call
482 * {@link #addToCustomContentPage}. This will only be invoked if
483 * {@link #hasCustomContentToLeft()} is {@code true}.
484 */
485 protected void addCustomContentToLeft() {
486 }
487
488 /**
489 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
490 * ensure the custom content page is added or removed if necessary.
491 */
492 protected void invalidateHasCustomContentToLeft() {
493 if (mWorkspace.getScreenOrder().isEmpty()) {
494 // Not bound yet, wait for bindScreens to be called.
495 return;
496 }
497
498 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
499 // Create the custom content page and call the subclass to populate it.
500 mWorkspace.createCustomContentPage();
501 addCustomContentToLeft();
502 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
503 mWorkspace.removeCustomContentPage();
504 }
505 }
506
Adam Cohenf9426d52012-06-04 17:26:21 -0700507 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700508 boolean searchVisible = false;
509 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800510 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700511 int coi = getCurrentOrientationIndexForGlobalIcons();
512 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
513 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700514 updateAppMarketIcon();
515 searchVisible = updateGlobalSearchIcon();
516 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700517 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700518 if (sGlobalSearchIcon[coi] != null) {
519 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700520 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700521 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700522 if (sVoiceSearchIcon[coi] != null) {
523 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700524 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700525 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700526 if (sAppMarketIcon[coi] != null) {
527 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800528 }
Winson Chungadf0c182012-08-23 14:59:07 -0700529 if (mSearchDropTargetBar != null) {
530 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
531 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800532 }
Romain Guycbb89e42009-06-08 15:52:54 -0700533
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800534 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700535 if (sLocaleConfiguration == null) {
536 new AsyncTask<Void, Void, LocaleConfiguration>() {
537 @Override
538 protected LocaleConfiguration doInBackground(Void... unused) {
539 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
540 readConfiguration(Launcher.this, localeConfiguration);
541 return localeConfiguration;
542 }
543
544 @Override
545 protected void onPostExecute(LocaleConfiguration result) {
546 sLocaleConfiguration = result;
547 checkForLocaleChange(); // recursive, but now with a locale configuration
548 }
549 }.execute();
550 return;
551 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700552
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800553 final Configuration configuration = getResources().getConfiguration();
554
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700555 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800556 final String locale = configuration.locale.toString();
557
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700558 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800559 final int mcc = configuration.mcc;
560
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700561 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800562 final int mnc = configuration.mnc;
563
Romain Guy84f296c2009-11-04 15:00:44 -0800564 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800565
Romain Guy84f296c2009-11-04 15:00:44 -0800566 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700567 sLocaleConfiguration.locale = locale;
568 sLocaleConfiguration.mcc = mcc;
569 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700570
Joe Onorato0589f0f2010-02-08 13:44:00 -0800571 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700572
573 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
574 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700575 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 public void run() {
577 writeConfiguration(Launcher.this, localeConfiguration);
578 }
579 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700580 }
581 }
582
583 private static class LocaleConfiguration {
584 public String locale;
585 public int mcc = -1;
586 public int mnc = -1;
587 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700588
Romain Guy98d01652009-06-30 16:21:04 -0700589 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
590 DataInputStream in = null;
591 try {
592 in = new DataInputStream(context.openFileInput(PREFERENCES));
593 configuration.locale = in.readUTF();
594 configuration.mcc = in.readInt();
595 configuration.mnc = in.readInt();
596 } catch (FileNotFoundException e) {
597 // Ignore
598 } catch (IOException e) {
599 // Ignore
600 } finally {
601 if (in != null) {
602 try {
603 in.close();
604 } catch (IOException e) {
605 // Ignore
606 }
607 }
608 }
609 }
610
611 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
612 DataOutputStream out = null;
613 try {
614 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
615 out.writeUTF(configuration.locale);
616 out.writeInt(configuration.mcc);
617 out.writeInt(configuration.mnc);
618 out.flush();
619 } catch (FileNotFoundException e) {
620 // Ignore
621 } catch (IOException e) {
622 //noinspection ResultOfMethodCallIgnored
623 context.getFileStreamPath(PREFERENCES).delete();
624 } finally {
625 if (out != null) {
626 try {
627 out.close();
628 } catch (IOException e) {
629 // Ignore
630 }
631 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800632 }
633 }
634
Bjorn Bringertc459e522013-06-07 19:36:01 +0100635 public LayoutInflater getInflater() {
636 return mInflater;
637 }
638
Adam Cohen716b51e2011-06-30 12:09:54 -0700639 public DragLayer getDragLayer() {
640 return mDragLayer;
641 }
642
Winson Chung36a62fe2012-05-06 18:04:42 -0700643 boolean isDraggingEnabled() {
644 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
645 // that is subsequently removed from the workspace in startBinding().
646 return !mModel.isLoadingWorkspace();
647 }
648
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800649 static int getScreen() {
650 synchronized (sLock) {
651 return sScreen;
652 }
653 }
654
655 static void setScreen(int screen) {
656 synchronized (sLock) {
657 sScreen = screen;
658 }
659 }
660
Winson Chung557d6ed2011-07-08 15:34:52 -0700661 /**
662 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
663 * a configuration step, this allows the proper animations to run after other transitions.
664 */
665 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700666 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800667 switch (args.requestCode) {
668 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700669 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700670 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800671 break;
672 case REQUEST_PICK_SHORTCUT:
673 processShortcut(args.intent);
674 break;
675 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700676 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700677 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700678 result = true;
679 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800680 case REQUEST_CREATE_APPWIDGET:
681 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700682 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700683 result = true;
684 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800685 }
Michael Jurka27614d22012-04-02 06:40:22 -0700686 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
687 // if you turned the screen off and then back while in All Apps, Launcher would not
688 // return to the workspace. Clearing mAddInfo.container here fixes this issue
689 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700690 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800691 }
692
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700694 protected void onActivityResult(
695 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700696 // Reset the startActivity waiting flag
697 mWaitingForResult = false;
698
Michael Jurka8b805b12012-04-18 14:23:14 -0700699 if (requestCode == REQUEST_BIND_APPWIDGET) {
700 int appWidgetId = data != null ?
701 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
702 if (resultCode == RESULT_CANCELED) {
703 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
704 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700705 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700706 }
707 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200708 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
709 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
710 mWorkspace.exitOverviewMode(false);
711 }
712 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700713 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200714
Winson Chung557d6ed2011-07-08 15:34:52 -0700715 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800716 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
717 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700718
Adam Cohened66b2b2012-01-23 17:28:51 -0800719 // We have special handling for widgets
720 if (isWidgetDrop) {
721 int appWidgetId = data != null ?
722 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700723 if (appWidgetId < 0) {
724 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
725 "widget configuration activity.");
726 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
727 } else {
728 completeTwoStageWidgetDrop(resultCode, appWidgetId);
729 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800730 return;
731 }
732
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800733 // The pattern used here is that a user PICKs a specific application,
734 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700735
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
737 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700738 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800739 final PendingAddArguments args = new PendingAddArguments();
740 args.requestCode = requestCode;
741 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700742 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700743 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700744 args.cellX = mPendingAddInfo.cellX;
745 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800746 if (isWorkspaceLocked()) {
747 sPendingAddList.add(args);
748 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700749 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800751 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800752 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700753 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800754 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
755 null);
756 }
757
758 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700759 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700760 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800761 Runnable onCompleteRunnable = null;
762 int animationType = 0;
763
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700764 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800765 if (resultCode == RESULT_OK) {
766 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
767 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700768 mPendingAddWidgetInfo);
769 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800770 onCompleteRunnable = new Runnable() {
771 @Override
772 public void run() {
773 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700774 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800775 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
776 null);
777 }
778 };
779 } else if (resultCode == RESULT_CANCELED) {
780 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
781 onCompleteRunnable = new Runnable() {
782 @Override
783 public void run() {
784 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
785 null);
786 }
787 };
788 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700789 if (mDragLayer.getAnimatedView() != null) {
790 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
791 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
792 animationType, boundWidget, true);
793 } else {
794 // The animated view may be null in the case of a rotation during widget configuration
795 onCompleteRunnable.run();
796 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800797 }
798
799 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700800 protected void onStop() {
801 super.onStop();
802 FirstFrameAnimatorHelper.setIsVisible(false);
803 }
804
805 @Override
806 protected void onStart() {
807 super.onStart();
808 FirstFrameAnimatorHelper.setIsVisible(true);
809 }
810
811 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800812 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200813 long startTime = 0;
814 if (DEBUG_RESUME_TIME) {
815 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400816 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200817 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700819
Winson Chung4a2afa32012-07-19 14:53:05 -0700820 // Restore the previous launcher state
821 if (mOnResumeState == State.WORKSPACE) {
822 showWorkspace(false);
823 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700824 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700825 }
826 mOnResumeState = State.NONE;
827
Craig Mautner360310b2012-10-26 15:13:08 -0700828 // Background was set to gradient in onPause(), restore to black if in all apps.
829 setWorkspaceBackground(mState == State.WORKSPACE);
830
Winson Chungde0fb8f2012-05-08 14:37:08 -0700831 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700832 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700833
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800834 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700835 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700836 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400837 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700838 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400839 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700840 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700842 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200843 // We might have postponed some bind calls until onResume (see waitUntilResume) --
844 // execute them here
845 long startTimeCallbacks = 0;
846 if (DEBUG_RESUME_TIME) {
847 startTimeCallbacks = System.currentTimeMillis();
848 }
849
850 if (mAppsCustomizeContent != null) {
851 mAppsCustomizeContent.setBulkBind(true);
852 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700853 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
854 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200855 }
856 if (mAppsCustomizeContent != null) {
857 mAppsCustomizeContent.setBulkBind(false);
858 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700859 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200860 if (DEBUG_RESUME_TIME) {
861 Log.d(TAG, "Time spent processing callbacks in onResume: " +
862 (System.currentTimeMillis() - startTimeCallbacks));
863 }
Michael Jurka447bf842013-05-15 14:52:15 +0200864 }
Michael Jurka54554252013-08-01 12:52:23 +0200865 if (mOnResumeCallbacks.size() > 0) {
866 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
867 mOnResumeCallbacks.get(i).run();
868 }
869 mOnResumeCallbacks.clear();
870 }
Winson Chunge4e50662012-01-23 14:45:13 -0800871
872 // Reset the pressed state of icons that were locked in the press state while activities
873 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800874 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800875 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800876 mWaitingForResume.setStayPressed(false);
877 }
Winson Chunge4e50662012-01-23 14:45:13 -0800878 if (mAppsCustomizeContent != null) {
879 // Resets the previous all apps icon press state
880 mAppsCustomizeContent.resetDrawableState();
881 }
Adam Cohen06dff352012-06-01 17:17:08 -0700882 // It is possible that widgets can receive updates while launcher is not in the foreground.
883 // Consequently, the widgets will be inflated in the orientation of the foreground activity
884 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
885 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700886 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700887
888 // Again, as with the above scenario, it's possible that one or more of the global icons
889 // were updated in the wrong orientation.
890 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200891 if (DEBUG_RESUME_TIME) {
892 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
893 }
Adam Cohen06dff352012-06-01 17:17:08 -0700894 }
895
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700897 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700898 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
899 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
900 // when Launcher resumes and we are still in AllApps.
901 updateWallpaperVisibility(true);
902
Winson Chung997a9232013-07-24 15:33:46 -0700903 // Ensure that items added to Launcher are queued until Launcher returns
904 InstallShortcutReceiver.enableInstallQueue();
905
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700906 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700907 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800908 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700909 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700910 }
Romain Guycbb89e42009-06-08 15:52:54 -0700911
Adam Cohen66a01fd2013-06-11 12:48:00 -0700912 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600913 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
914 addCustomContentToLeft();
915 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700916 }
917
Adam Cohenbffe7452013-07-22 18:21:45 -0700918 QSBScroller mQsbScroller = new QSBScroller() {
919 int scrollY = 0;
920
921 @Override
922 public void setScrollY(int scroll) {
923 scrollY = scroll;
924
925 if (mWorkspace.isOnOrMovingToCustomContent()) {
926 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100927 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700928 }
929 }
930 };
931
932 public void resetQSBScroll() {
933 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100934 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700935 }
936
937 public interface CustomContentCallbacks {
938 // Custom content is completely shown
939 public void onShow();
940
941 // Custom content is completely hidden
942 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700943
944 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
945 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700946 }
947
Adam Cohen30bacb22013-08-29 14:25:25 -0700948 protected void startSettings() {
949 }
950
Adam Cohenbffe7452013-07-22 18:21:45 -0700951 public interface QSBScroller {
952 public void setScrollY(int scrollY);
953 }
954
Adam Cohen66a01fd2013-06-11 12:48:00 -0700955 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700956 public QSBScroller addToCustomContentPage(View customContent) {
957 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700958 }
959
Winson Chung98ca0f72013-07-29 12:58:51 -0700960 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700961 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700962 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700963 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700964 }
965
Adam Cohenedb40762013-07-18 16:45:45 -0700966 // The custom content needs to offset its content to account for the QSB
967 public int getTopOffsetForCustomContent() {
968 return mWorkspace.getPaddingTop();
969 }
970
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700971 @Override
972 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400973 // Flag the loader to stop early before switching
974 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700975 if (mAppsCustomizeContent != null) {
976 mAppsCustomizeContent.surrender();
977 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800978 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700979 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700980
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800981 // We can't hide the IME if it was forced open. So don't bother
982 /*
983 @Override
984 public void onWindowFocusChanged(boolean hasFocus) {
985 super.onWindowFocusChanged(hasFocus);
986
987 if (hasFocus) {
988 final InputMethodManager inputManager = (InputMethodManager)
989 getSystemService(Context.INPUT_METHOD_SERVICE);
990 WindowManager.LayoutParams lp = getWindow().getAttributes();
991 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
992 android.os.Handler()) {
993 protected void onReceiveResult(int resultCode, Bundle resultData) {
994 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
995 }
996 });
997 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
998 }
999 }
1000 */
1001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001002 private boolean acceptFilter() {
1003 final InputMethodManager inputManager = (InputMethodManager)
1004 getSystemService(Context.INPUT_METHOD_SERVICE);
1005 return !inputManager.isFullscreenMode();
1006 }
1007
1008 @Override
1009 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001010 final int uniChar = event.getUnicodeChar();
1011 final boolean handled = super.onKeyDown(keyCode, event);
1012 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1013 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001014 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1015 keyCode, event);
1016 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001017 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001018 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001019 // showSearchDialog()
1020 // If there are multiple keystrokes before the search dialog takes focus,
1021 // onSearchRequested() will be called for every keystroke,
1022 // but it is idempotent, so it's fine.
1023 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001024 }
1025 }
1026
Joe Onorato8a9625e2010-01-28 15:55:35 -08001027 // Eat the long press event so the keyboard doesn't come up.
1028 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1029 return true;
1030 }
1031
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 return handled;
1033 }
1034
Karl Rosaen138a0412009-04-23 19:00:21 -07001035 private String getTypedText() {
1036 return mDefaultKeySsb.toString();
1037 }
1038
1039 private void clearTypedText() {
1040 mDefaultKeySsb.clear();
1041 mDefaultKeySsb.clearSpans();
1042 Selection.setSelection(mDefaultKeySsb, 0);
1043 }
1044
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001045 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001046 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1047 * State
1048 */
1049 private static State intToState(int stateOrdinal) {
1050 State state = State.WORKSPACE;
1051 final State[] stateValues = State.values();
1052 for (int i = 0; i < stateValues.length; i++) {
1053 if (stateValues[i].ordinal() == stateOrdinal) {
1054 state = stateValues[i];
1055 break;
1056 }
1057 }
1058 return state;
1059 }
1060
1061 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 * Restores the previous state, if it exists.
1063 *
1064 * @param savedState The previous state.
1065 */
1066 private void restoreState(Bundle savedState) {
1067 if (savedState == null) {
1068 return;
1069 }
1070
Michael Jurka883f55b2010-10-21 15:47:14 -07001071 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001072 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001073 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001074 }
1075
Winson Chungf0c6ae02012-03-21 16:10:31 -07001076 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001078 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001079 }
1080
Winson Chung3d503fb2011-07-13 17:25:49 -07001081 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001082 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001083
Winson Chung3d503fb2011-07-13 17:25:49 -07001084 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1085 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001086 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001087 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1088 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001089 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1090 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1091 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001092 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001093 mRestoring = true;
1094 }
1095
1096 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1097 if (renameFolder) {
1098 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001099 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001100 mRestoring = true;
1101 }
Winson Chunga12a2502010-12-20 14:41:35 -08001102
Winson Chung785d2eb2011-04-14 16:08:02 -07001103 // Restore the AppsCustomize tab
1104 if (mAppsCustomizeTabHost != null) {
1105 String curTab = savedState.getString("apps_customize_currentTab");
1106 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001107 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001108 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001109 mAppsCustomizeContent.loadAssociatedPages(
1110 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001111 }
1112
Winson Chung5afbf7b2011-07-25 11:53:08 -07001113 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1114 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001115 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001116 }
1117
1118 /**
1119 * Finds all the views we need and configure them properly.
1120 */
1121 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001122 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001123
Craig Mautner360310b2012-10-26 15:13:08 -07001124 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001125 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1126 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001127
John Spurlock77e1f472013-09-11 10:09:51 -04001128 mLauncherView.setSystemUiVisibility(
1129 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001130 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131
Winson Chung4c98d922011-05-31 16:50:48 -07001132 // Setup the drag layer
1133 mDragLayer.setup(this, dragController);
1134
Winson Chung3d503fb2011-07-13 17:25:49 -07001135 // Setup the hotseat
1136 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1137 if (mHotseat != null) {
1138 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001139 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001140 }
1141
Adam Cohenf358a4b2013-07-23 16:47:31 -07001142 mOverviewPanel = findViewById(R.id.overview_panel);
1143 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1144 @Override
1145 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001146 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001147 }
1148 });
1149 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1150 @Override
1151 public void onClick(View arg0) {
1152 startWallpaper();
1153 }
1154 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001155 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1156 @Override
1157 public void onClick(View arg0) {
1158 startSettings();
1159 }
1160 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001161 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001162
Winson Chung4c98d922011-05-31 16:50:48 -07001163 // Setup the workspace
1164 mWorkspace.setHapticFeedbackEnabled(false);
1165 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001166 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001167 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001168
Winson Chungf0ea4d32011-06-06 14:27:16 -07001169 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001170 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001171
Winson Chungf0ea4d32011-06-06 14:27:16 -07001172 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001173 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001174 mAppsCustomizeContent = (AppsCustomizePagedView)
1175 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1176 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001177
Winson Chung3d503fb2011-07-13 17:25:49 -07001178 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001179 dragController.setDragScoller(mWorkspace);
1180 dragController.setScrollView(mDragLayer);
1181 dragController.setMoveTarget(mWorkspace);
1182 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001183 if (mSearchDropTargetBar != null) {
1184 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001185 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001186
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001187 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001188 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001189 mWeightWatcher = new WeightWatcher(this);
1190 mWeightWatcher.setAlpha(0.5f);
1191 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001192 new FrameLayout.LayoutParams(
1193 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001194 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001195 Gravity.BOTTOM)
1196 );
Adam Cohen39a06042013-07-19 14:30:12 -07001197
1198 boolean show = shouldShowWeightWatcher();
1199 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001200 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 }
1202
1203 /**
1204 * Creates a view representing a shortcut.
1205 *
1206 * @param info The data structure describing the shortcut.
1207 *
1208 * @return A View inflated from R.layout.application.
1209 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001210 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001212 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 }
1214
1215 /**
1216 * Creates a view representing a shortcut inflated from the specified resource.
1217 *
1218 * @param layoutResId The id of the XML layout used to create the shortcut.
1219 * @param parent The group the shortcut belongs to.
1220 * @param info The data structure describing the shortcut.
1221 *
1222 * @return A View inflated from layoutResId.
1223 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001224 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001225 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1226 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001227 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 return favorite;
1229 }
1230
1231 /**
1232 * Add an application shortcut to the workspace.
1233 *
1234 * @param data The intent describing the application.
1235 * @param cellInfo The position on screen where to create the shortcut.
1236 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001237 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001238 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001239 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001240
Adam Cohenfbba09b2011-07-18 21:43:05 -07001241 // First we check if we already know the exact location where we want to add this item.
1242 if (cellX >= 0 && cellY >= 0) {
1243 cellXY[0] = cellX;
1244 cellXY[1] = cellY;
1245 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001246 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001247 return;
1248 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001250 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001251
Romain Guy73b979d2009-06-09 12:57:21 -07001252 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001253 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001255 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001256 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001257 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001258 } else {
1259 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 }
1261 }
Romain Guycbb89e42009-06-08 15:52:54 -07001262
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001263 /**
1264 * Add a shortcut to the workspace.
1265 *
1266 * @param data The intent describing the shortcut.
1267 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001269 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001270 int cellY) {
1271 int[] cellXY = mTmpAddItemCellCoordinates;
1272 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001273 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001274
Michael Jurkad3ef3062010-11-23 16:23:58 -08001275 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001276
Adam Cohen558baaf2011-08-15 15:22:57 -07001277 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001278 if (info == null) {
1279 return;
1280 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001281 final View view = createShortcut(info);
1282
Adam Cohenfbba09b2011-07-18 21:43:05 -07001283 // First we check if we already know the exact location where we want to add this item.
1284 if (cellX >= 0 && cellY >= 0) {
1285 cellXY[0] = cellX;
1286 cellXY[1] = cellY;
1287 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001288
1289 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001290 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001291 true, null,null)) {
1292 return;
1293 }
1294 DragObject dragObject = new DragObject();
1295 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001296 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1297 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001298 return;
1299 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001300 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001301 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001302 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001303 foundCellSpan = (result != null);
1304 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001305 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001306 }
1307
1308 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001309 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001310 return;
1311 }
1312
Adam Cohendcd297f2013-06-18 13:13:40 -07001313 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314
1315 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001316 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001317 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 }
1319 }
1320
Adam Cohen2f093b62012-04-30 18:59:53 -07001321 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1322 int minHeight) {
1323 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001324 // We want to account for the extra amount of padding that we are adding to the widget
1325 // to ensure that it gets the full amount of space that it has requested
1326 int requiredWidth = minWidth + padding.left + padding.right;
1327 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001328 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001329 }
1330
Adam Cohen2f093b62012-04-30 18:59:53 -07001331 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1332 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001333 }
1334
Adam Cohen2f093b62012-04-30 18:59:53 -07001335 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1336 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001337 }
1338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1340 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001341 }
1342
Adam Cohen2f093b62012-04-30 18:59:53 -07001343 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1344 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001345 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001346 }
1347
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001348 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001349 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001351 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001352 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001354 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001355 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1356 if (appWidgetInfo == null) {
1357 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1358 }
Romain Guycbb89e42009-06-08 15:52:54 -07001359
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001360 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001361 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001362
Adam Cohen2f093b62012-04-30 18:59:53 -07001363 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1364 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001365
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001367 // We have saved the position to which the widget was dragged-- this really only matters
1368 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001369 int[] cellXY = mTmpAddItemCellCoordinates;
1370 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001371 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001372 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001373 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1374 cellXY[0] = mPendingAddInfo.cellX;
1375 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001376 spanXY[0] = mPendingAddInfo.spanX;
1377 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001378 foundCellSpan = true;
1379 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001380 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001381 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001382 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1383 spanXY[1], cellXY, finalSpan);
1384 spanXY[0] = finalSpan[0];
1385 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001386 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001387 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001388 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001389 }
1390
Michael Jurka0280c3b2010-09-17 15:00:07 -07001391 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001392 if (appWidgetId != -1) {
1393 // Deleting an app widget ID is a void call but writes to disk before returning
1394 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001395 new Thread("deleteAppWidgetId") {
1396 public void run() {
1397 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1398 }
1399 }.start();
1400 }
Winson Chung93eef082012-03-23 15:59:27 -07001401 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001402 return;
1403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001405 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001406 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1407 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001408 launcherInfo.spanX = spanXY[0];
1409 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001410 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1411 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001412
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001413 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001414 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001415
1416 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001417 if (hostView == null) {
1418 // Perform actual inflation because we're live
1419 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1420 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1421 } else {
1422 // The AppWidgetHostView has already been inflated and instantiated
1423 launcherInfo.hostView = hostView;
1424 }
Romain Guycbb89e42009-06-08 15:52:54 -07001425
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001426 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001427 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001428 launcherInfo.notifyWidgetSizeChanged(this);
1429
Adam Cohendcd297f2013-06-18 13:13:40 -07001430 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001431 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001432
1433 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001435 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 }
Romain Guycbb89e42009-06-08 15:52:54 -07001437
Adam Cohended9f8d2010-11-03 13:25:16 -07001438 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1439 @Override
1440 public void onReceive(Context context, Intent intent) {
1441 final String action = intent.getAction();
1442 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1443 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001444 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001445 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001446
Winson Chungc100e8e2011-08-09 16:02:43 -07001447 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001448 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001449 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001450 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001451 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001452 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1453 mUserPresent = true;
1454 updateRunning();
1455 }
1456 }
1457 };
1458
1459 @Override
1460 public void onAttachedToWindow() {
1461 super.onAttachedToWindow();
1462
1463 // Listen for broadcasts related to user-presence
1464 final IntentFilter filter = new IntentFilter();
1465 filter.addAction(Intent.ACTION_SCREEN_OFF);
1466 filter.addAction(Intent.ACTION_USER_PRESENT);
1467 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001468 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001469 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001470 mVisible = true;
1471 }
1472
1473 @Override
1474 public void onDetachedFromWindow() {
1475 super.onDetachedFromWindow();
1476 mVisible = false;
1477
Adam Cohend113e0c2010-11-11 10:48:05 -08001478 if (mAttached) {
1479 unregisterReceiver(mReceiver);
1480 mAttached = false;
1481 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001482 updateRunning();
1483 }
1484
1485 public void onWindowVisibilityChanged(int visibility) {
1486 mVisible = visibility == View.VISIBLE;
1487 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001488 // The following code used to be in onResume, but it turns out onResume is called when
1489 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1490 // is a more appropriate event to handle
1491 if (mVisible) {
1492 mAppsCustomizeTabHost.onWindowVisible();
1493 if (!mWorkspaceLoading) {
1494 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001495 // We want to let Launcher draw itself at least once before we force it to build
1496 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001497 // apps is nice and speedy.
1498 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001499 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001500 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001501 if (mStarted) return;
1502 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001503 // We delay the layer building a bit in order to give
1504 // other message processing a time to run. In particular
1505 // this avoids a delay in hiding the IME if it was
1506 // currently shown, because doing that may involve
1507 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001508 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001509 final ViewTreeObserver.OnDrawListener listener = this;
1510 mWorkspace.post(new Runnable() {
1511 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001512 if (mWorkspace != null &&
1513 mWorkspace.getViewTreeObserver() != null) {
1514 mWorkspace.getViewTreeObserver().
1515 removeOnDrawListener(listener);
1516 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001517 }
1518 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001519 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001520 }
1521 });
1522 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001523 // When Launcher comes back to foreground, a different Activity might be responsible for
1524 // the app market intent, so refresh the icon
1525 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001526 clearTypedText();
1527 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001528 }
1529
1530 private void sendAdvanceMessage(long delay) {
1531 mHandler.removeMessages(ADVANCE_MSG);
1532 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1533 mHandler.sendMessageDelayed(msg, delay);
1534 mAutoAdvanceSentTime = System.currentTimeMillis();
1535 }
1536
1537 private void updateRunning() {
1538 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1539 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1540 mAutoAdvanceRunning = autoAdvanceRunning;
1541 if (autoAdvanceRunning) {
1542 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1543 sendAdvanceMessage(delay);
1544 } else {
1545 if (!mWidgetsToAdvance.isEmpty()) {
1546 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1547 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1548 }
1549 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001550 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001551 }
1552 }
1553 }
1554
1555 private final Handler mHandler = new Handler() {
1556 @Override
1557 public void handleMessage(Message msg) {
1558 if (msg.what == ADVANCE_MSG) {
1559 int i = 0;
1560 for (View key: mWidgetsToAdvance.keySet()) {
1561 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1562 final int delay = mAdvanceStagger * i;
1563 if (v instanceof Advanceable) {
1564 postDelayed(new Runnable() {
1565 public void run() {
1566 ((Advanceable) v).advance();
1567 }
1568 }, delay);
1569 }
1570 i++;
1571 }
1572 sendAdvanceMessage(mAdvanceInterval);
1573 }
1574 }
1575 };
1576
1577 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001578 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001579 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1580 if (v instanceof Advanceable) {
1581 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001582 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001583 updateRunning();
1584 }
1585 }
1586
1587 void removeWidgetToAutoAdvance(View hostView) {
1588 if (mWidgetsToAdvance.containsKey(hostView)) {
1589 mWidgetsToAdvance.remove(hostView);
1590 updateRunning();
1591 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001592 }
1593
Joe Onorato9c1289c2009-08-17 11:03:03 -04001594 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001595 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001596 launcherInfo.hostView = null;
1597 }
1598
Winson Chung93eef082012-03-23 15:59:27 -07001599 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1600 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1601 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001602 }
1603
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001604 public LauncherAppWidgetHost getAppWidgetHost() {
1605 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
Romain Guycbb89e42009-06-08 15:52:54 -07001607
Winson Chunga9abd0e2010-10-27 17:18:37 -07001608 public LauncherModel getModel() {
1609 return mModel;
1610 }
1611
Bjorn Bringertc459e522013-06-07 19:36:01 +01001612 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001613 getWindow().closeAllPanels();
1614
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001615 // Whatever we were doing is hereby canceled.
1616 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001617 }
1618
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001619 @Override
1620 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001621 long startTime = 0;
1622 if (DEBUG_RESUME_TIME) {
1623 startTime = System.currentTimeMillis();
1624 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625 super.onNewIntent(intent);
1626
1627 // Close the menu
1628 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001629 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001630 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001631
Jamie Genniscb222e82012-10-23 15:44:26 -07001632 final boolean alreadyOnHome =
1633 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001634 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001635
Jamie Genniscb222e82012-10-23 15:44:26 -07001636 Runnable processIntent = new Runnable() {
1637 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001638 if (mWorkspace == null) {
1639 // Can be cases where mWorkspace is null, this prevents a NPE
1640 return;
1641 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001642 Folder openFolder = mWorkspace.getOpenFolder();
1643 // In all these cases, only animate if we're already on home
1644 mWorkspace.exitWidgetResizeMode();
1645 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1646 openFolder == null) {
1647 mWorkspace.moveToDefaultScreen(true);
1648 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001649
Jamie Genniscb222e82012-10-23 15:44:26 -07001650 closeFolder();
1651 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001652
Jamie Genniscb222e82012-10-23 15:44:26 -07001653 // If we are already on home, then just animate back to the workspace,
1654 // otherwise, just wait until onResume to set the state back to Workspace
1655 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001656 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001657 } else {
1658 mOnResumeState = State.WORKSPACE;
1659 }
1660
1661 final View v = getWindow().peekDecorView();
1662 if (v != null && v.getWindowToken() != null) {
1663 InputMethodManager imm = (InputMethodManager)getSystemService(
1664 INPUT_METHOD_SERVICE);
1665 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1666 }
1667
Winson Chung7819a562013-09-19 15:55:45 -07001668 // Reset the apps customize page
1669 if (mAppsCustomizeTabHost != null) {
Jamie Genniscb222e82012-10-23 15:44:26 -07001670 mAppsCustomizeTabHost.reset();
1671 }
1672 }
1673 };
1674
1675 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1676 // Delay processing of the intent to allow the status bar animation to finish
1677 // first in order to avoid janky animations.
1678 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001679 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001680 // Process the intent immediately.
1681 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001682 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001683
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 }
Michael Jurka447bf842013-05-15 14:52:15 +02001685 if (DEBUG_RESUME_TIME) {
1686 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1687 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001688 }
1689
Adam Cohen040a5d22013-09-16 17:09:33 -07001690 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1691 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001692 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001693 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001694 }
1695 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001696 protected void showWorkspaceAndExitOverviewMode() {
1697 showWorkspaceAndExitOverviewMode(true);
1698 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001699
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001701 public void onRestoreInstanceState(Bundle state) {
1702 super.onRestoreInstanceState(state);
1703 for (int page: mSynchronouslyBoundPages) {
1704 mWorkspace.restoreInstanceStateForChild(page);
1705 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001706 }
1707
1708 @Override
1709 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001710 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001711 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712
Michael Jurka883f55b2010-10-21 15:47:14 -07001713 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001714 // We close any open folder since it will not be re-opened, and we need to make sure
1715 // this state is reflected.
1716 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717
Adam Cohendcd297f2013-06-18 13:13:40 -07001718 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001719 mWaitingForResult) {
1720 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001721 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001722 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1723 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001724 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1725 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1726 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 }
1728
1729 if (mFolderInfo != null && mWaitingForResult) {
1730 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1731 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1732 }
Michael Jurka946ad472010-07-09 18:05:18 -07001733
Winson Chung785d2eb2011-04-14 16:08:02 -07001734 // Save the current AppsCustomize tab
1735 if (mAppsCustomizeTabHost != null) {
1736 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1737 if (currentTabTag != null) {
1738 outState.putString("apps_customize_currentTab", currentTabTag);
1739 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001740 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1741 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001742 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743 }
1744
1745 @Override
1746 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001748
Winson Chunge7a03942011-08-05 15:05:12 -07001749 // Remove all pending runnables
1750 mHandler.removeMessages(ADVANCE_MSG);
1751 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001752 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001753
Winson Chungcd2b0142011-06-08 16:02:26 -07001754 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001755 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001756 mModel.stopLoader();
1757 app.setLauncher(null);
1758
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001760 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001761 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001762 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001763 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001764 mAppWidgetHost = null;
1765
1766 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767
1768 TextKeyListener.getInstance().release();
1769
Winson Chung81b52252012-08-27 15:34:29 -07001770 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1771 // to prevent leaking Launcher activities on orientation change.
1772 if (mModel != null) {
1773 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1774 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001775
1776 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001777 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001778
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001779 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001780 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1781 mWorkspace.removeAllViews();
1782 mWorkspace = null;
1783 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001784
Michael Jurka2ecf9952012-06-18 12:52:28 -07001785 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786 }
1787
Adam Cohena9cf38f2011-05-02 15:36:58 -07001788 public DragController getDragController() {
1789 return mDragController;
1790 }
1791
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792 @Override
1793 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001794 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 super.startActivityForResult(intent, requestCode);
1796 }
1797
Winson Chung70d72102011-08-12 11:24:35 -07001798 /**
1799 * Indicates that we want global search for this activity by setting the globalSearch
1800 * argument for {@link #startSearch} to true.
1801 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001803 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001804 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001805
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001806 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001807
Karl Rosaen138a0412009-04-23 19:00:21 -07001808 if (initialQuery == null) {
1809 // Use any text typed in the launcher as the initial query
1810 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001811 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 if (appSearchData == null) {
1813 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001814 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 }
Winson Chungadf0c182012-08-23 14:59:07 -07001816 Rect sourceBounds = new Rect();
1817 if (mSearchDropTargetBar != null) {
1818 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1819 }
Romain Guycbb89e42009-06-08 15:52:54 -07001820
Bjorn Bringertc459e522013-06-07 19:36:01 +01001821 startSearch(initialQuery, selectInitialQuery,
1822 appSearchData, sourceBounds);
1823 }
1824
1825 public void startSearch(String initialQuery,
1826 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001827 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001828 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001829 }
1830
1831 /**
1832 * Starts the global search activity. This code is a copied from SearchManager
1833 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001834 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001835 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001836 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001837 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1838 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1839 if (globalSearchActivity == null) {
1840 Log.w(TAG, "No global search activity found.");
1841 return;
1842 }
1843 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1844 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1845 intent.setComponent(globalSearchActivity);
1846 // Make sure that we have a Bundle to put source in
1847 if (appSearchData == null) {
1848 appSearchData = new Bundle();
1849 } else {
1850 appSearchData = new Bundle(appSearchData);
1851 }
1852 // Set source to package name of app that starts global search, if not set already.
1853 if (!appSearchData.containsKey("source")) {
1854 appSearchData.putString("source", getPackageName());
1855 }
1856 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1857 if (!TextUtils.isEmpty(initialQuery)) {
1858 intent.putExtra(SearchManager.QUERY, initialQuery);
1859 }
1860 if (selectInitialQuery) {
1861 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1862 }
1863 intent.setSourceBounds(sourceBounds);
1864 try {
1865 startActivity(intent);
1866 } catch (ActivityNotFoundException ex) {
1867 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1868 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001869 }
1870
Winson Chung70d72102011-08-12 11:24:35 -07001871 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001872 public boolean onPrepareOptionsMenu(Menu menu) {
1873 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001874 if (!mWorkspace.isInOverviewMode()) {
1875 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001876 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001877 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001878 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001880 @Override
1881 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001882 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001883 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001884 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001885 }
1886
Joe Onorato9c1289c2009-08-17 11:03:03 -04001887 public boolean isWorkspaceLocked() {
1888 return mWorkspaceLoading || mWaitingForResult;
1889 }
1890
Michael Jurka0280c3b2010-09-17 15:00:07 -07001891 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001892 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001893 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001894 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1895 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001896 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001897 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001898 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001899
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001900 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1901 AppWidgetProviderInfo appWidgetInfo) {
1902 if (appWidgetInfo.configure != null) {
1903 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001904
Bjorn Bringert7984c942009-12-09 15:38:25 +00001905 // Launch over to configure widget, if needed
1906 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001907 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001908 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001909 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001910 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001911 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001912 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001913 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001914 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001915 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001916 }
1917 }
Romain Guycbb89e42009-06-08 15:52:54 -07001918
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001919 protected void moveToCustomContentScreen(boolean animate) {
1920 mWorkspace.moveToCustomContentScreen(animate);
1921 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001922 /**
1923 * Process a shortcut drop.
1924 *
1925 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001926 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001927 * @param cell The cell it should be added to, optional
1928 * @param position The location on the screen where it was dropped, optional
1929 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001930 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001931 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001932 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001933 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001934 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001935 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001936
1937 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001938 mPendingAddInfo.cellX = cell[0];
1939 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001940 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001941
1942 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1943 createShortcutIntent.setComponent(componentName);
1944 processShortcut(createShortcutIntent);
1945 }
1946
Adam Cohenfbba09b2011-07-18 21:43:05 -07001947 /**
1948 * Process a widget drop.
1949 *
1950 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001951 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001952 * @param cell The cell it should be added to, optional
1953 * @param position The location on the screen where it was dropped, optional
1954 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001955 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001956 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001957 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001958 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001959 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001960 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001961 mPendingAddInfo.minSpanX = info.minSpanX;
1962 mPendingAddInfo.minSpanY = info.minSpanY;
1963
Adam Cohenfbba09b2011-07-18 21:43:05 -07001964 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 mPendingAddInfo.cellX = cell[0];
1966 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001967 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001968 if (span != null) {
1969 mPendingAddInfo.spanX = span[0];
1970 mPendingAddInfo.spanY = span[1];
1971 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001972
Adam Cohened66b2b2012-01-23 17:28:51 -08001973 AppWidgetHostView hostView = info.boundWidget;
1974 int appWidgetId;
1975 if (hostView != null) {
1976 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001977 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001978 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001979 // In this case, we either need to start an activity to get permission to bind
1980 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001981 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001982 Bundle options = info.bindOptions;
1983
1984 boolean success = false;
1985 if (options != null) {
1986 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1987 info.componentName, options);
1988 } else {
1989 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1990 info.componentName);
1991 }
1992 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001993 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001994 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001995 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001996 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1997 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1998 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001999 // TODO: we need to make sure that this accounts for the options bundle.
2000 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002001 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2002 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002003 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002004 }
2005
Joe Onoratodeb98af2010-02-19 14:59:39 -08002006 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002007 // Handle case where user selected "Applications"
2008 String applicationName = getResources().getString(R.string.group_applications);
2009 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002010
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002011 if (applicationName != null && applicationName.equals(shortcutName)) {
2012 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2013 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002014
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002015 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2016 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002017 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002018 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002019 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002020 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002021 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 }
2023
Winson Chung24ab2f12010-09-16 14:10:47 -07002024 void processWallpaper(Intent intent) {
2025 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2026 }
2027
Adam Cohendcd297f2013-06-18 13:13:40 -07002028 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002029 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002030 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 folderInfo.title = getText(R.string.folder_name);
2032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002034 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002035 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002036 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002037
2038 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002039 FolderIcon newFolder =
2040 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002041 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002042 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002043 // Force measure the new folder icon
2044 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2045 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002046 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 }
Romain Guycbb89e42009-06-08 15:52:54 -07002048
Joe Onorato9c1289c2009-08-17 11:03:03 -04002049 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002050 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002051 }
2052
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002053 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002054 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002056 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002057 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058 }
2059
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002060 protected ComponentName getWallpaperPickerComponent() {
2061 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2062 }
2063
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002064 /**
2065 * Registers various content observers. The current implementation registers
2066 * only a favorites observer to keep track of the favorites applications.
2067 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002068 private void registerContentObservers() {
2069 ContentResolver resolver = getContentResolver();
2070 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2071 true, mWidgetObserver);
2072 }
2073
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 @Override
2075 public boolean dispatchKeyEvent(KeyEvent event) {
2076 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2077 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002078 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002079 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002080 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002081 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002082 dumpState();
2083 return true;
2084 }
2085 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002086 }
2087 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2088 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002089 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002090 return true;
2091 }
2092 }
2093
2094 return super.dispatchKeyEvent(event);
2095 }
2096
Joe Onorato88ec0992009-11-19 13:16:06 -08002097 @Override
2098 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002099 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002100 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002101 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002102 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002103 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002104 Folder openFolder = mWorkspace.getOpenFolder();
2105 if (openFolder.isEditingName()) {
2106 openFolder.dismissEditingName();
2107 } else {
2108 closeFolder();
2109 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002110 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002111 mWorkspace.exitWidgetResizeMode();
2112
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002113 // Back button is a no-op here, but give at least some feedback for the button press
2114 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002115 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002116 }
2117
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002118 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002119 * Re-listen when widgets are reset.
2120 */
2121 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002122 if (mAppWidgetHost != null) {
2123 mAppWidgetHost.startListening();
2124 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002125 }
2126
2127 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 * Launches the intent referred by the clicked shortcut.
2129 *
2130 * @param v The view representing the clicked shortcut.
2131 */
2132 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002133 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2134 // view has detached (it's possible for this to happen if the view is removed mid touch).
2135 if (v.getWindowToken() == null) {
2136 return;
2137 }
2138
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002139 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002140 return;
2141 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002142
Adam Cohen1697b792013-09-17 19:08:21 -07002143 if (v instanceof Workspace) {
2144 if (mWorkspace.isInOverviewMode()) {
2145 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002146 }
2147 return;
2148 }
2149
2150 if (v instanceof CellLayout) {
2151 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002152 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002153 }
2154 }
2155
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002156 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002157 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002159 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2160 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002161
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002162 // Check for special shortcuts
2163 if (intent.getComponent() != null) {
2164 final String shortcutClass = intent.getComponent().getClassName();
2165
2166 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002167 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002168 return;
2169 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2170 MemoryDumpActivity.startDump(this);
2171 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002172 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2173 toggleShowWeightWatcher();
2174 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002175 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002176 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002177
2178 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002179 int[] pos = new int[2];
2180 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002181 intent.setSourceBounds(new Rect(pos[0], pos[1],
2182 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002183
2184 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002185
Daniel Sandlerff02d492013-08-05 02:12:05 -04002186 mStats.recordLaunch(intent, shortcut);
2187
Michael Jurkaddd62e92011-02-16 17:49:14 -08002188 if (success && v instanceof BubbleTextView) {
2189 mWaitingForResume = (BubbleTextView) v;
2190 mWaitingForResume.setStayPressed(true);
2191 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002192 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002193 if (v instanceof FolderIcon) {
2194 FolderIcon fi = (FolderIcon) v;
2195 handleFolderClick(fi);
2196 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002197 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002198 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002199 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002200 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002201 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002202 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 }
2204 }
2205
Michael Jurka0e260592010-06-30 17:07:39 -07002206 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002207 return false;
2208 }
2209
Michael Jurkaaf442092010-06-10 17:01:57 -07002210 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002211 * Event handler for the search button
2212 *
2213 * @param v The view that was clicked.
2214 */
2215 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002216 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2217
Amith Yamasania135ba82011-08-09 17:42:01 -07002218 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002219 }
2220
2221 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002222 * Event handler for the voice button
2223 *
2224 * @param v The view that was clicked.
2225 */
2226 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002227 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002228
Bjorn Bringertc459e522013-06-07 19:36:01 +01002229 startVoice();
2230 }
2231
2232 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002233 try {
2234 final SearchManager searchManager =
2235 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2236 ComponentName activityName = searchManager.getGlobalSearchActivity();
2237 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002238 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002239 if (activityName != null) {
2240 intent.setPackage(activityName.getPackageName());
2241 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002242 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002243 } catch (ActivityNotFoundException e) {
2244 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002245 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002246 startActivitySafely(null, intent, "onClickVoiceButton");
2247 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002248 }
2249
2250 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002251 * Event handler for the "grid" button that appears on the home screen, which
2252 * enters all apps mode.
2253 *
2254 * @param v The view that was clicked.
2255 */
2256 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002257 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002258 }
2259
2260 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002261 // Provide the same haptic feedback that the system offers for virtual keys.
2262 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002263 }
2264
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002265 public void onClickAppMarketButton(View v) {
2266 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002267 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002268 } else {
2269 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002270 }
2271 }
2272
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002273 /**
2274 * Called when the user stops interacting with the launcher.
2275 * This implies that the user is now on the homescreen and is not doing housekeeping.
2276 */
2277 protected void onInteractionEnd() {}
2278
2279 /**
2280 * Called when the user starts interacting with the launcher.
2281 * The possible interactions are:
2282 * - open all apps
2283 * - reorder an app shortcut, or a widget
2284 * - open the overview mode.
2285 * This is a good time to stop doing things that only make sense
2286 * when the user is on the homescreen and not doing housekeeping.
2287 */
2288 protected void onInteractionBegin() {}
2289
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002290 void startApplicationDetailsActivity(ComponentName componentName) {
2291 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002292 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2293 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002294 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002295 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002296 }
2297
Michael Jurka1e2f4652013-07-08 18:03:46 -07002298 // returns true if the activity was started
2299 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002300 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002301 // System applications cannot be installed. For now, show a toast explaining that.
2302 // We may give them the option of disabling apps this way.
2303 int messageId = R.string.uninstall_system_app_text;
2304 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002305 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002306 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002307 String packageName = componentName.getPackageName();
2308 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002309 Intent intent = new Intent(
2310 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002311 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2312 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002313 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002314 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002315 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002316 }
2317
Michael Jurka86a720e2012-05-09 11:23:23 -07002318 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002320
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002321 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002322 // Only launch using the new animation if the shortcut has not opted out (this is a
2323 // private contract between launcher and may be ignored in the future).
2324 boolean useLaunchAnimation = (v != null) &&
2325 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2326 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002327 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2328 v.getMeasuredWidth(), v.getMeasuredHeight());
2329
2330 startActivity(intent, opts.toBundle());
2331 } else {
2332 startActivity(intent);
2333 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002334 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002335 } catch (SecurityException e) {
2336 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002337 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002338 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002339 "or use the exported attribute for this activity. "
2340 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002341 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002342 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002343 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002344
Michael Jurka86a720e2012-05-09 11:23:23 -07002345 boolean startActivitySafely(View v, Intent intent, Object tag) {
2346 boolean success = false;
2347 try {
2348 success = startActivity(v, intent, tag);
2349 } catch (ActivityNotFoundException e) {
2350 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2351 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2352 }
2353 return success;
2354 }
2355
Adam Cohena9cf38f2011-05-02 15:36:58 -07002356 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002357 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002358 Folder openFolder = mWorkspace.getFolderForTag(info);
2359
2360 // If the folder info reports that the associated folder is open, then verify that
2361 // it is actually opened. There have been a few instances where this gets out of sync.
2362 if (info.opened && openFolder == null) {
2363 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002364 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002365 info.opened = false;
2366 }
2367
Adam Cohenfb91f302012-06-11 15:45:18 -07002368 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002369 // Close any open folder
2370 closeFolder();
2371 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002372 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 } else {
2374 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 int folderScreen;
2376 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002377 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002378 // .. and close it
2379 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002380 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002381 // Close any folder open on the current screen
2382 closeFolder();
2383 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002384 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 }
2386 }
2387 }
2388 }
2389
Adam Cohen268c4752012-06-06 17:47:33 -07002390 /**
2391 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2392 * in the DragLayer in the exact absolute location of the original FolderIcon.
2393 */
2394 private void copyFolderIconToImage(FolderIcon fi) {
2395 final int width = fi.getMeasuredWidth();
2396 final int height = fi.getMeasuredHeight();
2397
2398 // Lazy load ImageView, Bitmap and Canvas
2399 if (mFolderIconImageView == null) {
2400 mFolderIconImageView = new ImageView(this);
2401 }
2402 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2403 mFolderIconBitmap.getHeight() != height) {
2404 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2405 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2406 }
2407
2408 DragLayer.LayoutParams lp;
2409 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2410 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2411 } else {
2412 lp = new DragLayer.LayoutParams(width, height);
2413 }
2414
Adam Cohen307fe232012-08-16 17:55:58 -07002415 // The layout from which the folder is being opened may be scaled, adjust the starting
2416 // view size by this scale factor.
2417 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002418 lp.customPosition = true;
2419 lp.x = mRectForFolderAnimation.left;
2420 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002421 lp.width = (int) (scale * width);
2422 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002423
2424 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2425 fi.draw(mFolderIconCanvas);
2426 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002427 if (fi.getFolder() != null) {
2428 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2429 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002430 }
Adam Cohen268c4752012-06-06 17:47:33 -07002431 // Just in case this image view is still in the drag layer from a previous animation,
2432 // we remove it and re-add it.
2433 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2434 mDragLayer.removeView(mFolderIconImageView);
2435 }
2436 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002437 if (fi.getFolder() != null) {
2438 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002439 }
Adam Cohen268c4752012-06-06 17:47:33 -07002440 }
2441
Adam Cohen2801caf2011-05-13 20:57:39 -07002442 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002443 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002444 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2445 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2446 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2447
Adam Cohenc51934b2011-07-26 21:07:43 -07002448 FolderInfo info = (FolderInfo) fi.getTag();
2449 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2450 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002451 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2452 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002453 }
2454
Adam Cohen268c4752012-06-06 17:47:33 -07002455 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2456 copyFolderIconToImage(fi);
2457 fi.setVisibility(View.INVISIBLE);
2458
Michael Jurka2ecf9952012-06-18 12:52:28 -07002459 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002460 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002461 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2462 oa.start();
2463 }
2464
Adam Cohen268c4752012-06-06 17:47:33 -07002465 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002466 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002467 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2468 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2469 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2470
Adam Cohen268c4752012-06-06 17:47:33 -07002471 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002472
Adam Cohen268c4752012-06-06 17:47:33 -07002473 // We remove and re-draw the FolderIcon in-case it has changed
2474 mDragLayer.removeView(mFolderIconImageView);
2475 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002476 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002477 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002478 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002479 oa.addListener(new AnimatorListenerAdapter() {
2480 @Override
2481 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002482 if (cl != null) {
2483 cl.clearFolderLeaveBehind();
2484 // Remove the ImageView copy of the FolderIcon and make the original visible.
2485 mDragLayer.removeView(mFolderIconImageView);
2486 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002487 }
2488 }
2489 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002490 oa.start();
2491 }
2492
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002493 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002494 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002495 * is animated relative to the specified View. If the View is null, no animation
2496 * is played.
2497 *
2498 * @param folderInfo The FolderInfo describing the folder to open.
2499 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002500 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002501 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002502 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002503
Adam Cohena9cf38f2011-05-02 15:36:58 -07002504 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002505
Adam Cohen4554ee12011-08-03 16:13:21 -07002506 // Just verify that the folder hasn't already been added to the DragLayer.
2507 // There was a one-off crash where the folder had a parent already.
2508 if (folder.getParent() == null) {
2509 mDragLayer.addView(folder);
2510 mDragController.addDropTarget((DropTarget) folder);
2511 } else {
2512 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2513 folder.getParent() + ").");
2514 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002515 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002516 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002517
2518 // Notify the accessibility manager that this folder "window" has appeared and occluded
2519 // the workspace items
2520 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2521 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002522 }
2523
2524 public void closeFolder() {
2525 Folder folder = mWorkspace.getOpenFolder();
2526 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002527 if (folder.isEditingName()) {
2528 folder.dismissEditingName();
2529 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002530 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002531
2532 // Dismiss the folder cling
2533 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002534 }
2535 }
2536
2537 void closeFolder(Folder folder) {
2538 folder.getInfo().opened = false;
2539
2540 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2541 if (parent != null) {
2542 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2543 shrinkAndFadeInFolderIcon(fi);
2544 }
2545 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002546
2547 // Notify the accessibility manager that this folder "window" has disappeard and no
2548 // longer occludeds the workspace items
2549 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002550 }
2551
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002553 if (!isDraggingEnabled()) return false;
2554 if (isWorkspaceLocked()) return false;
2555 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002556
Adam Cohen1697b792013-09-17 19:08:21 -07002557 if (v instanceof Workspace) {
2558 if (!mWorkspace.isInOverviewMode()) {
2559 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2560 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2561 mWorkspace.enterOverviewMode();
2562 }
2563 return true;
2564 }
2565
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002566 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002567 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002568 }
2569
Michael Jurka0280c3b2010-09-17 15:00:07 -07002570 resetAddInfo();
2571 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002572 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002573 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002574 return true;
2575 }
2576
Winson Chung3d503fb2011-07-13 17:25:49 -07002577 // The hotseat touch handling does not go through Workspace, and we always allow long press
2578 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002579 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002580 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2581 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002582 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002583 // User long pressed on empty space
2584 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2585 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2586 // Disabling reordering until we sort out some issues.
2587 if (mWorkspace.isInOverviewMode()) {
2588 mWorkspace.startReordering(v);
2589 } else {
2590 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002591 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002592 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002593 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002594 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002595 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002596 }
2597 }
2598 }
2599 return true;
2600 }
2601
Winson Chung3d503fb2011-07-13 17:25:49 -07002602 boolean isHotseatLayout(View layout) {
2603 return mHotseat != null && layout != null &&
2604 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2605 }
2606 Hotseat getHotseat() {
2607 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002608 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002609 View getOverviewPanel() {
2610 return mOverviewPanel;
2611 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002612 SearchDropTargetBar getSearchBar() {
2613 return mSearchDropTargetBar;
2614 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002615
Winson Chung3d503fb2011-07-13 17:25:49 -07002616 /**
2617 * Returns the CellLayout of the specified container at the specified screen.
2618 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002619 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002620 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2621 if (mHotseat != null) {
2622 return mHotseat.getLayout();
2623 } else {
2624 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002625 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002626 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002627 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002628 }
2629 }
2630
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002631 Workspace getWorkspace() {
2632 return mWorkspace;
2633 }
2634
Daniel Sandler843e8602010-06-07 14:59:01 -04002635 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002636 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002637 }
2638
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002639 /**
2640 * Helper method for the cameraZoomIn/cameraZoomOut animations
2641 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002642 * @param scaleFactor The scale factor used for the zoom
2643 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002644 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002645 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002646 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002647 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002648
Winson Chung18f41f82012-05-09 13:28:10 -07002649 void disableWallpaperIfInAllApps() {
2650 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002651 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002652 if (mAppsCustomizeTabHost != null &&
2653 !mAppsCustomizeTabHost.isTransitioning()) {
2654 updateWallpaperVisibility(false);
2655 }
2656 }
2657 }
2658
Craig Mautner360310b2012-10-26 15:13:08 -07002659 private void setWorkspaceBackground(boolean workspace) {
2660 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002661 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002662 }
2663
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002664 void updateWallpaperVisibility(boolean visible) {
2665 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2666 int curflags = getWindow().getAttributes().flags
2667 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2668 if (wpflags != curflags) {
2669 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2670 }
Craig Mautner360310b2012-10-26 15:13:08 -07002671 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002672 }
2673
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002674 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2675 if (v instanceof LauncherTransitionable) {
2676 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2677 }
2678 }
2679
Michael Jurkabed61d22012-02-14 22:51:29 -08002680 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2681 if (v instanceof LauncherTransitionable) {
2682 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2683 }
Winson Chung70442722012-02-10 15:43:22 -08002684
2685 // Update the workspace transition step as well
2686 dispatchOnLauncherTransitionStep(v, 0f);
2687 }
2688
2689 private void dispatchOnLauncherTransitionStep(View v, float t) {
2690 if (v instanceof LauncherTransitionable) {
2691 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2692 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002693 }
2694
2695 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2696 if (v instanceof LauncherTransitionable) {
2697 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2698 }
Winson Chung70442722012-02-10 15:43:22 -08002699
2700 // Update the workspace transition step as well
2701 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002702 }
2703
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002704 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002705 * Things to test when changing the following seven functions.
2706 * - Home from workspace
2707 * - from center screen
2708 * - from other screens
2709 * - Home from all apps
2710 * - from center screen
2711 * - from other screens
2712 * - Back from all apps
2713 * - from center screen
2714 * - from other screens
2715 * - Launch app from workspace and quit
2716 * - with back
2717 * - with home
2718 * - Launch app from all apps and quit
2719 * - with back
2720 * - with home
2721 * - Go to a screen that's not the default, then all
2722 * apps, and launch and app, and go back
2723 * - with back
2724 * -with home
2725 * - On workspace, long press power and go back
2726 * - with back
2727 * - with home
2728 * - On all apps, long press power and go back
2729 * - with back
2730 * - with home
2731 * - On workspace, power off
2732 * - On all apps, power off
2733 * - Launch an app and turn off the screen while in that app
2734 * - Go back with home key
2735 * - Go back with back key TODO: make this not go to workspace
2736 * - From all apps
2737 * - From workspace
2738 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2739 * - From all apps
2740 * - From the center workspace
2741 * - From another workspace
2742 */
2743
2744 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002745 * Zoom the camera out from the workspace to reveal 'toView'.
2746 * Assumes that the view to show is anchored at either the very top or very bottom
2747 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002748 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002749 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002750 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2751 showAppsCustomizeHelper(animated, springLoaded, contentType);
2752 }
2753 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2754 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002755 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002756 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002757 mStateAnimation.cancel();
2758 mStateAnimation = null;
2759 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002760 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002761
Winson Chungf0ea4d32011-06-06 14:27:16 -07002762 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2763 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2764 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002765 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002766 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002767 final int startDelay =
2768 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002769
Michael Jurkab3e22d92011-10-31 15:58:33 -07002770 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002771
Michael Jurkad74c9842011-07-10 12:44:21 -07002772 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002773 Animator workspaceAnim =
2774 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002775 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2776 // Set the content type for the all apps space
2777 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2778 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002779
2780 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002781 toView.setScaleX(scale);
2782 toView.setScaleY(scale);
2783 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2784 scaleAnim.
2785 scaleX(1f).scaleY(1f).
2786 setDuration(duration).
2787 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002788
Winson Chungf0ea4d32011-06-06 14:27:16 -07002789 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002790 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002791 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002792 .ofFloat(toView, "alpha", 0f, 1f)
2793 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002794 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002795 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2796 @Override
2797 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002798 if (animation == null) {
2799 throw new RuntimeException("animation is null");
2800 }
Winson Chung70442722012-02-10 15:43:22 -08002801 float t = (Float) animation.getAnimatedValue();
2802 dispatchOnLauncherTransitionStep(fromView, t);
2803 dispatchOnLauncherTransitionStep(toView, t);
2804 }
2805 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002806
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002807 // toView should appear right at the end of the workspace shrink
2808 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002809 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002810 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002811 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002812
2813 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002814 boolean animationCancelled = false;
2815
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002816 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002817 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002818 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002819 // Prepare the position
2820 toView.setTranslationX(0.0f);
2821 toView.setTranslationY(0.0f);
2822 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002823 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002824 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002825 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002826 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002827 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2828 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002829
Adam Cohenf4ddea32011-09-12 13:46:42 -07002830 if (!animationCancelled) {
2831 updateWallpaperVisibility(false);
2832 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002833
2834 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002835 if (mSearchDropTargetBar != null) {
2836 mSearchDropTargetBar.hideSearchBar(false);
2837 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002838 }
2839
Adam Cohencff6af82011-09-13 14:51:53 -07002840 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002841 public void onAnimationCancel(Animator animation) {
2842 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002843 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002844 });
2845
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002846 if (workspaceAnim != null) {
2847 mStateAnimation.play(workspaceAnim);
2848 }
Michael Jurka1899a362011-11-03 13:50:45 -07002849
2850 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002851
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002852 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2853 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002854
2855 // If any of the objects being animated haven't been measured/laid out
2856 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002857 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002858 (mWorkspace.getMeasuredWidth() == 0) ||
2859 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002860 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002861 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002862
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002863 final AnimatorSet stateAnimation = mStateAnimation;
2864 final Runnable startAnimRunnable = new Runnable() {
2865 public void run() {
2866 // Check that mStateAnimation hasn't changed while
2867 // we waited for a layout/draw pass
2868 if (mStateAnimation != stateAnimation)
2869 return;
2870 setPivotsForZoom(toView, scale);
2871 dispatchOnLauncherTransitionStart(fromView, animated, false);
2872 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002873 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002874 }
2875 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002876 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002877 final ViewTreeObserver observer = toView.getViewTreeObserver();
2878 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2879 public void onGlobalLayout() {
2880 startAnimRunnable.run();
2881 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2882 }
2883 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002884 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002885 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002886 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002887 } else {
2888 toView.setTranslationX(0.0f);
2889 toView.setTranslationY(0.0f);
2890 toView.setScaleX(1.0f);
2891 toView.setScaleY(1.0f);
2892 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002893 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002894
Daniel Sandlere4f98912013-06-25 15:13:26 -04002895 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002896 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002897 if (mSearchDropTargetBar != null) {
2898 mSearchDropTargetBar.hideSearchBar(false);
2899 }
Michael Jurkaabded662011-03-04 12:06:57 -08002900 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002901 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002902 dispatchOnLauncherTransitionStart(fromView, animated, false);
2903 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002904 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002905 dispatchOnLauncherTransitionStart(toView, animated, false);
2906 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002907 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002908 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002909 }
2910
2911 /**
2912 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002913 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002914 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002915 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002916 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2917 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002918
Michael Jurkab3e22d92011-10-31 15:58:33 -07002919 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002920 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002921 mStateAnimation.cancel();
2922 mStateAnimation = null;
2923 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002924 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002925
Winson Chungf0ea4d32011-06-06 14:27:16 -07002926 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002927 final int fadeOutDuration =
2928 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002929 final float scaleFactor = (float)
2930 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2931 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002932 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002933 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002934 if (toState == State.WORKSPACE) {
2935 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2936 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002937 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002938 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2939 workspaceAnim = mWorkspace.getChangeStateAnimation(
2940 Workspace.State.SPRING_LOADED, animated);
2941 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002942
Michael Jurkab3e22d92011-10-31 15:58:33 -07002943 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002944 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002945 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002946 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002947 final LauncherViewPropertyAnimator scaleAnim =
2948 new LauncherViewPropertyAnimator(fromView);
2949 scaleAnim.
2950 scaleX(scaleFactor).scaleY(scaleFactor).
2951 setDuration(duration).
2952 setInterpolator(new Workspace.ZoomInInterpolator());
2953
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002954 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002955 .ofFloat(fromView, "alpha", 1f, 0f)
2956 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002957 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002958 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2959 @Override
2960 public void onAnimationUpdate(ValueAnimator animation) {
2961 float t = 1f - (Float) animation.getAnimatedValue();
2962 dispatchOnLauncherTransitionStep(fromView, t);
2963 dispatchOnLauncherTransitionStep(toView, t);
2964 }
2965 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002966
Michael Jurka2ecf9952012-06-18 12:52:28 -07002967 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002968
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002969 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2970 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002971 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002972
2973 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002974 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002975 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002976 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002977 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002978 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2979 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002980 if (onCompleteRunnable != null) {
2981 onCompleteRunnable.run();
2982 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002983 mAppsCustomizeContent.updateCurrentPageScroll();
2984 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002985 }
2986 });
2987
Winson Chungf0ea4d32011-06-06 14:27:16 -07002988 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002989 if (workspaceAnim != null) {
2990 mStateAnimation.play(workspaceAnim);
2991 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002992 dispatchOnLauncherTransitionStart(fromView, animated, true);
2993 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002994 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002995 } else {
2996 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002997 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002998 dispatchOnLauncherTransitionStart(fromView, animated, true);
2999 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003000 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003001 dispatchOnLauncherTransitionStart(toView, animated, true);
3002 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003003 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003004 }
3005
Michael Jurkae326f182011-11-21 14:05:46 -08003006 @Override
3007 public void onTrimMemory(int level) {
3008 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003009 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003010 mAppsCustomizeTabHost.onTrimMemory();
3011 }
3012 }
3013
Winson Chung18f41f82012-05-09 13:28:10 -07003014 @Override
3015 public void onWindowFocusChanged(boolean hasFocus) {
3016 if (!hasFocus) {
3017 // When another window occludes launcher (like the notification shade, or recents),
3018 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3019 updateWallpaperVisibility(true);
3020 } else {
3021 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003022 mWorkspace.postDelayed(new Runnable() {
3023 @Override
3024 public void run() {
3025 disableWallpaperIfInAllApps();
3026 }
3027 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003028 }
3029 }
3030
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003031 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003032 showWorkspace(animated, null);
3033 }
3034
3035 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003036 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003037 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003038 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003039 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003040
Winson Chungc7d2b602012-05-16 17:02:20 -07003041 // Show the search bar (only animate if we were showing the drop target bar in spring
3042 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003043 if (mSearchDropTargetBar != null) {
3044 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3045 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003046
Michael Jurkab3e22d92011-10-31 15:58:33 -07003047 // Set focus to the AppsCustomize button
3048 if (mAllAppsButton != null) {
3049 mAllAppsButton.requestFocus();
3050 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003051 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003052
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003053 // Change the state *after* we've called all the transition code
3054 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003055
Winson Chung5fb63472011-02-02 17:03:37 -08003056 // Resume the auto-advance of widgets
3057 mUserPresent = true;
3058 updateRunning();
3059
alanv1d4fde62012-10-17 13:15:47 -07003060 // Send an accessibility event to announce the context change
3061 getWindow().getDecorView()
3062 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003063
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003064 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003065 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003066 }
3067
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003068 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003069 }
3070
Winson Chungc58497e2013-09-03 17:48:37 -07003071 void showAllApps(boolean animated,
3072 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003073 if (mState != State.WORKSPACE) return;
3074
Winson Chungc58497e2013-09-03 17:48:37 -07003075 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003076 mAppsCustomizeTabHost.requestFocus();
3077
Michael Jurkab3e22d92011-10-31 15:58:33 -07003078 // Change the state *after* we've called all the transition code
3079 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003080 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003081
3082 // Pause the auto-advance of widgets until we are out of AllApps
3083 mUserPresent = false;
3084 updateRunning();
3085 closeFolder();
3086
3087 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003088 getWindow().getDecorView()
3089 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003090 }
3091
Adam Cohen7777d962011-08-18 18:58:38 -07003092 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003093 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003094 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003095 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003096 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003097 }
Adam Cohen7777d962011-08-18 18:58:38 -07003098
Adam Cohened66b2b2012-01-23 17:28:51 -08003099 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3100 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003101 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3102
Winson Chunge7a03942011-08-05 15:05:12 -07003103 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003104 @Override
3105 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003106 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003107 // Before we show workspace, hide all apps again because
3108 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3109 // clean up our state transition functions
3110 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003111 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003112 } else {
3113 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003114 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003115 }
3116 }, (extendedDelay ?
3117 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3118 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3119 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003120
Michael Jurkad3ef3062010-11-23 16:23:58 -08003121 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003122 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003123 final boolean animated = true;
3124 final boolean springLoaded = true;
3125 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003126 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003127 }
3128 // Otherwise, we are not in spring loaded mode, so don't do anything.
3129 }
3130
Michael Jurkab3e22d92011-10-31 15:58:33 -07003131 void lockAllApps() {
3132 // TODO
3133 }
3134
3135 void unlockAllApps() {
3136 // TODO
3137 }
3138
Winson Chungf0ea4d32011-06-06 14:27:16 -07003139 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003140 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003141 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003142 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003143 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003144 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003145 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003146 int duration = 0;
3147 if (mSearchDropTargetBar != null) {
3148 duration = mSearchDropTargetBar.getTransitionInDuration();
3149 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003150 mHotseat.animate().alpha(1f).setDuration(duration);
3151 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003152 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003153 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003154 }
3155 }
3156 }
3157
3158 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003159 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003160 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003161 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003162 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003163 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003164 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003165 int duration = 0;
3166 if (mSearchDropTargetBar != null) {
3167 duration = mSearchDropTargetBar.getTransitionOutDuration();
3168 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003169 mHotseat.animate().alpha(0f).setDuration(duration);
3170 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003171 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003172 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003173 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003174 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003175 }
3176
Patrick Dubroy5f445422011-02-18 14:35:21 -08003177 /**
3178 * Add an item from all apps or customize onto the given workspace screen.
3179 * If layout is null, add to the current screen.
3180 */
3181 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003182 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003183 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003184 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003185 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003186
Winson Chungdff8ebb2011-09-08 17:25:31 -07003187 /** Maps the current orientation to an index for referencing orientation correct global icons */
3188 private int getCurrentOrientationIndexForGlobalIcons() {
3189 // default - 0, landscape - 1
3190 switch (getResources().getConfiguration().orientation) {
3191 case Configuration.ORIENTATION_LANDSCAPE:
3192 return 1;
3193 default:
3194 return 0;
3195 }
3196 }
3197
Michael Jurkaae65ee32012-04-30 11:45:54 -07003198 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003199 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003200 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003201 // Look for the toolbar icon specified in the activity meta-data
3202 Bundle metaData = packageManager.getActivityInfo(
3203 activityName, PackageManager.GET_META_DATA).metaData;
3204 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003205 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003206 if (iconResId != 0) {
3207 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003208 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003209 }
3210 }
3211 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003212 // This can happen if the activity defines an invalid drawable
3213 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3214 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003215 } catch (Resources.NotFoundException nfe) {
3216 // This can happen if the activity defines an invalid drawable
3217 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3218 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003219 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003220 return null;
3221 }
3222
3223 // if successful in getting icon, return it; otherwise, set button to use default drawable
3224 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003225 int buttonId, ComponentName activityName, int fallbackDrawableId,
3226 String toolbarResourceName) {
3227 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003228 Resources r = getResources();
3229 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3230 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003231
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003232 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003233 // If we were unable to find the icon via the meta-data, use a generic one
3234 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003235 toolbarIcon = r.getDrawable(fallbackDrawableId);
3236 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003237 if (button != null) {
3238 button.setCompoundDrawables(toolbarIcon, null, null, null);
3239 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003240 return null;
3241 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003242 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003243 if (button != null) {
3244 button.setCompoundDrawables(toolbarIcon, null, null, null);
3245 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003246 return toolbarIcon.getConstantState();
3247 }
3248 }
3249
3250 // if successful in getting icon, return it; otherwise, set button to use default drawable
3251 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003252 int buttonId, ComponentName activityName, int fallbackDrawableId,
3253 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003254 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003255 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003256
Michael Jurka19e0fc52011-07-22 18:00:21 -07003257 if (button != null) {
3258 // If we were unable to find the icon via the meta-data, use a
3259 // generic one
3260 if (toolbarIcon == null) {
3261 button.setImageResource(fallbackDrawableId);
3262 } else {
3263 button.setImageDrawable(toolbarIcon);
3264 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003265 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003266
3267 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3268
Michael Jurka0423dcf2010-10-05 14:56:18 -07003269 }
3270
Winson Chung1b884092012-06-08 17:13:02 -07003271 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003272 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003273 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003274 }
3275
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003276 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003277 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003278 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003279 }
3280
Winson Chungbb185bd2011-11-21 12:31:42 -08003281 private void invalidatePressedFocusedStates(View container, View button) {
3282 if (container instanceof HolographicLinearLayout) {
3283 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3284 layout.invalidatePressedFocusedStates();
3285 } else if (button instanceof HolographicImageView) {
3286 HolographicImageView view = (HolographicImageView) button;
3287 view.invalidatePressedFocusedStates();
3288 }
3289 }
3290
Cristina Stancu476493b2013-08-07 17:20:14 +01003291 public View getQsbBar() {
3292 if (mQsbBar == null) {
3293 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3294 }
3295 return mQsbBar;
3296 }
3297
3298 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003299 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003300 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003301 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003302 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003303
Winson Chung1cad91e2011-05-25 17:41:01 -07003304 final SearchManager searchManager =
3305 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3306 ComponentName activityName = searchManager.getGlobalSearchActivity();
3307 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003308 int coi = getCurrentOrientationIndexForGlobalIcons();
3309 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003310 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3311 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3312 if (sGlobalSearchIcon[coi] == null) {
3313 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3314 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3315 TOOLBAR_ICON_METADATA_NAME);
3316 }
3317
Winson Chungc51db6a2011-10-05 11:44:49 -07003318 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3319 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003320 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003321 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003322 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003323 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003324 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3325 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003326 if (searchButton != null) searchButton.setVisibility(View.GONE);
3327 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003328 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003329 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003330 }
3331 }
3332
Cristina Stancu476493b2013-08-07 17:20:14 +01003333 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003334 final View searchButtonContainer = findViewById(R.id.search_button_container);
3335 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003336 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003337 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003338 }
3339
Cristina Stancu476493b2013-08-07 17:20:14 +01003340 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003341 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003342 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003343
Winson Chungc51db6a2011-10-05 11:44:49 -07003344 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003345 final SearchManager searchManager =
3346 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3347 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3348
3349 ComponentName activityName = null;
3350 if (globalSearchActivity != null) {
3351 // Check if the global search activity handles voice search
3352 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3353 intent.setPackage(globalSearchActivity.getPackageName());
3354 activityName = intent.resolveActivity(getPackageManager());
3355 }
3356
3357 if (activityName == null) {
3358 // Fallback: check if an activity other than the global search activity
3359 // resolves this
3360 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3361 activityName = intent.resolveActivity(getPackageManager());
3362 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003363 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003364 int coi = getCurrentOrientationIndexForGlobalIcons();
3365 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003366 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3367 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3368 if (sVoiceSearchIcon[coi] == null) {
3369 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3370 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3371 TOOLBAR_ICON_METADATA_NAME);
3372 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003373 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003374 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003375 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003376 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003377 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003378 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003379 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003380 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003381 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003382 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003383 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003384 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003385
Cristina Stancu476493b2013-08-07 17:20:14 +01003386 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003387 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3388 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003389 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003390 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003391 }
3392
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003393 public void setVoiceButtonProxyVisible(boolean visible) {
3394 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3395 if (voiceButtonProxy != null) {
3396 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3397 }
3398 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003399 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003400 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003401 */
3402 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003403 final View marketButton = findViewById(R.id.market_button);
3404 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3405 // Find the app market activity by resolving an intent.
3406 // (If multiple app markets are installed, it will return the ResolverActivity.)
3407 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003408 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003409 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003410 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003411 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003412 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3413 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003414 marketButton.setVisibility(View.VISIBLE);
3415 } else {
3416 // We should hide and disable the view so that we don't try and restore the visibility
3417 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3418 marketButton.setVisibility(View.GONE);
3419 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003420 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003421 }
3422
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003423 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003424 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3425 Resources r = getResources();
3426 Drawable marketIconDrawable = d.newDrawable(r);
3427 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3428 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3429 marketIconDrawable.setBounds(0, 0, w, h);
3430
3431 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003432 }
3433
Michael Jurkad7c28052012-04-27 15:43:36 -07003434 @Override
3435 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003436 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003437 final List<CharSequence> text = event.getText();
3438 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003439 // Populate event with a fake title based on the current state.
3440 if (mState == State.APPS_CUSTOMIZE) {
3441 text.add(getString(R.string.all_apps_button_label));
3442 } else {
3443 text.add(getString(R.string.all_apps_home_button_label));
3444 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003445 return result;
3446 }
3447
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003448 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003449 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003450 */
3451 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3452 @Override
3453 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003454 closeSystemDialogs();
3455 }
3456 }
3457
3458 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003459 * Receives notifications whenever the appwidgets are reset.
3460 */
3461 private class AppWidgetResetObserver extends ContentObserver {
3462 public AppWidgetResetObserver() {
3463 super(new Handler());
3464 }
3465
3466 @Override
3467 public void onChange(boolean selfChange) {
3468 onAppWidgetReset();
3469 }
3470 }
3471
3472 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003473 * If the activity is currently paused, signal that we need to run the passed Runnable
3474 * in onResume.
3475 *
3476 * This needs to be called from incoming places where resources might have been loaded
3477 * while we are paused. That is becaues the Configuration might be wrong
3478 * when we're not running, and if it comes back to what it was when we
3479 * were paused, we are not restarted.
3480 *
3481 * Implementation of the method from LauncherModel.Callbacks.
3482 *
3483 * @return true if we are currently paused. The caller might be able to
3484 * skip some work in that case since we will come back again.
3485 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003486 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003487 if (mPaused) {
3488 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003489 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003490 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003491 }
3492 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003493 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003494 return true;
3495 } else {
3496 return false;
3497 }
3498 }
3499
Michael Jurkac402cd92013-05-20 15:49:32 +02003500 private boolean waitUntilResume(Runnable run) {
3501 return waitUntilResume(run, false);
3502 }
3503
Michael Jurka1e2f4652013-07-08 18:03:46 -07003504 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003505 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003506 }
3507
Michael Jurka7607c2f2013-04-03 14:33:19 -07003508 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003509 * If the activity is currently paused, signal that we need to re-run the loader
3510 * in onResume.
3511 *
3512 * This needs to be called from incoming places where resources might have been loaded
3513 * while we are paused. That is becaues the Configuration might be wrong
3514 * when we're not running, and if it comes back to what it was when we
3515 * were paused, we are not restarted.
3516 *
3517 * Implementation of the method from LauncherModel.Callbacks.
3518 *
3519 * @return true if we are currently paused. The caller might be able to
3520 * skip some work in that case since we will come back again.
3521 */
3522 public boolean setLoadOnResume() {
3523 if (mPaused) {
3524 Log.i(TAG, "setLoadOnResume");
3525 mOnResumeNeedsLoad = true;
3526 return true;
3527 } else {
3528 return false;
3529 }
3530 }
3531
3532 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003533 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003534 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003535 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003536 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003537 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003538 } else {
3539 return SCREEN_COUNT / 2;
3540 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003541 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003542
Joe Onorato9c1289c2009-08-17 11:03:03 -04003543 /**
3544 * Refreshes the shortcuts shown on the workspace.
3545 *
3546 * Implementation of the method from LauncherModel.Callbacks.
3547 */
3548 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003549 // If we're starting binding all over again, clear any bind calls we'd postponed in
3550 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3551 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003552 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003553
Winson Chungd64d1762013-08-20 14:37:16 -07003554 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003555 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003556 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003557
Michael Jurka05bf6442011-11-30 20:28:53 -08003558 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003559 if (mHotseat != null) {
3560 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003561 }
3562 }
3563
Adam Cohendcd297f2013-06-18 13:13:40 -07003564 @Override
3565 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003566 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003567
Adam Cohen5084cba2013-09-03 12:01:16 -07003568 // If there are no screens, we need to have an empty screen
3569 if (orderedScreenIds.size() == 0) {
3570 mWorkspace.addExtraEmptyScreen();
3571 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003572
3573 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003574 // setCurrentPage() so ensure that all pages are added before calling this).
3575 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003576 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3577 mWorkspace.createCustomContentPage();
3578 }
Winson Chung64359a52013-07-08 17:17:08 -07003579 }
3580
3581 @Override
3582 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003583 int count = orderedScreenIds.size();
3584 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003585 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003586 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003587 }
3588
Adam Cohen39a06042013-07-19 14:30:12 -07003589 private boolean shouldShowWeightWatcher() {
3590 String spKey = LauncherAppState.getSharedPreferencesKey();
3591 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003592 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003593
3594 return show;
3595 }
3596
Adam Cohen4caf2982013-08-20 18:54:31 -07003597 private boolean emailSent() {
3598 String spKey = LauncherAppState.getSharedPreferencesKey();
3599 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3600 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3601 return show;
3602 }
3603
3604 private void setEmailSent(boolean sent) {
3605 String spKey = LauncherAppState.getSharedPreferencesKey();
3606 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3607
3608 SharedPreferences.Editor editor = sp.edit();
3609 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3610 editor.commit();
3611 }
3612
Adam Cohen39a06042013-07-19 14:30:12 -07003613 private void toggleShowWeightWatcher() {
3614 String spKey = LauncherAppState.getSharedPreferencesKey();
3615 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3616 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3617
3618 show = !show;
3619
3620 SharedPreferences.Editor editor = sp.edit();
3621 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3622 editor.commit();
3623
3624 if (mWeightWatcher != null) {
3625 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3626 }
3627 }
3628
Winson Chungd64d1762013-08-20 14:37:16 -07003629 public void bindAppsAdded(final ArrayList<Long> newScreens,
3630 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003631 final ArrayList<ItemInfo> addAnimated,
3632 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003633 Runnable r = new Runnable() {
3634 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003635 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003636 }
3637 };
3638 if (waitUntilResume(r)) {
3639 return;
3640 }
3641
Winson Chungd64d1762013-08-20 14:37:16 -07003642 // Add the new screens
3643 bindAddScreens(newScreens);
3644
3645 // We add the items without animation on non-visible pages, and with
3646 // animations on the new page (which we will try and snap to).
3647 if (!addNotAnimated.isEmpty()) {
3648 bindItems(addNotAnimated, 0,
3649 addNotAnimated.size(), false);
3650 }
3651 if (!addAnimated.isEmpty()) {
3652 bindItems(addAnimated, 0,
3653 addAnimated.size(), true);
3654 }
Winson Chungc58497e2013-09-03 17:48:37 -07003655
3656 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3657 addedApps != null && mAppsCustomizeContent != null) {
3658 mAppsCustomizeContent.addApps(addedApps);
3659 }
Winson Chungd64d1762013-08-20 14:37:16 -07003660 }
3661
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003662 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003663 * Bind the items start-end from the list.
3664 *
3665 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003666 */
Winson Chung64359a52013-07-08 17:17:08 -07003667 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3668 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003669 Runnable r = new Runnable() {
3670 public void run() {
3671 bindItems(shortcuts, start, end, forceAnimateIcons);
3672 }
3673 };
3674 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003675 return;
3676 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003677
Winson Chungf0c6ae02012-03-21 16:10:31 -07003678 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003679 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3680 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003681 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003682 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003683 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003684 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003685 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003686
3687 // Short circuit if we are loading dock items for a configuration which has no dock
3688 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3689 mHotseat == null) {
3690 continue;
3691 }
3692
Joe Onorato9c1289c2009-08-17 11:03:03 -04003693 switch (item.itemType) {
3694 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3695 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003696 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003697 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003698
Winson Chung64359a52013-07-08 17:17:08 -07003699 /*
3700 * TODO: FIX collision case
3701 */
Winson Chungce376632013-07-11 16:12:41 -07003702 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3703 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3704 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3705 throw new RuntimeException("OCCUPIED");
3706 }
Winson Chung64359a52013-07-08 17:17:08 -07003707 }
3708
Adam Cohendcd297f2013-06-18 13:13:40 -07003709 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3710 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003711 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003712 // Animate all the applications up now
3713 shortcut.setAlpha(0f);
3714 shortcut.setScaleX(0f);
3715 shortcut.setScaleY(0f);
3716 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003717 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003718 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003719 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003720 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003721 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003722 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003723 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003724 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3725 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003726 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003727 default:
3728 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003729 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003730 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003731
Winson Chung997a9232013-07-24 15:33:46 -07003732 if (animateIcons) {
3733 // Animate to the correct page
3734 if (newShortcutsScreenId > -1) {
3735 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3736 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3737 if (newShortcutsScreenId != currentScreenId) {
3738 mWorkspace.snapToPage(newScreenIndex);
3739 }
3740 }
3741
Winson Chung64359a52013-07-08 17:17:08 -07003742 // We post the animation slightly delayed to prevent slowdowns when we are loading
3743 // right after we return to launcher.
3744 mWorkspace.postDelayed(new Runnable() {
3745 public void run() {
3746 anim.playTogether(bounceAnims);
3747 anim.start();
3748 }
3749 }, NEW_APPS_ANIMATION_DELAY);
3750 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003751 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003752 }
3753
Joe Onorato9c1289c2009-08-17 11:03:03 -04003754 /**
3755 * Implementation of the method from LauncherModel.Callbacks.
3756 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003757 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003758 Runnable r = new Runnable() {
3759 public void run() {
3760 bindFolders(folders);
3761 }
3762 };
3763 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003764 return;
3765 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003766 sFolders.clear();
3767 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003768 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003769
3770 /**
3771 * Add the views for a widget to the workspace.
3772 *
3773 * Implementation of the method from LauncherModel.Callbacks.
3774 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003775 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003776 Runnable r = new Runnable() {
3777 public void run() {
3778 bindAppWidget(item);
3779 }
3780 };
3781 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003782 return;
3783 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003784
Daniel Sandler843e8602010-06-07 14:59:01 -04003785 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3786 if (DEBUG_WIDGETS) {
3787 Log.d(TAG, "bindAppWidget: " + item);
3788 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003789 final Workspace workspace = mWorkspace;
3790
3791 final int appWidgetId = item.appWidgetId;
3792 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003793 if (DEBUG_WIDGETS) {
3794 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3795 }
3796
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3798
Joe Onorato9c1289c2009-08-17 11:03:03 -04003799 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003800 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003801
Adam Cohendcd297f2013-06-18 13:13:40 -07003802 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003803 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003804 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3805
Joe Onorato9c1289c2009-08-17 11:03:03 -04003806 workspace.requestLayout();
3807
Daniel Sandler843e8602010-06-07 14:59:01 -04003808 if (DEBUG_WIDGETS) {
3809 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3810 + (SystemClock.uptimeMillis()-start) + "ms");
3811 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003812 }
3813
Adam Cohen1462de32012-07-24 22:34:36 -07003814 public void onPageBoundSynchronously(int page) {
3815 mSynchronouslyBoundPages.add(page);
3816 }
3817
Joe Onorato9c1289c2009-08-17 11:03:03 -04003818 /**
3819 * Callback saying that there aren't any more items to bind.
3820 *
3821 * Implementation of the method from LauncherModel.Callbacks.
3822 */
Adam Cohene25af792013-06-06 23:08:25 -07003823 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003824 Runnable r = new Runnable() {
3825 public void run() {
3826 finishBindingItems(upgradePath);
3827 }
3828 };
3829 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003830 return;
3831 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003832 if (mSavedState != null) {
3833 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003834 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003835 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003836 mSavedState = null;
3837 }
3838
Adam Cohen1462de32012-07-24 22:34:36 -07003839 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003840
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003841 // If we received the result of any pending adds while the loader was running (e.g. the
3842 // widget configuration forced an orientation change), process them now.
3843 for (int i = 0; i < sPendingAddList.size(); i++) {
3844 completeAdd(sPendingAddList.get(i));
3845 }
3846 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003847
Winson Chungc51db6a2011-10-05 11:44:49 -07003848 // Update the market app icon as necessary (the other icons will be managed in response to
3849 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003850 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003851
Winson Chungf0c6ae02012-03-21 16:10:31 -07003852 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003853 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003854 mWorkspace.getUniqueComponents(true, null);
3855 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003856 }
Adam Cohen99894d92013-06-14 11:22:59 -07003857
Adam Cohen66a01fd2013-06-11 12:48:00 -07003858 mWorkspace.post(new Runnable() {
3859 @Override
3860 public void run() {
3861 onFinishBindingItems();
3862 }
3863 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003864 }
3865
Winson Chunga2413752012-04-03 14:22:34 -07003866 private boolean canRunNewAppsAnimation() {
3867 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3868 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3869 }
3870
Winson Chungc9168342013-06-26 14:54:55 -07003871 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3872 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3873 PropertyValuesHolder.ofFloat("alpha", 1f),
3874 PropertyValuesHolder.ofFloat("scaleX", 1f),
3875 PropertyValuesHolder.ofFloat("scaleY", 1f));
3876 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3877 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3878 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3879 return bounceAnim;
3880 }
3881
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003882 @Override
3883 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003884 boolean searchVisible = updateGlobalSearchIcon();
3885 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003886 if (mSearchDropTargetBar != null) {
3887 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3888 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003889 }
3890
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003891 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003892 * Add the icons for all apps.
3893 *
3894 * Implementation of the method from LauncherModel.Callbacks.
3895 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003896 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003897 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3898 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3899 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3900 getHotseat().addAllAppsFolder(mIconCache, apps,
3901 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3902 }
3903 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003904 }
Winson Chungc58497e2013-09-03 17:48:37 -07003905 } else {
3906 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3907 mAppsCustomizeContent != null) {
3908 mAppsCustomizeContent.setApps(apps);
3909 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003910 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003911 }
3912
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003913 @Override
3914 public boolean shouldShowApp(ResolveInfo app) {
3915 return true;
3916 }
3917
Joe Onorato9c1289c2009-08-17 11:03:03 -04003918 /**
3919 * A package was updated.
3920 *
3921 * Implementation of the method from LauncherModel.Callbacks.
3922 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003923 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003924 Runnable r = new Runnable() {
3925 public void run() {
3926 bindAppsUpdated(apps);
3927 }
3928 };
3929 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003930 return;
3931 }
3932
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003933 if (mWorkspace != null) {
3934 mWorkspace.updateShortcuts(apps);
3935 }
Winson Chungc58497e2013-09-03 17:48:37 -07003936
3937 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3938 mAppsCustomizeContent != null) {
3939 mAppsCustomizeContent.updateApps(apps);
3940 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003941 }
3942
3943 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003944 * A package was uninstalled. We take both the super set of packageNames
3945 * in addition to specific applications to remove, the reason being that
3946 * this can be called when a package is updated as well. In that scenario,
3947 * we only remove specific components from the workspace, where as
3948 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949 *
3950 * Implementation of the method from LauncherModel.Callbacks.
3951 */
Winson Chung83892cc2013-05-01 16:53:33 -07003952 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003953 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003954 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003955 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003956 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003957 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003958 }
Winson Chungd64d1762013-08-20 14:37:16 -07003959 };
3960 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003961 return;
3962 }
3963
Winson Chung64359a52013-07-08 17:17:08 -07003964 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003965 mWorkspace.removeItemsByPackageName(packageNames);
3966 } else {
3967 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003968 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003969
Winson Chunga1820962011-10-03 16:31:06 -07003970 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003971 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003972
3973 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3974 mAppsCustomizeContent != null) {
3975 mAppsCustomizeContent.removeApps(appInfos);
3976 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003977 }
Joe Onoratobe386092009-11-17 17:32:16 -08003978
3979 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003980 * A number of packages were updated.
3981 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003982 private ArrayList<Object> mWidgetsAndShortcuts;
3983 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003984 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003985 bindPackagesUpdated(mWidgetsAndShortcuts);
3986 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003987 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003988 };
3989
3990 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3991 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3992 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003993 return;
3994 }
3995
Winson Chung64359a52013-07-08 17:17:08 -07003996 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003997 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3998 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003999 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004000 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004001 }
4002
Winson Chung400438b2011-01-16 17:53:48 -08004003 private int mapConfigurationOriActivityInfoOri(int configOri) {
4004 final Display d = getWindowManager().getDefaultDisplay();
4005 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4006 switch (d.getRotation()) {
4007 case Surface.ROTATION_0:
4008 case Surface.ROTATION_180:
4009 // We are currently in the same basic orientation as the natural orientation
4010 naturalOri = configOri;
4011 break;
4012 case Surface.ROTATION_90:
4013 case Surface.ROTATION_270:
4014 // We are currently in the other basic orientation to the natural orientation
4015 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4016 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4017 break;
4018 }
4019
4020 int[] oriMap = {
4021 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4022 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4023 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4024 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4025 };
4026 // Since the map starts at portrait, we need to offset if this device's natural orientation
4027 // is landscape.
4028 int indexOffset = 0;
4029 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4030 indexOffset = 1;
4031 }
4032 return oriMap[(d.getRotation() + indexOffset) % 4];
4033 }
Adam Cohen446e9402011-09-15 18:21:21 -07004034
Winson Chung4b919f82012-05-01 10:44:08 -07004035 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004036 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004037 getResources().getBoolean(R.bool.allow_rotation);
4038 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004039 }
Winson Chung4b919f82012-05-01 10:44:08 -07004040 public void lockScreenOrientation() {
4041 if (isRotationEnabled()) {
4042 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4043 .getConfiguration().orientation));
4044 }
4045 }
4046 public void unlockScreenOrientation(boolean immediate) {
4047 if (isRotationEnabled()) {
4048 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004049 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004050 } else {
4051 mHandler.postDelayed(new Runnable() {
4052 public void run() {
4053 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4054 }
4055 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004056 }
Winson Chung4b919f82012-05-01 10:44:08 -07004057 }
Winson Chung400438b2011-01-16 17:53:48 -08004058 }
4059
Winson Chung82f55532011-08-09 14:14:23 -07004060 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004061 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004062 if (DISABLE_CLINGS) {
4063 return false;
4064 }
4065
Brett Chabot2a9e2282011-08-23 15:03:13 -07004066 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004067 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004068
Michael Jurkae233a8b2013-03-19 13:49:20 +01004069 // Restricted secondary users (child mode) will potentially have very few apps
4070 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004071// boolean supportsLimitedUsers =
4072// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4073// Account[] accounts = AccountManager.get(this).getAccounts();
4074// if (supportsLimitedUsers && accounts.length == 0) {
4075// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4076// Bundle restrictions = um.getUserRestrictions();
4077// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4078// return false;
4079// }
4080// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004081 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004082 }
Michael Jurka22143132012-10-04 17:42:38 +02004083
Winson Chungaf40f202013-09-18 18:26:31 -07004084 private Cling initCling(int clingId, int[] positionData, boolean animate,
4085 boolean dimNavBarVisibilty) {
Michael Jurka22143132012-10-04 17:42:38 +02004086 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004087 if (cling != null) {
4088 cling.init(this, positionData);
Winson Chungaf40f202013-09-18 18:26:31 -07004089 cling.show(animate, SHOW_CLING_DURATION);
4090
4091 if (dimNavBarVisibilty) {
4092 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4093 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004094 }
4095 }
4096 return cling;
4097 }
Michael Jurka22143132012-10-04 17:42:38 +02004098
Winson Chungaf40f202013-09-18 18:26:31 -07004099 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4100 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004101 // To catch cases where siblings of top-level views are made invisible, just check whether
4102 // the cling is directly set to GONE before dismissing it.
4103 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004104 final Runnable cleanUpClingCb = new Runnable() {
4105 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004106 cling.cleanup();
Winson Chungaf40f202013-09-18 18:26:31 -07004107 /*
Winson Chung46353de2012-02-16 14:05:10 -08004108 // We should update the shared preferences on a background thread
4109 new Thread("dismissClingThread") {
4110 public void run() {
4111 SharedPreferences.Editor editor = mSharedPrefs.edit();
4112 editor.putBoolean(flag, true);
4113 editor.commit();
4114 }
4115 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004116 */
4117 if (postAnimationCb != null) {
4118 postAnimationCb.run();
4119 }
4120 }
4121 };
4122 if (duration <= 0) {
4123 cleanUpClingCb.run();
4124 } else {
4125 cling.hide(duration, cleanUpClingCb);
4126 }
Michael Jurka22143132012-10-04 17:42:38 +02004127 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004128
4129 if (restoreNavBarVisibilty) {
4130 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4131 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4132 }
Winson Chung82f55532011-08-09 14:14:23 -07004133 }
4134 }
Michael Jurka22143132012-10-04 17:42:38 +02004135
Winson Chung9d9d74f2011-09-19 11:49:12 -07004136 private void removeCling(int id) {
4137 final View cling = findViewById(id);
4138 if (cling != null) {
4139 final ViewGroup parent = (ViewGroup) cling.getParent();
4140 parent.post(new Runnable() {
4141 @Override
4142 public void run() {
4143 parent.removeView(cling);
4144 }
4145 });
Michael Jurka22143132012-10-04 17:42:38 +02004146 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004147 }
4148 }
Michael Jurka974c3862012-05-22 22:00:31 -07004149
4150 private boolean skipCustomClingIfNoAccounts() {
4151 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4152 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4153 if (customCling) {
4154 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004155 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004156 Account[] accounts = am.getAccountsByType("com.google");
4157 return accounts.length == 0;
4158 }
4159 return false;
4160 }
4161
Winson Chungaf40f202013-09-18 18:26:31 -07004162 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004163 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004164 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004165 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004166 // If we're not using the default workspace layout, replace workspace cling
4167 // with a custom workspace cling (usually specified in an overlay)
4168 // For now, only do this on tablets
4169 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02004170 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02004171 // Use a custom cling
4172 View cling = findViewById(R.id.workspace_cling);
4173 ViewGroup clingParent = (ViewGroup) cling.getParent();
4174 int clingIndex = clingParent.indexOfChild(cling);
4175 clingParent.removeViewAt(clingIndex);
4176 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4177 clingParent.addView(customCling, clingIndex);
4178 customCling.setId(R.id.workspace_cling);
4179 }
Winson Chungaf40f202013-09-18 18:26:31 -07004180 initCling(R.id.first_run_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004181 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004182 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004183 }
4184 }
Winson Chungaf40f202013-09-18 18:26:31 -07004185
4186 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004187 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004188 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004189 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
4190 initCling(R.id.workspace_cling, null, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004191 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004192 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004193 }
4194 }
4195 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004196 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004197 if (isClingsEnabled() &&
4198 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungaf40f202013-09-18 18:26:31 -07004199 Cling cling = initCling(R.id.folder_cling, null, true, true);
4200 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004201 } else {
4202 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004203 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004204 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004205 }
Michael Jurka104c4562013-07-08 18:03:46 -07004206 protected SharedPreferences getSharedPrefs() {
4207 return mSharedPrefs;
4208 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004209 public boolean isFolderClingVisible() {
4210 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004211 if (cling != null) {
4212 return cling.getVisibility() == View.VISIBLE;
4213 }
4214 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004215 }
Winson Chungaf40f202013-09-18 18:26:31 -07004216 public void dismissFirstRunCling(View v) {
4217 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4218 Runnable cb = new Runnable() {
4219 public void run() {
4220 // Show the workspace cling next
4221 showFirstRunWorkspaceCling();
4222 }
4223 };
4224 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4225 DISMISS_CLING_DURATION, false);
4226 }
Winson Chung82f55532011-08-09 14:14:23 -07004227 public void dismissWorkspaceCling(View v) {
4228 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004229 Runnable cb = null;
4230 if (v == null) {
4231 cb = new Runnable() {
4232 public void run() {
4233 mWorkspace.enterOverviewMode();
4234 }
4235 };
4236 }
4237 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4238 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004239 }
4240 public void dismissFolderCling(View v) {
4241 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004242 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4243 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004244 }
4245
Winson Chung80baf5a2010-08-09 16:03:15 -07004246 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004247 * Prints out out state for debugging.
4248 */
4249 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004250 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004251 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004252 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4253 Log.d(TAG, "mRestoring=" + mRestoring);
4254 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4255 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004256 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004257 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004258
Winson Chung785d2eb2011-04-14 16:08:02 -07004259 if (mAppsCustomizeContent != null) {
4260 mAppsCustomizeContent.dumpState();
4261 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004262 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004263 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004264
4265 @Override
4266 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4267 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004268 synchronized (sDumpLogs) {
4269 writer.println(" ");
4270 writer.println("Debug logs: ");
4271 for (int i = 0; i < sDumpLogs.size(); i++) {
4272 writer.println(" " + sDumpLogs.get(i));
4273 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004274 }
4275 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004276
4277 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004278 if (DEBUG_DUMP_LOG) {
4279 synchronized (sDumpLogs) {
4280 Log.d(TAG, "");
4281 Log.d(TAG, "*********************");
4282 Log.d(TAG, "Launcher debug logs: ");
4283 for (int i = 0; i < sDumpLogs.size(); i++) {
4284 Log.d(TAG, " " + sDumpLogs.get(i));
4285 }
4286 Log.d(TAG, "*********************");
4287 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004288 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004289 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004290 }
4291
4292 public static void addDumpLog(String tag, String log, boolean debugLog) {
4293 if (debugLog) {
4294 Log.d(tag, log);
4295 }
Winson Chungede41292013-09-19 16:27:36 -07004296 if (DEBUG_DUMP_LOG) {
4297 sDateStamp.setTime(System.currentTimeMillis());
4298 synchronized (sDumpLogs) {
4299 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004300 }
Winson Chungede41292013-09-19 16:27:36 -07004301 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004302 }
4303
Winson Chungede41292013-09-19 16:27:36 -07004304 public void dumpLogsToLocalData() {
4305 if (DEBUG_DUMP_LOG) {
4306 new Thread("DumpLogsToLocalData") {
4307 @Override
4308 public void run() {
4309 boolean success = false;
4310 sDateStamp.setTime(sRunStart);
4311 String FILENAME = sDateStamp.getMonth() + "-"
4312 + sDateStamp.getDay() + "_"
4313 + sDateStamp.getHours() + "-"
4314 + sDateStamp.getMinutes() + "_"
4315 + sDateStamp.getSeconds() + ".txt";
4316
4317 FileOutputStream fos = null;
4318 File outFile = null;
4319 try {
4320 outFile = new File(getFilesDir(), FILENAME);
4321 outFile.createNewFile();
4322 fos = new FileOutputStream(outFile);
4323 } catch (Exception e) {
4324 e.printStackTrace();
4325 }
4326 if (fos != null) {
4327 PrintWriter writer = new PrintWriter(fos);
4328
4329 writer.println(" ");
4330 writer.println("Debug logs: ");
4331 synchronized (sDumpLogs) {
4332 for (int i = 0; i < sDumpLogs.size(); i++) {
4333 writer.println(" " + sDumpLogs.get(i));
4334 }
4335 }
4336 writer.close();
4337 }
4338 try {
4339 if (fos != null) {
4340 fos.close();
4341 success = true;
4342 }
4343 } catch (IOException e) {
4344 e.printStackTrace();
4345 }
4346 }
4347 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004348 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004349 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004350}
Michael Jurka2763be32011-02-24 11:19:57 -08004351
Michael Jurkaabded662011-03-04 12:06:57 -08004352interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004353 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004354 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004355 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004356 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004357 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004358}