blob: 9777ea94a299b58ef48da247c617157701d38f5c [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;
Romain Guy6fefcf12009-06-11 13:07:43 -0700133
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700135 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136 private static final int REQUEST_PICK_APPLICATION = 6;
137 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700138 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700139 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
Michael Jurka8b805b12012-04-18 14:23:14 -0700141 private static final int REQUEST_BIND_APPWIDGET = 11;
142
Mathew Inwood876a8462013-06-14 14:12:41 +0100143 /**
144 * IntentStarter uses request codes starting with this. This must be greater than all activity
145 * request codes used internally.
146 */
147 protected static final int REQUEST_LAST = 100;
148
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
150
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800151 static final int SCREEN_COUNT = 5;
152 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
Romain Guy98d01652009-06-30 16:21:04 -0700154 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800155 // To turn on these properties, type
156 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
157 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
158 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Winson Chung2672ff92012-05-04 16:22:30 -0700160 // The Intent extra that defines whether to ignore the launch animation
161 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400162 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 // Type: int
165 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700166 // Type: int
167 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700169 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
170 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
172 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700173 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700175 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: boolean
177 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
178 // Type: long
179 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700180 // Type: int
181 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
182 // Type: int
183 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
184 // Type: parcelable
185 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100187 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700188 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100189 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700190 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100191 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700192
Adam Cohen39a06042013-07-19 14:30:12 -0700193 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700194 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700195
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700196 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700197 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700198 private State mState = State.WORKSPACE;
199 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700200
Joe Onorato9c1289c2009-08-17 11:03:03 -0400201 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700202 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
203 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700204 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700205 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800208 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209
Winson Chunga2413752012-04-03 14:22:34 -0700210 // How long to wait before the new-shortcut animation automatically pans the workspace
211 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700212 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700213
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800214 private final BroadcastReceiver mCloseSystemDialogsReceiver
215 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800216 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private LayoutInflater mInflater;
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700221 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800222 private DragLayer mDragLayer;
223 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700224 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700225
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700226 private AppWidgetManager mAppWidgetManager;
227 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700228
Michael Jurkac9d95c52011-08-29 14:03:34 -0700229 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700230 private AppWidgetProviderInfo mPendingAddWidgetInfo;
231
Michael Jurka0280c3b2010-09-17 15:00:07 -0700232 private int[] mTmpAddItemCellCoordinates = new int[2];
233
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 private FolderInfo mFolderInfo;
235
Winson Chung3d503fb2011-07-13 17:25:49 -0700236 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700237 private View mOverviewPanel;
238
Michael Jurka838a4ca2011-02-07 13:33:06 -0800239 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700240
Winson Chungc51db6a2011-10-05 11:44:49 -0700241 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700242 private AppsCustomizeTabHost mAppsCustomizeTabHost;
243 private AppsCustomizePagedView mAppsCustomizeContent;
244 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100245 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700248 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
249 // scroll issues (because the workspace may not have been measured yet) and extra work.
250 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
251 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252
253 private SpannableStringBuilder mDefaultKeySsb = null;
254
Joe Onorato9c1289c2009-08-17 11:03:03 -0400255 private boolean mWorkspaceLoading = true;
256
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800257 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 private boolean mRestoring;
259 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700260 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800261
Michael Jurka1e2f4652013-07-08 18:03:46 -0700262 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700263 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
264
Winson Chung4a2afa32012-07-19 14:53:05 -0700265 // Keep track of whether the user has left launcher
266 private static boolean sPausedFromUserAction = false;
267
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 private Bundle mSavedInstanceState;
269
Joe Onorato9c1289c2009-08-17 11:03:03 -0400270 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800271 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800272 private boolean mUserPresent = true;
273 private boolean mVisible = false;
274 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700275 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400276
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700277 private static LocaleConfiguration sLocaleConfiguration = null;
278
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700279 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700280
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700281 private Intent mAppMarketIntent = null;
282
Adam Cohended9f8d2010-11-03 13:25:16 -0700283 // Related to the auto-advancing of widgets
284 private final int ADVANCE_MSG = 1;
285 private final int mAdvanceInterval = 20000;
286 private final int mAdvanceStagger = 250;
287 private long mAutoAdvanceSentTime;
288 private long mAutoAdvanceTimeLeft = -1;
289 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
290 new HashMap<View, AppWidgetProviderInfo>();
291
Winson Chung400438b2011-01-16 17:53:48 -0800292 // Determines how long to wait after a rotation before restoring the screen orientation to
293 // match the sensor state.
294 private final int mRestoreScreenOrientationDelay = 500;
295
Michael Jurka4ef207b2010-11-29 17:05:45 -0800296 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700297 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
298 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
299 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800300
Craig Mautner360310b2012-10-26 15:13:08 -0700301 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700302
Adam Cohen1462de32012-07-24 22:34:36 -0700303 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
304
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700305 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700306 static Date sDateStamp = new Date();
307 static DateFormat sDateFormat =
308 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
309 static long sRunStart = System.currentTimeMillis();
310 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700311
Winson Chung46353de2012-02-16 14:05:10 -0800312 // We only want to get the SharedPreferences once since it does an FS stat each time we get
313 // it from the context.
314 private SharedPreferences mSharedPrefs;
315
Adam Cohene25af792013-06-06 23:08:25 -0700316 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
317
Winson Chungf0c6ae02012-03-21 16:10:31 -0700318 // Holds the page that we need to animate to, and the icon views that we need to animate up
319 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700320 private ImageView mFolderIconImageView;
321 private Bitmap mFolderIconBitmap;
322 private Canvas mFolderIconCanvas;
323 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700324
Michael Jurkaddd62e92011-02-16 17:49:14 -0800325 private BubbleTextView mWaitingForResume;
326
Michael Jurka22143132012-10-04 17:42:38 +0200327 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
328 = new HideFromAccessibilityHelper();
329
Michael Jurkac1f5d262011-09-30 19:32:27 -0700330 private Runnable mBuildLayersRunnable = new Runnable() {
331 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700332 if (mWorkspace != null) {
333 mWorkspace.buildPageHardwareLayers();
334 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700335 }
336 };
337
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800338 private static ArrayList<PendingAddArguments> sPendingAddList
339 = new ArrayList<PendingAddArguments>();
340
Michael Jurka0a457bf2012-11-19 14:05:05 -0800341 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
342
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800343 private static class PendingAddArguments {
344 int requestCode;
345 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700346 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700347 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800348 int cellX;
349 int cellY;
350 }
351
Daniel Sandlerff02d492013-08-05 02:12:05 -0400352 private Stats mStats;
353
Michael Jurka0a457bf2012-11-19 14:05:05 -0800354 private static boolean isPropertyEnabled(String propertyName) {
355 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700356 }
357
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 @Override
359 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700360 if (DEBUG_STRICT_MODE) {
361 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
362 .detectDiskReads()
363 .detectDiskWrites()
364 .detectNetwork() // or .detectAll() for all detectable problems
365 .penaltyLog()
366 .build());
367 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
368 .detectLeakedSqlLiteObjects()
369 .detectLeakedClosableObjects()
370 .penaltyLog()
371 .penaltyDeath()
372 .build());
373 }
374
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400376
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400377 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400378 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700379
380 // Determine the dynamic grid properties
381 Point smallestSize = new Point();
382 Point largestSize = new Point();
383 Point realSize = new Point();
384 Display display = getWindowManager().getDefaultDisplay();
385 display.getCurrentSizeRange(smallestSize, largestSize);
386 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700387 DisplayMetrics dm = new DisplayMetrics();
388 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700389 // Lazy-initialize the dynamic grid
390 DeviceProfile grid = app.initDynamicGrid(this,
391 Math.min(smallestSize.x, smallestSize.y),
392 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700393 realSize.x, realSize.y,
394 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700395
396 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400397 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700398 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800399 mModel = app.setLauncher(this);
400 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400401 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800402 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700403
Daniel Sandlerff02d492013-08-05 02:12:05 -0400404 mStats = new Stats(this);
405
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700406 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700407 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
408 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700409
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700410 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
411 // this also ensures that any synchronous binding below doesn't re-trigger another
412 // LauncherModel load.
413 mPaused = false;
414
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800415 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200416 android.os.Debug.startMethodTracing(
417 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 }
419
420 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 setContentView(R.layout.launcher);
422 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100423 grid.layout(this);
Winson Chung7d7541e2011-09-16 20:14:36 -0700424 showFirstRunWorkspaceCling();
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);
466 }
467
Winson Chung4a2afa32012-07-19 14:53:05 -0700468 protected void onUserLeaveHint() {
469 super.onUserLeaveHint();
470 sPausedFromUserAction = true;
471 }
472
Winson Chung98ca0f72013-07-29 12:58:51 -0700473 /** To be overriden by subclasses to hint to Launcher that we have custom content */
474 protected boolean hasCustomContentToLeft() {
475 return false;
476 }
477
Dave Hawkeya8881582013-09-17 15:55:33 -0600478 /**
479 * To be overridden by subclasses to create the custom content and call
480 * {@link #addToCustomContentPage}. This will only be invoked if
481 * {@link #hasCustomContentToLeft()} is {@code true}.
482 */
483 protected void addCustomContentToLeft() {
484 }
485
486 /**
487 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
488 * ensure the custom content page is added or removed if necessary.
489 */
490 protected void invalidateHasCustomContentToLeft() {
491 if (mWorkspace.getScreenOrder().isEmpty()) {
492 // Not bound yet, wait for bindScreens to be called.
493 return;
494 }
495
496 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
497 // Create the custom content page and call the subclass to populate it.
498 mWorkspace.createCustomContentPage();
499 addCustomContentToLeft();
500 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
501 mWorkspace.removeCustomContentPage();
502 }
503 }
504
Adam Cohenf9426d52012-06-04 17:26:21 -0700505 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700506 boolean searchVisible = false;
507 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800508 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700509 int coi = getCurrentOrientationIndexForGlobalIcons();
510 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
511 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700512 updateAppMarketIcon();
513 searchVisible = updateGlobalSearchIcon();
514 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700515 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700516 if (sGlobalSearchIcon[coi] != null) {
517 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700518 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700519 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700520 if (sVoiceSearchIcon[coi] != null) {
521 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700523 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700524 if (sAppMarketIcon[coi] != null) {
525 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800526 }
Winson Chungadf0c182012-08-23 14:59:07 -0700527 if (mSearchDropTargetBar != null) {
528 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
529 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800530 }
Romain Guycbb89e42009-06-08 15:52:54 -0700531
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800532 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700533 if (sLocaleConfiguration == null) {
534 new AsyncTask<Void, Void, LocaleConfiguration>() {
535 @Override
536 protected LocaleConfiguration doInBackground(Void... unused) {
537 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
538 readConfiguration(Launcher.this, localeConfiguration);
539 return localeConfiguration;
540 }
541
542 @Override
543 protected void onPostExecute(LocaleConfiguration result) {
544 sLocaleConfiguration = result;
545 checkForLocaleChange(); // recursive, but now with a locale configuration
546 }
547 }.execute();
548 return;
549 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700550
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800551 final Configuration configuration = getResources().getConfiguration();
552
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700553 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800554 final String locale = configuration.locale.toString();
555
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700556 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800557 final int mcc = configuration.mcc;
558
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700559 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800560 final int mnc = configuration.mnc;
561
Romain Guy84f296c2009-11-04 15:00:44 -0800562 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563
Romain Guy84f296c2009-11-04 15:00:44 -0800564 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700565 sLocaleConfiguration.locale = locale;
566 sLocaleConfiguration.mcc = mcc;
567 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700568
Joe Onorato0589f0f2010-02-08 13:44:00 -0800569 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700570
571 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
572 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700573 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574 public void run() {
575 writeConfiguration(Launcher.this, localeConfiguration);
576 }
577 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700578 }
579 }
580
581 private static class LocaleConfiguration {
582 public String locale;
583 public int mcc = -1;
584 public int mnc = -1;
585 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700586
Romain Guy98d01652009-06-30 16:21:04 -0700587 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
588 DataInputStream in = null;
589 try {
590 in = new DataInputStream(context.openFileInput(PREFERENCES));
591 configuration.locale = in.readUTF();
592 configuration.mcc = in.readInt();
593 configuration.mnc = in.readInt();
594 } catch (FileNotFoundException e) {
595 // Ignore
596 } catch (IOException e) {
597 // Ignore
598 } finally {
599 if (in != null) {
600 try {
601 in.close();
602 } catch (IOException e) {
603 // Ignore
604 }
605 }
606 }
607 }
608
609 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
610 DataOutputStream out = null;
611 try {
612 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
613 out.writeUTF(configuration.locale);
614 out.writeInt(configuration.mcc);
615 out.writeInt(configuration.mnc);
616 out.flush();
617 } catch (FileNotFoundException e) {
618 // Ignore
619 } catch (IOException e) {
620 //noinspection ResultOfMethodCallIgnored
621 context.getFileStreamPath(PREFERENCES).delete();
622 } finally {
623 if (out != null) {
624 try {
625 out.close();
626 } catch (IOException e) {
627 // Ignore
628 }
629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 }
631 }
632
Bjorn Bringertc459e522013-06-07 19:36:01 +0100633 public LayoutInflater getInflater() {
634 return mInflater;
635 }
636
Adam Cohen716b51e2011-06-30 12:09:54 -0700637 public DragLayer getDragLayer() {
638 return mDragLayer;
639 }
640
Winson Chung36a62fe2012-05-06 18:04:42 -0700641 boolean isDraggingEnabled() {
642 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
643 // that is subsequently removed from the workspace in startBinding().
644 return !mModel.isLoadingWorkspace();
645 }
646
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800647 static int getScreen() {
648 synchronized (sLock) {
649 return sScreen;
650 }
651 }
652
653 static void setScreen(int screen) {
654 synchronized (sLock) {
655 sScreen = screen;
656 }
657 }
658
Winson Chung557d6ed2011-07-08 15:34:52 -0700659 /**
660 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
661 * a configuration step, this allows the proper animations to run after other transitions.
662 */
663 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700664 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800665 switch (args.requestCode) {
666 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700667 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700668 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800669 break;
670 case REQUEST_PICK_SHORTCUT:
671 processShortcut(args.intent);
672 break;
673 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700674 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700675 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700676 result = true;
677 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800678 case REQUEST_CREATE_APPWIDGET:
679 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700680 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700681 result = true;
682 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800683 }
Michael Jurka27614d22012-04-02 06:40:22 -0700684 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
685 // if you turned the screen off and then back while in All Apps, Launcher would not
686 // return to the workspace. Clearing mAddInfo.container here fixes this issue
687 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700688 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800689 }
690
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800691 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700692 protected void onActivityResult(
693 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700694 // Reset the startActivity waiting flag
695 mWaitingForResult = false;
696
Michael Jurka8b805b12012-04-18 14:23:14 -0700697 if (requestCode == REQUEST_BIND_APPWIDGET) {
698 int appWidgetId = data != null ?
699 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
700 if (resultCode == RESULT_CANCELED) {
701 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
702 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700703 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700704 }
705 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200706 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
707 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
708 mWorkspace.exitOverviewMode(false);
709 }
710 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700711 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200712
Winson Chung557d6ed2011-07-08 15:34:52 -0700713 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800714 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
715 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700716
Adam Cohened66b2b2012-01-23 17:28:51 -0800717 // We have special handling for widgets
718 if (isWidgetDrop) {
719 int appWidgetId = data != null ?
720 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700721 if (appWidgetId < 0) {
722 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
723 "widget configuration activity.");
724 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
725 } else {
726 completeTwoStageWidgetDrop(resultCode, appWidgetId);
727 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800728 return;
729 }
730
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800731 // The pattern used here is that a user PICKs a specific application,
732 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700733
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
735 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700736 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 final PendingAddArguments args = new PendingAddArguments();
738 args.requestCode = requestCode;
739 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700740 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700741 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700742 args.cellX = mPendingAddInfo.cellX;
743 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800744 if (isWorkspaceLocked()) {
745 sPendingAddList.add(args);
746 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700747 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800748 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800749 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800750 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700751 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800752 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
753 null);
754 }
755
756 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700757 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700758 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800759 Runnable onCompleteRunnable = null;
760 int animationType = 0;
761
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700762 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800763 if (resultCode == RESULT_OK) {
764 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
765 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700766 mPendingAddWidgetInfo);
767 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800768 onCompleteRunnable = new Runnable() {
769 @Override
770 public void run() {
771 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700772 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800773 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
774 null);
775 }
776 };
777 } else if (resultCode == RESULT_CANCELED) {
778 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
779 onCompleteRunnable = new Runnable() {
780 @Override
781 public void run() {
782 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
783 null);
784 }
785 };
786 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700787 if (mDragLayer.getAnimatedView() != null) {
788 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
789 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
790 animationType, boundWidget, true);
791 } else {
792 // The animated view may be null in the case of a rotation during widget configuration
793 onCompleteRunnable.run();
794 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800795 }
796
797 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700798 protected void onStop() {
799 super.onStop();
800 FirstFrameAnimatorHelper.setIsVisible(false);
801 }
802
803 @Override
804 protected void onStart() {
805 super.onStart();
806 FirstFrameAnimatorHelper.setIsVisible(true);
807 }
808
809 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800810 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200811 long startTime = 0;
812 if (DEBUG_RESUME_TIME) {
813 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400814 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200815 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700817
Winson Chung4a2afa32012-07-19 14:53:05 -0700818 // Restore the previous launcher state
819 if (mOnResumeState == State.WORKSPACE) {
820 showWorkspace(false);
821 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700822 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700823 }
824 mOnResumeState = State.NONE;
825
Craig Mautner360310b2012-10-26 15:13:08 -0700826 // Background was set to gradient in onPause(), restore to black if in all apps.
827 setWorkspaceBackground(mState == State.WORKSPACE);
828
Winson Chungde0fb8f2012-05-08 14:37:08 -0700829 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700830 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700831
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800832 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700833 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700834 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400835 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700836 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400837 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700838 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700840 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200841 // We might have postponed some bind calls until onResume (see waitUntilResume) --
842 // execute them here
843 long startTimeCallbacks = 0;
844 if (DEBUG_RESUME_TIME) {
845 startTimeCallbacks = System.currentTimeMillis();
846 }
847
848 if (mAppsCustomizeContent != null) {
849 mAppsCustomizeContent.setBulkBind(true);
850 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700851 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
852 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200853 }
854 if (mAppsCustomizeContent != null) {
855 mAppsCustomizeContent.setBulkBind(false);
856 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700857 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200858 if (DEBUG_RESUME_TIME) {
859 Log.d(TAG, "Time spent processing callbacks in onResume: " +
860 (System.currentTimeMillis() - startTimeCallbacks));
861 }
Michael Jurka447bf842013-05-15 14:52:15 +0200862 }
Michael Jurka54554252013-08-01 12:52:23 +0200863 if (mOnResumeCallbacks.size() > 0) {
864 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
865 mOnResumeCallbacks.get(i).run();
866 }
867 mOnResumeCallbacks.clear();
868 }
Winson Chunge4e50662012-01-23 14:45:13 -0800869
870 // Reset the pressed state of icons that were locked in the press state while activities
871 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800872 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800873 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800874 mWaitingForResume.setStayPressed(false);
875 }
Winson Chunge4e50662012-01-23 14:45:13 -0800876 if (mAppsCustomizeContent != null) {
877 // Resets the previous all apps icon press state
878 mAppsCustomizeContent.resetDrawableState();
879 }
Adam Cohen06dff352012-06-01 17:17:08 -0700880 // It is possible that widgets can receive updates while launcher is not in the foreground.
881 // Consequently, the widgets will be inflated in the orientation of the foreground activity
882 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
883 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700884 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700885
886 // Again, as with the above scenario, it's possible that one or more of the global icons
887 // were updated in the wrong orientation.
888 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200889 if (DEBUG_RESUME_TIME) {
890 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
891 }
Adam Cohen4caf2982013-08-20 18:54:31 -0700892
893 // Write all the logs to disk
894 Launcher.addDumpLog(TAG, "10249126 - onResume() - dumping logs to disk", true);
895 dumpLogsToLocalData(false);
Adam Cohen06dff352012-06-01 17:17:08 -0700896 }
897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700899 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700900 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
901 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
902 // when Launcher resumes and we are still in AllApps.
903 updateWallpaperVisibility(true);
904
Winson Chung997a9232013-07-24 15:33:46 -0700905 // Ensure that items added to Launcher are queued until Launcher returns
906 InstallShortcutReceiver.enableInstallQueue();
907
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700908 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700909 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800910 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700911 mDragController.resetLastGestureUpTime();
Adam Cohen4caf2982013-08-20 18:54:31 -0700912
913 // Write all the logs to disk
914 Launcher.addDumpLog(TAG, "10249126 - onPause() - dumping logs to disk", true);
915 dumpLogsToLocalData(false);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700916 }
Romain Guycbb89e42009-06-08 15:52:54 -0700917
Adam Cohen66a01fd2013-06-11 12:48:00 -0700918 protected void onFinishBindingItems() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600919 if (hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
920 addCustomContentToLeft();
921 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700922 }
923
Adam Cohenbffe7452013-07-22 18:21:45 -0700924 QSBScroller mQsbScroller = new QSBScroller() {
925 int scrollY = 0;
926
927 @Override
928 public void setScrollY(int scroll) {
929 scrollY = scroll;
930
931 if (mWorkspace.isOnOrMovingToCustomContent()) {
932 mSearchDropTargetBar.setTranslationY(- scrollY);
933 }
934 }
935 };
936
937 public void resetQSBScroll() {
938 mSearchDropTargetBar.animate().translationY(0).start();
939 }
940
941 public interface CustomContentCallbacks {
942 // Custom content is completely shown
943 public void onShow();
944
945 // Custom content is completely hidden
946 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700947
948 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
949 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700950 }
951
Adam Cohen30bacb22013-08-29 14:25:25 -0700952 protected void startSettings() {
953 }
954
Adam Cohenbffe7452013-07-22 18:21:45 -0700955 public interface QSBScroller {
956 public void setScrollY(int scrollY);
957 }
958
Adam Cohen66a01fd2013-06-11 12:48:00 -0700959 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700960 public QSBScroller addToCustomContentPage(View customContent) {
961 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700962 }
963
Winson Chung98ca0f72013-07-29 12:58:51 -0700964 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700965 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700966 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700967 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700968 }
969
Adam Cohenedb40762013-07-18 16:45:45 -0700970 // The custom content needs to offset its content to account for the QSB
971 public int getTopOffsetForCustomContent() {
972 return mWorkspace.getPaddingTop();
973 }
974
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700975 @Override
976 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400977 // Flag the loader to stop early before switching
978 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700979 if (mAppsCustomizeContent != null) {
980 mAppsCustomizeContent.surrender();
981 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800982 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700983 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700984
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800985 // We can't hide the IME if it was forced open. So don't bother
986 /*
987 @Override
988 public void onWindowFocusChanged(boolean hasFocus) {
989 super.onWindowFocusChanged(hasFocus);
990
991 if (hasFocus) {
992 final InputMethodManager inputManager = (InputMethodManager)
993 getSystemService(Context.INPUT_METHOD_SERVICE);
994 WindowManager.LayoutParams lp = getWindow().getAttributes();
995 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
996 android.os.Handler()) {
997 protected void onReceiveResult(int resultCode, Bundle resultData) {
998 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
999 }
1000 });
1001 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1002 }
1003 }
1004 */
1005
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001006 private boolean acceptFilter() {
1007 final InputMethodManager inputManager = (InputMethodManager)
1008 getSystemService(Context.INPUT_METHOD_SERVICE);
1009 return !inputManager.isFullscreenMode();
1010 }
1011
1012 @Override
1013 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001014 final int uniChar = event.getUnicodeChar();
1015 final boolean handled = super.onKeyDown(keyCode, event);
1016 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1017 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001018 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1019 keyCode, event);
1020 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001021 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001022 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001023 // showSearchDialog()
1024 // If there are multiple keystrokes before the search dialog takes focus,
1025 // onSearchRequested() will be called for every keystroke,
1026 // but it is idempotent, so it's fine.
1027 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 }
1029 }
1030
Joe Onorato8a9625e2010-01-28 15:55:35 -08001031 // Eat the long press event so the keyboard doesn't come up.
1032 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1033 return true;
1034 }
1035
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001036 return handled;
1037 }
1038
Karl Rosaen138a0412009-04-23 19:00:21 -07001039 private String getTypedText() {
1040 return mDefaultKeySsb.toString();
1041 }
1042
1043 private void clearTypedText() {
1044 mDefaultKeySsb.clear();
1045 mDefaultKeySsb.clearSpans();
1046 Selection.setSelection(mDefaultKeySsb, 0);
1047 }
1048
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001049 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001050 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1051 * State
1052 */
1053 private static State intToState(int stateOrdinal) {
1054 State state = State.WORKSPACE;
1055 final State[] stateValues = State.values();
1056 for (int i = 0; i < stateValues.length; i++) {
1057 if (stateValues[i].ordinal() == stateOrdinal) {
1058 state = stateValues[i];
1059 break;
1060 }
1061 }
1062 return state;
1063 }
1064
1065 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066 * Restores the previous state, if it exists.
1067 *
1068 * @param savedState The previous state.
1069 */
1070 private void restoreState(Bundle savedState) {
1071 if (savedState == null) {
1072 return;
1073 }
1074
Michael Jurka883f55b2010-10-21 15:47:14 -07001075 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001076 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001077 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001078 }
1079
Winson Chungf0c6ae02012-03-21 16:10:31 -07001080 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001082 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001083 }
1084
Winson Chung3d503fb2011-07-13 17:25:49 -07001085 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001086 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001087
Winson Chung3d503fb2011-07-13 17:25:49 -07001088 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1089 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001090 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001091 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1092 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001093 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1094 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1095 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001096 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 mRestoring = true;
1098 }
1099
1100 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1101 if (renameFolder) {
1102 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001103 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001104 mRestoring = true;
1105 }
Winson Chunga12a2502010-12-20 14:41:35 -08001106
Winson Chung785d2eb2011-04-14 16:08:02 -07001107 // Restore the AppsCustomize tab
1108 if (mAppsCustomizeTabHost != null) {
1109 String curTab = savedState.getString("apps_customize_currentTab");
1110 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001111 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001112 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001113 mAppsCustomizeContent.loadAssociatedPages(
1114 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001115 }
1116
Winson Chung5afbf7b2011-07-25 11:53:08 -07001117 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1118 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001119 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001120 }
1121
1122 /**
1123 * Finds all the views we need and configure them properly.
1124 */
1125 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001126 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001127
Craig Mautner360310b2012-10-26 15:13:08 -07001128 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001129 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1130 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001131
John Spurlock77e1f472013-09-11 10:09:51 -04001132 mLauncherView.setSystemUiVisibility(
1133 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001134 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001135
Winson Chung4c98d922011-05-31 16:50:48 -07001136 // Setup the drag layer
1137 mDragLayer.setup(this, dragController);
1138
Winson Chung3d503fb2011-07-13 17:25:49 -07001139 // Setup the hotseat
1140 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1141 if (mHotseat != null) {
1142 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001143 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001144 }
1145
Adam Cohenf358a4b2013-07-23 16:47:31 -07001146 mOverviewPanel = findViewById(R.id.overview_panel);
1147 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1148 @Override
1149 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001150 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001151 }
1152 });
1153 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1154 @Override
1155 public void onClick(View arg0) {
1156 startWallpaper();
1157 }
1158 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001159 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1160 @Override
1161 public void onClick(View arg0) {
1162 startSettings();
1163 }
1164 });
Adam Cohendbdff6b2013-09-18 19:09:15 -07001165 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001166
Winson Chung4c98d922011-05-31 16:50:48 -07001167 // Setup the workspace
1168 mWorkspace.setHapticFeedbackEnabled(false);
1169 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001170 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001171 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001172
Winson Chungf0ea4d32011-06-06 14:27:16 -07001173 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001174 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001175
Winson Chungf0ea4d32011-06-06 14:27:16 -07001176 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001177 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001178 mAppsCustomizeContent = (AppsCustomizePagedView)
1179 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1180 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001181
Winson Chung3d503fb2011-07-13 17:25:49 -07001182 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001183 dragController.setDragScoller(mWorkspace);
1184 dragController.setScrollView(mDragLayer);
1185 dragController.setMoveTarget(mWorkspace);
1186 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001187 if (mSearchDropTargetBar != null) {
1188 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001189 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001190
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001191 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001192 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001193 mWeightWatcher = new WeightWatcher(this);
1194 mWeightWatcher.setAlpha(0.5f);
1195 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001196 new FrameLayout.LayoutParams(
1197 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001198 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001199 Gravity.BOTTOM)
1200 );
Adam Cohen39a06042013-07-19 14:30:12 -07001201
1202 boolean show = shouldShowWeightWatcher();
1203 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001204 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 }
1206
1207 /**
1208 * Creates a view representing a shortcut.
1209 *
1210 * @param info The data structure describing the shortcut.
1211 *
1212 * @return A View inflated from R.layout.application.
1213 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001214 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001216 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 }
1218
1219 /**
1220 * Creates a view representing a shortcut inflated from the specified resource.
1221 *
1222 * @param layoutResId The id of the XML layout used to create the shortcut.
1223 * @param parent The group the shortcut belongs to.
1224 * @param info The data structure describing the shortcut.
1225 *
1226 * @return A View inflated from layoutResId.
1227 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001228 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001229 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1230 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 return favorite;
1233 }
1234
1235 /**
1236 * Add an application shortcut to the workspace.
1237 *
1238 * @param data The intent describing the application.
1239 * @param cellInfo The position on screen where to create the shortcut.
1240 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001241 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001242 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001243 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001244
Adam Cohenfbba09b2011-07-18 21:43:05 -07001245 // First we check if we already know the exact location where we want to add this item.
1246 if (cellX >= 0 && cellY >= 0) {
1247 cellXY[0] = cellX;
1248 cellXY[1] = cellY;
1249 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001250 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001251 return;
1252 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001254 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001255
Romain Guy73b979d2009-06-09 12:57:21 -07001256 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001257 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001259 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001260 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001261 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001262 } else {
1263 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 }
1265 }
Romain Guycbb89e42009-06-08 15:52:54 -07001266
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267 /**
1268 * Add a shortcut to the workspace.
1269 *
1270 * @param data The intent describing the shortcut.
1271 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001273 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001274 int cellY) {
1275 int[] cellXY = mTmpAddItemCellCoordinates;
1276 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001277 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001278
Michael Jurkad3ef3062010-11-23 16:23:58 -08001279 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001280
Adam Cohen558baaf2011-08-15 15:22:57 -07001281 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001282 if (info == null) {
1283 return;
1284 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001285 final View view = createShortcut(info);
1286
Adam Cohenfbba09b2011-07-18 21:43:05 -07001287 // First we check if we already know the exact location where we want to add this item.
1288 if (cellX >= 0 && cellY >= 0) {
1289 cellXY[0] = cellX;
1290 cellXY[1] = cellY;
1291 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001292
1293 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001294 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001295 true, null,null)) {
1296 return;
1297 }
1298 DragObject dragObject = new DragObject();
1299 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001300 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1301 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001302 return;
1303 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001304 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001305 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001306 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001307 foundCellSpan = (result != null);
1308 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001309 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001310 }
1311
1312 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001313 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001314 return;
1315 }
1316
Adam Cohendcd297f2013-06-18 13:13:40 -07001317 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318
1319 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001320 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001321 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 }
1323 }
1324
Adam Cohen2f093b62012-04-30 18:59:53 -07001325 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1326 int minHeight) {
1327 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001328 // We want to account for the extra amount of padding that we are adding to the widget
1329 // to ensure that it gets the full amount of space that it has requested
1330 int requiredWidth = minWidth + padding.left + padding.right;
1331 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001332 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001333 }
1334
Adam Cohen2f093b62012-04-30 18:59:53 -07001335 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1336 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001337 }
1338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1340 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001341 }
1342
Adam Cohen2f093b62012-04-30 18:59:53 -07001343 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1344 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001345 }
1346
Adam Cohen2f093b62012-04-30 18:59:53 -07001347 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1348 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001349 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001350 }
1351
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001352 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001353 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001355 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001356 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001357 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001358 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001359 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1360 if (appWidgetInfo == null) {
1361 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1362 }
Romain Guycbb89e42009-06-08 15:52:54 -07001363
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001364 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001365 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001366
Adam Cohen2f093b62012-04-30 18:59:53 -07001367 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1368 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001369
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001371 // We have saved the position to which the widget was dragged-- this really only matters
1372 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001373 int[] cellXY = mTmpAddItemCellCoordinates;
1374 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001375 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001376 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001377 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1378 cellXY[0] = mPendingAddInfo.cellX;
1379 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001380 spanXY[0] = mPendingAddInfo.spanX;
1381 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001382 foundCellSpan = true;
1383 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001384 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001385 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001386 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1387 spanXY[1], cellXY, finalSpan);
1388 spanXY[0] = finalSpan[0];
1389 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001390 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001391 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001392 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001393 }
1394
Michael Jurka0280c3b2010-09-17 15:00:07 -07001395 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001396 if (appWidgetId != -1) {
1397 // Deleting an app widget ID is a void call but writes to disk before returning
1398 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001399 new Thread("deleteAppWidgetId") {
1400 public void run() {
1401 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1402 }
1403 }.start();
1404 }
Winson Chung93eef082012-03-23 15:59:27 -07001405 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001406 return;
1407 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001409 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001410 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1411 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 launcherInfo.spanX = spanXY[0];
1413 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001414 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1415 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001416
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001418 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419
1420 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001421 if (hostView == null) {
1422 // Perform actual inflation because we're live
1423 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1424 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1425 } else {
1426 // The AppWidgetHostView has already been inflated and instantiated
1427 launcherInfo.hostView = hostView;
1428 }
Romain Guycbb89e42009-06-08 15:52:54 -07001429
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001431 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001432 launcherInfo.notifyWidgetSizeChanged(this);
1433
Adam Cohendcd297f2013-06-18 13:13:40 -07001434 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001435 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001436
1437 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001439 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 }
Romain Guycbb89e42009-06-08 15:52:54 -07001441
Adam Cohended9f8d2010-11-03 13:25:16 -07001442 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1443 @Override
1444 public void onReceive(Context context, Intent intent) {
1445 final String action = intent.getAction();
1446 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1447 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001448 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001449 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001450
Winson Chungc100e8e2011-08-09 16:02:43 -07001451 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001452 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001453 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1454 mAppsCustomizeTabHost.reset();
Adam Cohen040a5d22013-09-16 17:09:33 -07001455 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001456 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001457 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1458 mUserPresent = true;
1459 updateRunning();
1460 }
1461 }
1462 };
1463
1464 @Override
1465 public void onAttachedToWindow() {
1466 super.onAttachedToWindow();
1467
1468 // Listen for broadcasts related to user-presence
1469 final IntentFilter filter = new IntentFilter();
1470 filter.addAction(Intent.ACTION_SCREEN_OFF);
1471 filter.addAction(Intent.ACTION_USER_PRESENT);
1472 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001473 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001474 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001475 mVisible = true;
1476 }
1477
1478 @Override
1479 public void onDetachedFromWindow() {
1480 super.onDetachedFromWindow();
1481 mVisible = false;
1482
Adam Cohend113e0c2010-11-11 10:48:05 -08001483 if (mAttached) {
1484 unregisterReceiver(mReceiver);
1485 mAttached = false;
1486 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001487 updateRunning();
1488 }
1489
1490 public void onWindowVisibilityChanged(int visibility) {
1491 mVisible = visibility == View.VISIBLE;
1492 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001493 // The following code used to be in onResume, but it turns out onResume is called when
1494 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1495 // is a more appropriate event to handle
1496 if (mVisible) {
1497 mAppsCustomizeTabHost.onWindowVisible();
1498 if (!mWorkspaceLoading) {
1499 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001500 // We want to let Launcher draw itself at least once before we force it to build
1501 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001502 // apps is nice and speedy.
1503 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001504 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001505 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001506 if (mStarted) return;
1507 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001508 // We delay the layer building a bit in order to give
1509 // other message processing a time to run. In particular
1510 // this avoids a delay in hiding the IME if it was
1511 // currently shown, because doing that may involve
1512 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001513 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001514 final ViewTreeObserver.OnDrawListener listener = this;
1515 mWorkspace.post(new Runnable() {
1516 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001517 if (mWorkspace != null &&
1518 mWorkspace.getViewTreeObserver() != null) {
1519 mWorkspace.getViewTreeObserver().
1520 removeOnDrawListener(listener);
1521 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001522 }
1523 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001524 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001525 }
1526 });
1527 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001528 // When Launcher comes back to foreground, a different Activity might be responsible for
1529 // the app market intent, so refresh the icon
1530 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001531 clearTypedText();
1532 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001533 }
1534
1535 private void sendAdvanceMessage(long delay) {
1536 mHandler.removeMessages(ADVANCE_MSG);
1537 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1538 mHandler.sendMessageDelayed(msg, delay);
1539 mAutoAdvanceSentTime = System.currentTimeMillis();
1540 }
1541
1542 private void updateRunning() {
1543 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1544 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1545 mAutoAdvanceRunning = autoAdvanceRunning;
1546 if (autoAdvanceRunning) {
1547 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1548 sendAdvanceMessage(delay);
1549 } else {
1550 if (!mWidgetsToAdvance.isEmpty()) {
1551 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1552 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1553 }
1554 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001555 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001556 }
1557 }
1558 }
1559
1560 private final Handler mHandler = new Handler() {
1561 @Override
1562 public void handleMessage(Message msg) {
1563 if (msg.what == ADVANCE_MSG) {
1564 int i = 0;
1565 for (View key: mWidgetsToAdvance.keySet()) {
1566 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1567 final int delay = mAdvanceStagger * i;
1568 if (v instanceof Advanceable) {
1569 postDelayed(new Runnable() {
1570 public void run() {
1571 ((Advanceable) v).advance();
1572 }
1573 }, delay);
1574 }
1575 i++;
1576 }
1577 sendAdvanceMessage(mAdvanceInterval);
1578 }
1579 }
1580 };
1581
1582 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001583 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001584 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1585 if (v instanceof Advanceable) {
1586 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001587 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001588 updateRunning();
1589 }
1590 }
1591
1592 void removeWidgetToAutoAdvance(View hostView) {
1593 if (mWidgetsToAdvance.containsKey(hostView)) {
1594 mWidgetsToAdvance.remove(hostView);
1595 updateRunning();
1596 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001597 }
1598
Joe Onorato9c1289c2009-08-17 11:03:03 -04001599 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001600 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001601 launcherInfo.hostView = null;
1602 }
1603
Winson Chung93eef082012-03-23 15:59:27 -07001604 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1605 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1606 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001607 }
1608
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001609 public LauncherAppWidgetHost getAppWidgetHost() {
1610 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611 }
Romain Guycbb89e42009-06-08 15:52:54 -07001612
Winson Chunga9abd0e2010-10-27 17:18:37 -07001613 public LauncherModel getModel() {
1614 return mModel;
1615 }
1616
Bjorn Bringertc459e522013-06-07 19:36:01 +01001617 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001618 getWindow().closeAllPanels();
1619
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001620 // Whatever we were doing is hereby canceled.
1621 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001622 }
1623
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001624 @Override
1625 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001626 long startTime = 0;
1627 if (DEBUG_RESUME_TIME) {
1628 startTime = System.currentTimeMillis();
1629 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001630 super.onNewIntent(intent);
1631
1632 // Close the menu
1633 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001634 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001635 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001636
Jamie Genniscb222e82012-10-23 15:44:26 -07001637 final boolean alreadyOnHome =
1638 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001639 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001640
Jamie Genniscb222e82012-10-23 15:44:26 -07001641 Runnable processIntent = new Runnable() {
1642 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001643 if (mWorkspace == null) {
1644 // Can be cases where mWorkspace is null, this prevents a NPE
1645 return;
1646 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001647 Folder openFolder = mWorkspace.getOpenFolder();
1648 // In all these cases, only animate if we're already on home
1649 mWorkspace.exitWidgetResizeMode();
1650 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1651 openFolder == null) {
1652 mWorkspace.moveToDefaultScreen(true);
1653 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001654
Jamie Genniscb222e82012-10-23 15:44:26 -07001655 closeFolder();
1656 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001657
Jamie Genniscb222e82012-10-23 15:44:26 -07001658 // If we are already on home, then just animate back to the workspace,
1659 // otherwise, just wait until onResume to set the state back to Workspace
1660 if (alreadyOnHome) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001661 showWorkspaceAndExitOverviewMode(true);
Jamie Genniscb222e82012-10-23 15:44:26 -07001662 } else {
1663 mOnResumeState = State.WORKSPACE;
1664 }
1665
1666 final View v = getWindow().peekDecorView();
1667 if (v != null && v.getWindowToken() != null) {
1668 InputMethodManager imm = (InputMethodManager)getSystemService(
1669 INPUT_METHOD_SERVICE);
1670 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1671 }
1672
1673 // Reset AllApps to its initial state
1674 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1675 mAppsCustomizeTabHost.reset();
1676 }
1677 }
1678 };
1679
1680 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1681 // Delay processing of the intent to allow the status bar animation to finish
1682 // first in order to avoid janky animations.
1683 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001684 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001685 // Process the intent immediately.
1686 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001687 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001688
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
Michael Jurka447bf842013-05-15 14:52:15 +02001690 if (DEBUG_RESUME_TIME) {
1691 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1692 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 }
1694
Adam Cohen040a5d22013-09-16 17:09:33 -07001695 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1696 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001697 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001698 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001699 }
1700 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001701 protected void showWorkspaceAndExitOverviewMode() {
1702 showWorkspaceAndExitOverviewMode(true);
1703 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001704
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001706 public void onRestoreInstanceState(Bundle state) {
1707 super.onRestoreInstanceState(state);
1708 for (int page: mSynchronouslyBoundPages) {
1709 mWorkspace.restoreInstanceStateForChild(page);
1710 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
1712
1713 @Override
1714 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001715 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001716 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717
Michael Jurka883f55b2010-10-21 15:47:14 -07001718 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001719 // We close any open folder since it will not be re-opened, and we need to make sure
1720 // this state is reflected.
1721 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722
Adam Cohendcd297f2013-06-18 13:13:40 -07001723 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001724 mWaitingForResult) {
1725 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001726 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001727 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1728 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001729 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1730 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1731 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732 }
1733
1734 if (mFolderInfo != null && mWaitingForResult) {
1735 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1736 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1737 }
Michael Jurka946ad472010-07-09 18:05:18 -07001738
Winson Chung785d2eb2011-04-14 16:08:02 -07001739 // Save the current AppsCustomize tab
1740 if (mAppsCustomizeTabHost != null) {
1741 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1742 if (currentTabTag != null) {
1743 outState.putString("apps_customize_currentTab", currentTabTag);
1744 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001745 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1746 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001747 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001748 }
1749
1750 @Override
1751 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001752 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001753
Winson Chunge7a03942011-08-05 15:05:12 -07001754 // Remove all pending runnables
1755 mHandler.removeMessages(ADVANCE_MSG);
1756 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001757 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001758
Winson Chungcd2b0142011-06-08 16:02:26 -07001759 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001760 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001761 mModel.stopLoader();
1762 app.setLauncher(null);
1763
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001765 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001766 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001767 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001769 mAppWidgetHost = null;
1770
1771 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772
1773 TextKeyListener.getInstance().release();
1774
Winson Chung81b52252012-08-27 15:34:29 -07001775 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1776 // to prevent leaking Launcher activities on orientation change.
1777 if (mModel != null) {
1778 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1779 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001780
1781 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001782 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001783
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001784 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001785 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1786 mWorkspace.removeAllViews();
1787 mWorkspace = null;
1788 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001789
Michael Jurka2ecf9952012-06-18 12:52:28 -07001790 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001791 }
1792
Adam Cohena9cf38f2011-05-02 15:36:58 -07001793 public DragController getDragController() {
1794 return mDragController;
1795 }
1796
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 @Override
1798 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001799 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 super.startActivityForResult(intent, requestCode);
1801 }
1802
Winson Chung70d72102011-08-12 11:24:35 -07001803 /**
1804 * Indicates that we want global search for this activity by setting the globalSearch
1805 * argument for {@link #startSearch} to true.
1806 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001808 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001810
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001811 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001812
Karl Rosaen138a0412009-04-23 19:00:21 -07001813 if (initialQuery == null) {
1814 // Use any text typed in the launcher as the initial query
1815 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 if (appSearchData == null) {
1818 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001819 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 }
Winson Chungadf0c182012-08-23 14:59:07 -07001821 Rect sourceBounds = new Rect();
1822 if (mSearchDropTargetBar != null) {
1823 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1824 }
Romain Guycbb89e42009-06-08 15:52:54 -07001825
Bjorn Bringertc459e522013-06-07 19:36:01 +01001826 startSearch(initialQuery, selectInitialQuery,
1827 appSearchData, sourceBounds);
1828 }
1829
1830 public void startSearch(String initialQuery,
1831 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001832 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001833 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001834 }
1835
1836 /**
1837 * Starts the global search activity. This code is a copied from SearchManager
1838 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001839 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001840 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001841 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001842 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1843 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1844 if (globalSearchActivity == null) {
1845 Log.w(TAG, "No global search activity found.");
1846 return;
1847 }
1848 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1849 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1850 intent.setComponent(globalSearchActivity);
1851 // Make sure that we have a Bundle to put source in
1852 if (appSearchData == null) {
1853 appSearchData = new Bundle();
1854 } else {
1855 appSearchData = new Bundle(appSearchData);
1856 }
1857 // Set source to package name of app that starts global search, if not set already.
1858 if (!appSearchData.containsKey("source")) {
1859 appSearchData.putString("source", getPackageName());
1860 }
1861 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1862 if (!TextUtils.isEmpty(initialQuery)) {
1863 intent.putExtra(SearchManager.QUERY, initialQuery);
1864 }
1865 if (selectInitialQuery) {
1866 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1867 }
1868 intent.setSourceBounds(sourceBounds);
1869 try {
1870 startActivity(intent);
1871 } catch (ActivityNotFoundException ex) {
1872 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1873 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001874 }
1875
Winson Chung70d72102011-08-12 11:24:35 -07001876 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001877 public boolean onPrepareOptionsMenu(Menu menu) {
1878 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001879 if (!mWorkspace.isInOverviewMode()) {
1880 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001881 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001882 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001883 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001885 @Override
1886 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001887 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001888 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001889 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001890 }
1891
Joe Onorato9c1289c2009-08-17 11:03:03 -04001892 public boolean isWorkspaceLocked() {
1893 return mWorkspaceLoading || mWaitingForResult;
1894 }
1895
Michael Jurka0280c3b2010-09-17 15:00:07 -07001896 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001897 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001898 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001899 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1900 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001901 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001902 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001903 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001904
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001905 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1906 AppWidgetProviderInfo appWidgetInfo) {
1907 if (appWidgetInfo.configure != null) {
1908 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001909
Bjorn Bringert7984c942009-12-09 15:38:25 +00001910 // Launch over to configure widget, if needed
1911 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001912 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001913 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001914 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001915 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001916 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001917 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001918 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001919 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001920 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001921 }
1922 }
Romain Guycbb89e42009-06-08 15:52:54 -07001923
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001924 protected void moveToCustomContentScreen(boolean animate) {
1925 mWorkspace.moveToCustomContentScreen(animate);
1926 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001927 /**
1928 * Process a shortcut drop.
1929 *
1930 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001931 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001932 * @param cell The cell it should be added to, optional
1933 * @param position The location on the screen where it was dropped, optional
1934 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001935 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001936 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001937 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001938 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001939 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001940 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001941
1942 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001943 mPendingAddInfo.cellX = cell[0];
1944 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001945 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001946
1947 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1948 createShortcutIntent.setComponent(componentName);
1949 processShortcut(createShortcutIntent);
1950 }
1951
Adam Cohenfbba09b2011-07-18 21:43:05 -07001952 /**
1953 * Process a widget drop.
1954 *
1955 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001956 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001957 * @param cell The cell it should be added to, optional
1958 * @param position The location on the screen where it was dropped, optional
1959 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001960 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001961 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001962 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001964 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001966 mPendingAddInfo.minSpanX = info.minSpanX;
1967 mPendingAddInfo.minSpanY = info.minSpanY;
1968
Adam Cohenfbba09b2011-07-18 21:43:05 -07001969 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001970 mPendingAddInfo.cellX = cell[0];
1971 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001972 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001973 if (span != null) {
1974 mPendingAddInfo.spanX = span[0];
1975 mPendingAddInfo.spanY = span[1];
1976 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001977
Adam Cohened66b2b2012-01-23 17:28:51 -08001978 AppWidgetHostView hostView = info.boundWidget;
1979 int appWidgetId;
1980 if (hostView != null) {
1981 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001982 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001983 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001984 // In this case, we either need to start an activity to get permission to bind
1985 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001986 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001987 Bundle options = info.bindOptions;
1988
1989 boolean success = false;
1990 if (options != null) {
1991 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1992 info.componentName, options);
1993 } else {
1994 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1995 info.componentName);
1996 }
1997 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001998 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001999 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002000 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002001 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2002 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2003 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002004 // TODO: we need to make sure that this accounts for the options bundle.
2005 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002006 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2007 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002008 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002009 }
2010
Joe Onoratodeb98af2010-02-19 14:59:39 -08002011 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002012 // Handle case where user selected "Applications"
2013 String applicationName = getResources().getString(R.string.group_applications);
2014 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002015
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002016 if (applicationName != null && applicationName.equals(shortcutName)) {
2017 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2018 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002019
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002020 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2021 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002022 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002023 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002024 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002025 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028
Winson Chung24ab2f12010-09-16 14:10:47 -07002029 void processWallpaper(Intent intent) {
2030 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2031 }
2032
Adam Cohendcd297f2013-06-18 13:13:40 -07002033 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002034 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002035 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002036 folderInfo.title = getText(R.string.folder_name);
2037
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002039 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002040 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002041 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002042
2043 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002044 FolderIcon newFolder =
2045 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002046 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002047 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002048 // Force measure the new folder icon
2049 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2050 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002051 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 }
Romain Guycbb89e42009-06-08 15:52:54 -07002053
Joe Onorato9c1289c2009-08-17 11:03:03 -04002054 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002055 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002056 }
2057
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002058 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002059 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002061 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002062 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 }
2064
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002065 protected ComponentName getWallpaperPickerComponent() {
2066 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2067 }
2068
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002069 /**
2070 * Registers various content observers. The current implementation registers
2071 * only a favorites observer to keep track of the favorites applications.
2072 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002073 private void registerContentObservers() {
2074 ContentResolver resolver = getContentResolver();
2075 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2076 true, mWidgetObserver);
2077 }
2078
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 @Override
2080 public boolean dispatchKeyEvent(KeyEvent event) {
2081 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2082 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002084 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002085 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002086 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002087 dumpState();
2088 return true;
2089 }
2090 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002091 }
2092 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2093 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002094 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 return true;
2096 }
2097 }
2098
2099 return super.dispatchKeyEvent(event);
2100 }
2101
Joe Onorato88ec0992009-11-19 13:16:06 -08002102 @Override
2103 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002104 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002105 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002106 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002107 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002108 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002109 Folder openFolder = mWorkspace.getOpenFolder();
2110 if (openFolder.isEditingName()) {
2111 openFolder.dismissEditingName();
2112 } else {
2113 closeFolder();
2114 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002115 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002116 mWorkspace.exitWidgetResizeMode();
2117
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002118 // Back button is a no-op here, but give at least some feedback for the button press
2119 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002120 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002121 }
2122
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002124 * Re-listen when widgets are reset.
2125 */
2126 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002127 if (mAppWidgetHost != null) {
2128 mAppWidgetHost.startListening();
2129 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002130 }
2131
2132 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002133 * Launches the intent referred by the clicked shortcut.
2134 *
2135 * @param v The view representing the clicked shortcut.
2136 */
2137 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002138 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2139 // view has detached (it's possible for this to happen if the view is removed mid touch).
2140 if (v.getWindowToken() == null) {
2141 return;
2142 }
2143
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002144 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002145 return;
2146 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002147
Adam Cohen1697b792013-09-17 19:08:21 -07002148 if (v instanceof Workspace) {
2149 if (mWorkspace.isInOverviewMode()) {
2150 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002151 }
2152 return;
2153 }
2154
2155 if (v instanceof CellLayout) {
2156 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002157 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002158 }
2159 }
2160
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002162 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002164 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2165 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002166
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002167 // Check for special shortcuts
2168 if (intent.getComponent() != null) {
2169 final String shortcutClass = intent.getComponent().getClassName();
2170
2171 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002172 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002173 return;
2174 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2175 MemoryDumpActivity.startDump(this);
2176 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002177 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2178 toggleShowWeightWatcher();
2179 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002180 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002181 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002182
2183 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002184 int[] pos = new int[2];
2185 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002186 intent.setSourceBounds(new Rect(pos[0], pos[1],
2187 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002188
2189 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002190
Daniel Sandlerff02d492013-08-05 02:12:05 -04002191 mStats.recordLaunch(intent, shortcut);
2192
Michael Jurkaddd62e92011-02-16 17:49:14 -08002193 if (success && v instanceof BubbleTextView) {
2194 mWaitingForResume = (BubbleTextView) v;
2195 mWaitingForResume.setStayPressed(true);
2196 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002198 if (v instanceof FolderIcon) {
2199 FolderIcon fi = (FolderIcon) v;
2200 handleFolderClick(fi);
2201 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002202 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002203 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002204 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002205 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002206 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002207 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 }
2209 }
2210
Michael Jurka0e260592010-06-30 17:07:39 -07002211 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002212 return false;
2213 }
2214
Michael Jurkaaf442092010-06-10 17:01:57 -07002215 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002216 * Event handler for the search button
2217 *
2218 * @param v The view that was clicked.
2219 */
2220 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002221 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2222
Amith Yamasania135ba82011-08-09 17:42:01 -07002223 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002224 }
2225
2226 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002227 * Event handler for the voice button
2228 *
2229 * @param v The view that was clicked.
2230 */
2231 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002232 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002233
Bjorn Bringertc459e522013-06-07 19:36:01 +01002234 startVoice();
2235 }
2236
2237 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002238 try {
2239 final SearchManager searchManager =
2240 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2241 ComponentName activityName = searchManager.getGlobalSearchActivity();
2242 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002243 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002244 if (activityName != null) {
2245 intent.setPackage(activityName.getPackageName());
2246 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002247 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002248 } catch (ActivityNotFoundException e) {
2249 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002250 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002251 startActivitySafely(null, intent, "onClickVoiceButton");
2252 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002253 }
2254
2255 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002256 * Event handler for the "grid" button that appears on the home screen, which
2257 * enters all apps mode.
2258 *
2259 * @param v The view that was clicked.
2260 */
2261 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002262 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002263 }
2264
2265 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002266 // Provide the same haptic feedback that the system offers for virtual keys.
2267 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002268 }
2269
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002270 public void onClickAppMarketButton(View v) {
2271 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002272 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002273 } else {
2274 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002275 }
2276 }
2277
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002278 /**
2279 * Called when the user stops interacting with the launcher.
2280 * This implies that the user is now on the homescreen and is not doing housekeeping.
2281 */
2282 protected void onInteractionEnd() {}
2283
2284 /**
2285 * Called when the user starts interacting with the launcher.
2286 * The possible interactions are:
2287 * - open all apps
2288 * - reorder an app shortcut, or a widget
2289 * - open the overview mode.
2290 * This is a good time to stop doing things that only make sense
2291 * when the user is on the homescreen and not doing housekeeping.
2292 */
2293 protected void onInteractionBegin() {}
2294
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002295 void startApplicationDetailsActivity(ComponentName componentName) {
2296 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002297 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2298 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002299 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002300 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002301 }
2302
Michael Jurka1e2f4652013-07-08 18:03:46 -07002303 // returns true if the activity was started
2304 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002305 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002306 // System applications cannot be installed. For now, show a toast explaining that.
2307 // We may give them the option of disabling apps this way.
2308 int messageId = R.string.uninstall_system_app_text;
2309 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002310 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002311 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002312 String packageName = componentName.getPackageName();
2313 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002314 Intent intent = new Intent(
2315 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002316 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2317 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002318 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002319 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002320 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002321 }
2322
Michael Jurka86a720e2012-05-09 11:23:23 -07002323 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002324 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002325
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002327 // Only launch using the new animation if the shortcut has not opted out (this is a
2328 // private contract between launcher and may be ignored in the future).
2329 boolean useLaunchAnimation = (v != null) &&
2330 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2331 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002332 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2333 v.getMeasuredWidth(), v.getMeasuredHeight());
2334
2335 startActivity(intent, opts.toBundle());
2336 } else {
2337 startActivity(intent);
2338 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002339 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 } catch (SecurityException e) {
2341 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002342 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002343 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002344 "or use the exported attribute for this activity. "
2345 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002346 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002347 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002348 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002349
Michael Jurka86a720e2012-05-09 11:23:23 -07002350 boolean startActivitySafely(View v, Intent intent, Object tag) {
2351 boolean success = false;
2352 try {
2353 success = startActivity(v, intent, tag);
2354 } catch (ActivityNotFoundException e) {
2355 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2356 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2357 }
2358 return success;
2359 }
2360
Adam Cohena9cf38f2011-05-02 15:36:58 -07002361 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002362 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002363 Folder openFolder = mWorkspace.getFolderForTag(info);
2364
2365 // If the folder info reports that the associated folder is open, then verify that
2366 // it is actually opened. There have been a few instances where this gets out of sync.
2367 if (info.opened && openFolder == null) {
2368 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002369 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002370 info.opened = false;
2371 }
2372
Adam Cohenfb91f302012-06-11 15:45:18 -07002373 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 // Close any open folder
2375 closeFolder();
2376 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002377 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002378 } else {
2379 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002380 int folderScreen;
2381 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002382 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002383 // .. and close it
2384 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002385 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 // Close any folder open on the current screen
2387 closeFolder();
2388 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002389 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 }
2391 }
2392 }
2393 }
2394
Adam Cohen268c4752012-06-06 17:47:33 -07002395 /**
2396 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2397 * in the DragLayer in the exact absolute location of the original FolderIcon.
2398 */
2399 private void copyFolderIconToImage(FolderIcon fi) {
2400 final int width = fi.getMeasuredWidth();
2401 final int height = fi.getMeasuredHeight();
2402
2403 // Lazy load ImageView, Bitmap and Canvas
2404 if (mFolderIconImageView == null) {
2405 mFolderIconImageView = new ImageView(this);
2406 }
2407 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2408 mFolderIconBitmap.getHeight() != height) {
2409 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2410 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2411 }
2412
2413 DragLayer.LayoutParams lp;
2414 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2415 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2416 } else {
2417 lp = new DragLayer.LayoutParams(width, height);
2418 }
2419
Adam Cohen307fe232012-08-16 17:55:58 -07002420 // The layout from which the folder is being opened may be scaled, adjust the starting
2421 // view size by this scale factor.
2422 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002423 lp.customPosition = true;
2424 lp.x = mRectForFolderAnimation.left;
2425 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002426 lp.width = (int) (scale * width);
2427 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002428
2429 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2430 fi.draw(mFolderIconCanvas);
2431 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002432 if (fi.getFolder() != null) {
2433 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2434 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002435 }
Adam Cohen268c4752012-06-06 17:47:33 -07002436 // Just in case this image view is still in the drag layer from a previous animation,
2437 // we remove it and re-add it.
2438 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2439 mDragLayer.removeView(mFolderIconImageView);
2440 }
2441 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002442 if (fi.getFolder() != null) {
2443 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002444 }
Adam Cohen268c4752012-06-06 17:47:33 -07002445 }
2446
Adam Cohen2801caf2011-05-13 20:57:39 -07002447 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002448 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002449 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2450 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2451 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2452
Adam Cohenc51934b2011-07-26 21:07:43 -07002453 FolderInfo info = (FolderInfo) fi.getTag();
2454 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2455 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002456 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2457 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002458 }
2459
Adam Cohen268c4752012-06-06 17:47:33 -07002460 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2461 copyFolderIconToImage(fi);
2462 fi.setVisibility(View.INVISIBLE);
2463
Michael Jurka2ecf9952012-06-18 12:52:28 -07002464 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002465 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002466 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2467 oa.start();
2468 }
2469
Adam Cohen268c4752012-06-06 17:47:33 -07002470 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002471 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002472 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2473 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2474 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2475
Adam Cohen268c4752012-06-06 17:47:33 -07002476 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002477
Adam Cohen268c4752012-06-06 17:47:33 -07002478 // We remove and re-draw the FolderIcon in-case it has changed
2479 mDragLayer.removeView(mFolderIconImageView);
2480 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002481 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002482 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002483 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002484 oa.addListener(new AnimatorListenerAdapter() {
2485 @Override
2486 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002487 if (cl != null) {
2488 cl.clearFolderLeaveBehind();
2489 // Remove the ImageView copy of the FolderIcon and make the original visible.
2490 mDragLayer.removeView(mFolderIconImageView);
2491 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002492 }
2493 }
2494 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002495 oa.start();
2496 }
2497
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002498 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002499 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002500 * is animated relative to the specified View. If the View is null, no animation
2501 * is played.
2502 *
2503 * @param folderInfo The FolderInfo describing the folder to open.
2504 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002505 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002506 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002507 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002508
Adam Cohena9cf38f2011-05-02 15:36:58 -07002509 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002510
Adam Cohen4554ee12011-08-03 16:13:21 -07002511 // Just verify that the folder hasn't already been added to the DragLayer.
2512 // There was a one-off crash where the folder had a parent already.
2513 if (folder.getParent() == null) {
2514 mDragLayer.addView(folder);
2515 mDragController.addDropTarget((DropTarget) folder);
2516 } else {
2517 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2518 folder.getParent() + ").");
2519 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002520 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002521 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002522
2523 // Notify the accessibility manager that this folder "window" has appeared and occluded
2524 // the workspace items
2525 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2526 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002527 }
2528
2529 public void closeFolder() {
2530 Folder folder = mWorkspace.getOpenFolder();
2531 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002532 if (folder.isEditingName()) {
2533 folder.dismissEditingName();
2534 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002535 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002536
2537 // Dismiss the folder cling
2538 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002539 }
2540 }
2541
2542 void closeFolder(Folder folder) {
2543 folder.getInfo().opened = false;
2544
2545 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2546 if (parent != null) {
2547 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2548 shrinkAndFadeInFolderIcon(fi);
2549 }
2550 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002551
2552 // Notify the accessibility manager that this folder "window" has disappeard and no
2553 // longer occludeds the workspace items
2554 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002555 }
2556
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002557 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002558 if (!isDraggingEnabled()) return false;
2559 if (isWorkspaceLocked()) return false;
2560 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002561
Adam Cohen1697b792013-09-17 19:08:21 -07002562 if (v instanceof Workspace) {
2563 if (!mWorkspace.isInOverviewMode()) {
2564 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2565 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2566 mWorkspace.enterOverviewMode();
2567 }
2568 return true;
2569 }
2570
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002571 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002572 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002573 }
2574
Michael Jurka0280c3b2010-09-17 15:00:07 -07002575 resetAddInfo();
2576 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002577 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002578 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002579 return true;
2580 }
2581
Winson Chung3d503fb2011-07-13 17:25:49 -07002582 // The hotseat touch handling does not go through Workspace, and we always allow long press
2583 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002584 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002585 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2586 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002587 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002588 // User long pressed on empty space
2589 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2590 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2591 // Disabling reordering until we sort out some issues.
2592 if (mWorkspace.isInOverviewMode()) {
2593 mWorkspace.startReordering(v);
2594 } else {
2595 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002596 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002597 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002598 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002599 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002600 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002601 }
2602 }
2603 }
2604 return true;
2605 }
2606
Winson Chung3d503fb2011-07-13 17:25:49 -07002607 boolean isHotseatLayout(View layout) {
2608 return mHotseat != null && layout != null &&
2609 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2610 }
2611 Hotseat getHotseat() {
2612 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002613 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002614 View getOverviewPanel() {
2615 return mOverviewPanel;
2616 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002617 SearchDropTargetBar getSearchBar() {
2618 return mSearchDropTargetBar;
2619 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002620
Winson Chung3d503fb2011-07-13 17:25:49 -07002621 /**
2622 * Returns the CellLayout of the specified container at the specified screen.
2623 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002624 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002625 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2626 if (mHotseat != null) {
2627 return mHotseat.getLayout();
2628 } else {
2629 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002630 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002631 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002632 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002633 }
2634 }
2635
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002636 Workspace getWorkspace() {
2637 return mWorkspace;
2638 }
2639
Daniel Sandler843e8602010-06-07 14:59:01 -04002640 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002641 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002642 }
2643
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 /**
2645 * Helper method for the cameraZoomIn/cameraZoomOut animations
2646 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002647 * @param scaleFactor The scale factor used for the zoom
2648 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002649 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002650 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002651 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002652 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002653
Winson Chung18f41f82012-05-09 13:28:10 -07002654 void disableWallpaperIfInAllApps() {
2655 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002656 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002657 if (mAppsCustomizeTabHost != null &&
2658 !mAppsCustomizeTabHost.isTransitioning()) {
2659 updateWallpaperVisibility(false);
2660 }
2661 }
2662 }
2663
Craig Mautner360310b2012-10-26 15:13:08 -07002664 private void setWorkspaceBackground(boolean workspace) {
2665 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002666 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002667 }
2668
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002669 void updateWallpaperVisibility(boolean visible) {
2670 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2671 int curflags = getWindow().getAttributes().flags
2672 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2673 if (wpflags != curflags) {
2674 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2675 }
Craig Mautner360310b2012-10-26 15:13:08 -07002676 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002677 }
2678
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002679 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2680 if (v instanceof LauncherTransitionable) {
2681 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2682 }
2683 }
2684
Michael Jurkabed61d22012-02-14 22:51:29 -08002685 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2686 if (v instanceof LauncherTransitionable) {
2687 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2688 }
Winson Chung70442722012-02-10 15:43:22 -08002689
2690 // Update the workspace transition step as well
2691 dispatchOnLauncherTransitionStep(v, 0f);
2692 }
2693
2694 private void dispatchOnLauncherTransitionStep(View v, float t) {
2695 if (v instanceof LauncherTransitionable) {
2696 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2697 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002698 }
2699
2700 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2701 if (v instanceof LauncherTransitionable) {
2702 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2703 }
Winson Chung70442722012-02-10 15:43:22 -08002704
2705 // Update the workspace transition step as well
2706 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002707 }
2708
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002709 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002710 * Things to test when changing the following seven functions.
2711 * - Home from workspace
2712 * - from center screen
2713 * - from other screens
2714 * - Home from all apps
2715 * - from center screen
2716 * - from other screens
2717 * - Back from all apps
2718 * - from center screen
2719 * - from other screens
2720 * - Launch app from workspace and quit
2721 * - with back
2722 * - with home
2723 * - Launch app from all apps and quit
2724 * - with back
2725 * - with home
2726 * - Go to a screen that's not the default, then all
2727 * apps, and launch and app, and go back
2728 * - with back
2729 * -with home
2730 * - On workspace, long press power and go back
2731 * - with back
2732 * - with home
2733 * - On all apps, long press power and go back
2734 * - with back
2735 * - with home
2736 * - On workspace, power off
2737 * - On all apps, power off
2738 * - Launch an app and turn off the screen while in that app
2739 * - Go back with home key
2740 * - Go back with back key TODO: make this not go to workspace
2741 * - From all apps
2742 * - From workspace
2743 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2744 * - From all apps
2745 * - From the center workspace
2746 * - From another workspace
2747 */
2748
2749 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002750 * Zoom the camera out from the workspace to reveal 'toView'.
2751 * Assumes that the view to show is anchored at either the very top or very bottom
2752 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002753 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002754 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002755 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2756 showAppsCustomizeHelper(animated, springLoaded, contentType);
2757 }
2758 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2759 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002760 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002761 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002762 mStateAnimation.cancel();
2763 mStateAnimation = null;
2764 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002765 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002766
Winson Chungf0ea4d32011-06-06 14:27:16 -07002767 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2768 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2769 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002770 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002771 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002772 final int startDelay =
2773 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002774
Michael Jurkab3e22d92011-10-31 15:58:33 -07002775 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002776
Michael Jurkad74c9842011-07-10 12:44:21 -07002777 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002778 Animator workspaceAnim =
2779 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002780 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2781 // Set the content type for the all apps space
2782 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2783 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002784
2785 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002786 toView.setScaleX(scale);
2787 toView.setScaleY(scale);
2788 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2789 scaleAnim.
2790 scaleX(1f).scaleY(1f).
2791 setDuration(duration).
2792 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002793
Winson Chungf0ea4d32011-06-06 14:27:16 -07002794 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002795 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002796 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002797 .ofFloat(toView, "alpha", 0f, 1f)
2798 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002799 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002800 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2801 @Override
2802 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002803 if (animation == null) {
2804 throw new RuntimeException("animation is null");
2805 }
Winson Chung70442722012-02-10 15:43:22 -08002806 float t = (Float) animation.getAnimatedValue();
2807 dispatchOnLauncherTransitionStep(fromView, t);
2808 dispatchOnLauncherTransitionStep(toView, t);
2809 }
2810 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002811
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002812 // toView should appear right at the end of the workspace shrink
2813 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002814 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002815 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002816 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002817
2818 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002819 boolean animationCancelled = false;
2820
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002821 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002822 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002823 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002824 // Prepare the position
2825 toView.setTranslationX(0.0f);
2826 toView.setTranslationY(0.0f);
2827 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002828 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002829 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002830 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002831 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002832 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2833 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002834
Adam Cohenf4ddea32011-09-12 13:46:42 -07002835 if (!animationCancelled) {
2836 updateWallpaperVisibility(false);
2837 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002838
2839 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002840 if (mSearchDropTargetBar != null) {
2841 mSearchDropTargetBar.hideSearchBar(false);
2842 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002843 }
2844
Adam Cohencff6af82011-09-13 14:51:53 -07002845 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002846 public void onAnimationCancel(Animator animation) {
2847 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002848 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002849 });
2850
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002851 if (workspaceAnim != null) {
2852 mStateAnimation.play(workspaceAnim);
2853 }
Michael Jurka1899a362011-11-03 13:50:45 -07002854
2855 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002856
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002857 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2858 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002859
2860 // If any of the objects being animated haven't been measured/laid out
2861 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002862 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002863 (mWorkspace.getMeasuredWidth() == 0) ||
2864 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002865 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002866 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002867
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002868 final AnimatorSet stateAnimation = mStateAnimation;
2869 final Runnable startAnimRunnable = new Runnable() {
2870 public void run() {
2871 // Check that mStateAnimation hasn't changed while
2872 // we waited for a layout/draw pass
2873 if (mStateAnimation != stateAnimation)
2874 return;
2875 setPivotsForZoom(toView, scale);
2876 dispatchOnLauncherTransitionStart(fromView, animated, false);
2877 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002878 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002879 }
2880 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002881 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002882 final ViewTreeObserver observer = toView.getViewTreeObserver();
2883 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2884 public void onGlobalLayout() {
2885 startAnimRunnable.run();
2886 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2887 }
2888 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002889 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002890 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002891 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002892 } else {
2893 toView.setTranslationX(0.0f);
2894 toView.setTranslationY(0.0f);
2895 toView.setScaleX(1.0f);
2896 toView.setScaleY(1.0f);
2897 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002898 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002899
Daniel Sandlere4f98912013-06-25 15:13:26 -04002900 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002901 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002902 if (mSearchDropTargetBar != null) {
2903 mSearchDropTargetBar.hideSearchBar(false);
2904 }
Michael Jurkaabded662011-03-04 12:06:57 -08002905 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002906 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002907 dispatchOnLauncherTransitionStart(fromView, animated, false);
2908 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002909 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002910 dispatchOnLauncherTransitionStart(toView, animated, false);
2911 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002912 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002913 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002914 }
2915
2916 /**
2917 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002918 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002919 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002920 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002921 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2922 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002923
Michael Jurkab3e22d92011-10-31 15:58:33 -07002924 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002925 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002926 mStateAnimation.cancel();
2927 mStateAnimation = null;
2928 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002929 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002930
Winson Chungf0ea4d32011-06-06 14:27:16 -07002931 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002932 final int fadeOutDuration =
2933 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002934 final float scaleFactor = (float)
2935 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2936 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002937 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002938 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002939 if (toState == State.WORKSPACE) {
2940 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2941 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002942 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002943 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2944 workspaceAnim = mWorkspace.getChangeStateAnimation(
2945 Workspace.State.SPRING_LOADED, animated);
2946 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002947
Michael Jurkab3e22d92011-10-31 15:58:33 -07002948 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002949 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002950 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002951 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002952 final LauncherViewPropertyAnimator scaleAnim =
2953 new LauncherViewPropertyAnimator(fromView);
2954 scaleAnim.
2955 scaleX(scaleFactor).scaleY(scaleFactor).
2956 setDuration(duration).
2957 setInterpolator(new Workspace.ZoomInInterpolator());
2958
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002959 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002960 .ofFloat(fromView, "alpha", 1f, 0f)
2961 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002962 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002963 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2964 @Override
2965 public void onAnimationUpdate(ValueAnimator animation) {
2966 float t = 1f - (Float) animation.getAnimatedValue();
2967 dispatchOnLauncherTransitionStep(fromView, t);
2968 dispatchOnLauncherTransitionStep(toView, t);
2969 }
2970 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002971
Michael Jurka2ecf9952012-06-18 12:52:28 -07002972 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002973
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002974 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2975 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002976 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002977
2978 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002979 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002980 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002981 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002982 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002983 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2984 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002985 if (onCompleteRunnable != null) {
2986 onCompleteRunnable.run();
2987 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002988 mAppsCustomizeContent.updateCurrentPageScroll();
2989 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002990 }
2991 });
2992
Winson Chungf0ea4d32011-06-06 14:27:16 -07002993 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002994 if (workspaceAnim != null) {
2995 mStateAnimation.play(workspaceAnim);
2996 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002997 dispatchOnLauncherTransitionStart(fromView, animated, true);
2998 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002999 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003000 } else {
3001 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003002 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003003 dispatchOnLauncherTransitionStart(fromView, animated, true);
3004 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003005 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003006 dispatchOnLauncherTransitionStart(toView, animated, true);
3007 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003008 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003009 }
3010
Michael Jurkae326f182011-11-21 14:05:46 -08003011 @Override
3012 public void onTrimMemory(int level) {
3013 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003014 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003015 mAppsCustomizeTabHost.onTrimMemory();
3016 }
3017 }
3018
Winson Chung18f41f82012-05-09 13:28:10 -07003019 @Override
3020 public void onWindowFocusChanged(boolean hasFocus) {
3021 if (!hasFocus) {
3022 // When another window occludes launcher (like the notification shade, or recents),
3023 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3024 updateWallpaperVisibility(true);
3025 } else {
3026 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003027 mWorkspace.postDelayed(new Runnable() {
3028 @Override
3029 public void run() {
3030 disableWallpaperIfInAllApps();
3031 }
3032 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003033 }
3034 }
3035
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003036 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003037 showWorkspace(animated, null);
3038 }
3039
3040 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003041 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003042 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003043 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003044 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003045
Winson Chungc7d2b602012-05-16 17:02:20 -07003046 // Show the search bar (only animate if we were showing the drop target bar in spring
3047 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003048 if (mSearchDropTargetBar != null) {
3049 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3050 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003051
Michael Jurkab3e22d92011-10-31 15:58:33 -07003052 // Set focus to the AppsCustomize button
3053 if (mAllAppsButton != null) {
3054 mAllAppsButton.requestFocus();
3055 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003056 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003057
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003058 // Change the state *after* we've called all the transition code
3059 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003060
Winson Chung5fb63472011-02-02 17:03:37 -08003061 // Resume the auto-advance of widgets
3062 mUserPresent = true;
3063 updateRunning();
3064
alanv1d4fde62012-10-17 13:15:47 -07003065 // Send an accessibility event to announce the context change
3066 getWindow().getDecorView()
3067 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003068
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003069 onWorkspaceShown(animated);
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003070 onInteractionEnd();
Bjorn Bringertc459e522013-06-07 19:36:01 +01003071 }
3072
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003073 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003074 }
3075
Winson Chungc58497e2013-09-03 17:48:37 -07003076 void showAllApps(boolean animated,
3077 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003078 if (mState != State.WORKSPACE) return;
3079
Winson Chungc58497e2013-09-03 17:48:37 -07003080 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003081 mAppsCustomizeTabHost.requestFocus();
3082
Michael Jurkab3e22d92011-10-31 15:58:33 -07003083 // Change the state *after* we've called all the transition code
3084 mState = State.APPS_CUSTOMIZE;
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07003085 onInteractionBegin();
Michael Jurkab3e22d92011-10-31 15:58:33 -07003086
3087 // Pause the auto-advance of widgets until we are out of AllApps
3088 mUserPresent = false;
3089 updateRunning();
3090 closeFolder();
3091
3092 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003093 getWindow().getDecorView()
3094 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003095 }
3096
Adam Cohen7777d962011-08-18 18:58:38 -07003097 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003098 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003099 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003100 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003101 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003102 }
Adam Cohen7777d962011-08-18 18:58:38 -07003103
Adam Cohened66b2b2012-01-23 17:28:51 -08003104 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3105 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003106 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3107
Winson Chunge7a03942011-08-05 15:05:12 -07003108 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003109 @Override
3110 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003111 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003112 // Before we show workspace, hide all apps again because
3113 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3114 // clean up our state transition functions
3115 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003116 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003117 } else {
3118 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003119 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003120 }
3121 }, (extendedDelay ?
3122 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3123 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3124 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003125
Michael Jurkad3ef3062010-11-23 16:23:58 -08003126 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003127 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003128 final boolean animated = true;
3129 final boolean springLoaded = true;
3130 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003131 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003132 }
3133 // Otherwise, we are not in spring loaded mode, so don't do anything.
3134 }
3135
Michael Jurkab3e22d92011-10-31 15:58:33 -07003136 void lockAllApps() {
3137 // TODO
3138 }
3139
3140 void unlockAllApps() {
3141 // TODO
3142 }
3143
Winson Chungf0ea4d32011-06-06 14:27:16 -07003144 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003145 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003146 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003147 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003148 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003149 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003150 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003151 int duration = 0;
3152 if (mSearchDropTargetBar != null) {
3153 duration = mSearchDropTargetBar.getTransitionInDuration();
3154 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003155 mHotseat.animate().alpha(1f).setDuration(duration);
3156 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003157 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003158 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003159 }
3160 }
3161 }
3162
3163 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003164 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003165 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003166 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003167 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003168 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003169 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003170 int duration = 0;
3171 if (mSearchDropTargetBar != null) {
3172 duration = mSearchDropTargetBar.getTransitionOutDuration();
3173 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003174 mHotseat.animate().alpha(0f).setDuration(duration);
3175 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003176 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003177 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003178 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003179 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003180 }
3181
Patrick Dubroy5f445422011-02-18 14:35:21 -08003182 /**
3183 * Add an item from all apps or customize onto the given workspace screen.
3184 * If layout is null, add to the current screen.
3185 */
3186 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003187 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003188 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003189 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003190 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003191
Winson Chungdff8ebb2011-09-08 17:25:31 -07003192 /** Maps the current orientation to an index for referencing orientation correct global icons */
3193 private int getCurrentOrientationIndexForGlobalIcons() {
3194 // default - 0, landscape - 1
3195 switch (getResources().getConfiguration().orientation) {
3196 case Configuration.ORIENTATION_LANDSCAPE:
3197 return 1;
3198 default:
3199 return 0;
3200 }
3201 }
3202
Michael Jurkaae65ee32012-04-30 11:45:54 -07003203 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003204 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003205 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003206 // Look for the toolbar icon specified in the activity meta-data
3207 Bundle metaData = packageManager.getActivityInfo(
3208 activityName, PackageManager.GET_META_DATA).metaData;
3209 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003210 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003211 if (iconResId != 0) {
3212 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003213 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003214 }
3215 }
3216 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003217 // This can happen if the activity defines an invalid drawable
3218 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3219 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003220 } catch (Resources.NotFoundException nfe) {
3221 // This can happen if the activity defines an invalid drawable
3222 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3223 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003224 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003225 return null;
3226 }
3227
3228 // if successful in getting icon, return it; otherwise, set button to use default drawable
3229 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003230 int buttonId, ComponentName activityName, int fallbackDrawableId,
3231 String toolbarResourceName) {
3232 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003233 Resources r = getResources();
3234 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3235 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003236
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003237 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003238 // If we were unable to find the icon via the meta-data, use a generic one
3239 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003240 toolbarIcon = r.getDrawable(fallbackDrawableId);
3241 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003242 if (button != null) {
3243 button.setCompoundDrawables(toolbarIcon, null, null, null);
3244 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003245 return null;
3246 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003247 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003248 if (button != null) {
3249 button.setCompoundDrawables(toolbarIcon, null, null, null);
3250 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003251 return toolbarIcon.getConstantState();
3252 }
3253 }
3254
3255 // if successful in getting icon, return it; otherwise, set button to use default drawable
3256 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003257 int buttonId, ComponentName activityName, int fallbackDrawableId,
3258 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003259 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003260 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003261
Michael Jurka19e0fc52011-07-22 18:00:21 -07003262 if (button != null) {
3263 // If we were unable to find the icon via the meta-data, use a
3264 // generic one
3265 if (toolbarIcon == null) {
3266 button.setImageResource(fallbackDrawableId);
3267 } else {
3268 button.setImageDrawable(toolbarIcon);
3269 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003270 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003271
3272 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3273
Michael Jurka0423dcf2010-10-05 14:56:18 -07003274 }
3275
Winson Chung1b884092012-06-08 17:13:02 -07003276 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003277 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003278 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003279 }
3280
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003281 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003282 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003283 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003284 }
3285
Winson Chungbb185bd2011-11-21 12:31:42 -08003286 private void invalidatePressedFocusedStates(View container, View button) {
3287 if (container instanceof HolographicLinearLayout) {
3288 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3289 layout.invalidatePressedFocusedStates();
3290 } else if (button instanceof HolographicImageView) {
3291 HolographicImageView view = (HolographicImageView) button;
3292 view.invalidatePressedFocusedStates();
3293 }
3294 }
3295
Cristina Stancu476493b2013-08-07 17:20:14 +01003296 public View getQsbBar() {
3297 if (mQsbBar == null) {
3298 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3299 }
3300 return mQsbBar;
3301 }
3302
3303 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003304 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003305 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003306 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003307 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003308
Winson Chung1cad91e2011-05-25 17:41:01 -07003309 final SearchManager searchManager =
3310 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3311 ComponentName activityName = searchManager.getGlobalSearchActivity();
3312 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003313 int coi = getCurrentOrientationIndexForGlobalIcons();
3314 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003315 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3316 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3317 if (sGlobalSearchIcon[coi] == null) {
3318 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3319 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3320 TOOLBAR_ICON_METADATA_NAME);
3321 }
3322
Winson Chungc51db6a2011-10-05 11:44:49 -07003323 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3324 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003325 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003326 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003327 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003328 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003329 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3330 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003331 if (searchButton != null) searchButton.setVisibility(View.GONE);
3332 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003333 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003334 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003335 }
3336 }
3337
Cristina Stancu476493b2013-08-07 17:20:14 +01003338 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003339 final View searchButtonContainer = findViewById(R.id.search_button_container);
3340 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003341 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003342 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003343 }
3344
Cristina Stancu476493b2013-08-07 17:20:14 +01003345 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003346 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003347 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003348
Winson Chungc51db6a2011-10-05 11:44:49 -07003349 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003350 final SearchManager searchManager =
3351 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3352 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3353
3354 ComponentName activityName = null;
3355 if (globalSearchActivity != null) {
3356 // Check if the global search activity handles voice search
3357 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3358 intent.setPackage(globalSearchActivity.getPackageName());
3359 activityName = intent.resolveActivity(getPackageManager());
3360 }
3361
3362 if (activityName == null) {
3363 // Fallback: check if an activity other than the global search activity
3364 // resolves this
3365 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3366 activityName = intent.resolveActivity(getPackageManager());
3367 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003368 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003369 int coi = getCurrentOrientationIndexForGlobalIcons();
3370 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003371 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3372 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3373 if (sVoiceSearchIcon[coi] == null) {
3374 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3375 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3376 TOOLBAR_ICON_METADATA_NAME);
3377 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003378 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003379 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003380 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003381 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003382 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003383 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003384 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003385 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003386 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003387 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003388 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003389 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003390
Cristina Stancu476493b2013-08-07 17:20:14 +01003391 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003392 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3393 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003394 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003395 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003396 }
3397
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003398 public void setVoiceButtonProxyVisible(boolean visible) {
3399 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3400 if (voiceButtonProxy != null) {
3401 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3402 }
3403 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003404 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003405 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003406 */
3407 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003408 final View marketButton = findViewById(R.id.market_button);
3409 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3410 // Find the app market activity by resolving an intent.
3411 // (If multiple app markets are installed, it will return the ResolverActivity.)
3412 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003413 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003414 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003415 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003416 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003417 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3418 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003419 marketButton.setVisibility(View.VISIBLE);
3420 } else {
3421 // We should hide and disable the view so that we don't try and restore the visibility
3422 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3423 marketButton.setVisibility(View.GONE);
3424 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003425 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003426 }
3427
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003428 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003429 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3430 Resources r = getResources();
3431 Drawable marketIconDrawable = d.newDrawable(r);
3432 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3433 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3434 marketIconDrawable.setBounds(0, 0, w, h);
3435
3436 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003437 }
3438
Michael Jurkad7c28052012-04-27 15:43:36 -07003439 @Override
3440 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003441 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003442 final List<CharSequence> text = event.getText();
3443 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003444 // Populate event with a fake title based on the current state.
3445 if (mState == State.APPS_CUSTOMIZE) {
3446 text.add(getString(R.string.all_apps_button_label));
3447 } else {
3448 text.add(getString(R.string.all_apps_home_button_label));
3449 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003450 return result;
3451 }
3452
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003453 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003454 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003455 */
3456 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3457 @Override
3458 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003459 closeSystemDialogs();
3460 }
3461 }
3462
3463 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003464 * Receives notifications whenever the appwidgets are reset.
3465 */
3466 private class AppWidgetResetObserver extends ContentObserver {
3467 public AppWidgetResetObserver() {
3468 super(new Handler());
3469 }
3470
3471 @Override
3472 public void onChange(boolean selfChange) {
3473 onAppWidgetReset();
3474 }
3475 }
3476
3477 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003478 * If the activity is currently paused, signal that we need to run the passed Runnable
3479 * in onResume.
3480 *
3481 * This needs to be called from incoming places where resources might have been loaded
3482 * while we are paused. That is becaues the Configuration might be wrong
3483 * when we're not running, and if it comes back to what it was when we
3484 * were paused, we are not restarted.
3485 *
3486 * Implementation of the method from LauncherModel.Callbacks.
3487 *
3488 * @return true if we are currently paused. The caller might be able to
3489 * skip some work in that case since we will come back again.
3490 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003491 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003492 if (mPaused) {
3493 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003494 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003495 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003496 }
3497 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003498 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003499 return true;
3500 } else {
3501 return false;
3502 }
3503 }
3504
Michael Jurkac402cd92013-05-20 15:49:32 +02003505 private boolean waitUntilResume(Runnable run) {
3506 return waitUntilResume(run, false);
3507 }
3508
Michael Jurka1e2f4652013-07-08 18:03:46 -07003509 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003510 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003511 }
3512
Michael Jurka7607c2f2013-04-03 14:33:19 -07003513 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003514 * If the activity is currently paused, signal that we need to re-run the loader
3515 * in onResume.
3516 *
3517 * This needs to be called from incoming places where resources might have been loaded
3518 * while we are paused. That is becaues the Configuration might be wrong
3519 * when we're not running, and if it comes back to what it was when we
3520 * were paused, we are not restarted.
3521 *
3522 * Implementation of the method from LauncherModel.Callbacks.
3523 *
3524 * @return true if we are currently paused. The caller might be able to
3525 * skip some work in that case since we will come back again.
3526 */
3527 public boolean setLoadOnResume() {
3528 if (mPaused) {
3529 Log.i(TAG, "setLoadOnResume");
3530 mOnResumeNeedsLoad = true;
3531 return true;
3532 } else {
3533 return false;
3534 }
3535 }
3536
3537 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003538 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003539 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003540 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003541 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003542 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003543 } else {
3544 return SCREEN_COUNT / 2;
3545 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003546 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003547
Joe Onorato9c1289c2009-08-17 11:03:03 -04003548 /**
3549 * Refreshes the shortcuts shown on the workspace.
3550 *
3551 * Implementation of the method from LauncherModel.Callbacks.
3552 */
3553 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003554 // If we're starting binding all over again, clear any bind calls we'd postponed in
3555 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3556 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003557 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003558
Winson Chungd64d1762013-08-20 14:37:16 -07003559 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003560 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003561 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003562
Michael Jurka05bf644e2011-11-30 20:28:53 -08003563 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003564 if (mHotseat != null) {
3565 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003566 }
3567 }
3568
Adam Cohendcd297f2013-06-18 13:13:40 -07003569 @Override
3570 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003571 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003572
Adam Cohen5084cba2013-09-03 12:01:16 -07003573 // If there are no screens, we need to have an empty screen
3574 if (orderedScreenIds.size() == 0) {
3575 mWorkspace.addExtraEmptyScreen();
3576 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003577
3578 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003579 // setCurrentPage() so ensure that all pages are added before calling this).
3580 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003581 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3582 mWorkspace.createCustomContentPage();
3583 }
Winson Chung64359a52013-07-08 17:17:08 -07003584 }
3585
3586 @Override
3587 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003588 int count = orderedScreenIds.size();
3589 for (int i = 0; i < count; i++) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003590 Launcher.addDumpLog(TAG, "10249126 - bindAddScreens(" + orderedScreenIds.get(i) + ")", true);
Adam Cohen89bddfa2013-08-20 11:57:13 -07003591 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003592 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003593 }
3594
Adam Cohen39a06042013-07-19 14:30:12 -07003595 private boolean shouldShowWeightWatcher() {
3596 String spKey = LauncherAppState.getSharedPreferencesKey();
3597 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003598 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003599
3600 return show;
3601 }
3602
Adam Cohen4caf2982013-08-20 18:54:31 -07003603 private boolean emailSent() {
3604 String spKey = LauncherAppState.getSharedPreferencesKey();
3605 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3606 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3607 return show;
3608 }
3609
3610 private void setEmailSent(boolean sent) {
3611 String spKey = LauncherAppState.getSharedPreferencesKey();
3612 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3613
3614 SharedPreferences.Editor editor = sp.edit();
3615 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3616 editor.commit();
3617 }
3618
Adam Cohen39a06042013-07-19 14:30:12 -07003619 private void toggleShowWeightWatcher() {
3620 String spKey = LauncherAppState.getSharedPreferencesKey();
3621 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3622 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3623
3624 show = !show;
3625
3626 SharedPreferences.Editor editor = sp.edit();
3627 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3628 editor.commit();
3629
3630 if (mWeightWatcher != null) {
3631 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3632 }
3633 }
3634
Winson Chungd64d1762013-08-20 14:37:16 -07003635 public void bindAppsAdded(final ArrayList<Long> newScreens,
3636 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003637 final ArrayList<ItemInfo> addAnimated,
3638 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003639 Runnable r = new Runnable() {
3640 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003641 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003642 }
3643 };
3644 if (waitUntilResume(r)) {
3645 return;
3646 }
3647
Adam Cohen4caf2982013-08-20 18:54:31 -07003648 Launcher.addDumpLog(TAG, "10249126 - bindAppsAdded(" + newScreens.size() + ")", true);
Winson Chungd64d1762013-08-20 14:37:16 -07003649
3650 // Add the new screens
3651 bindAddScreens(newScreens);
3652
3653 // We add the items without animation on non-visible pages, and with
3654 // animations on the new page (which we will try and snap to).
3655 if (!addNotAnimated.isEmpty()) {
3656 bindItems(addNotAnimated, 0,
3657 addNotAnimated.size(), false);
3658 }
3659 if (!addAnimated.isEmpty()) {
3660 bindItems(addAnimated, 0,
3661 addAnimated.size(), true);
3662 }
Winson Chungc58497e2013-09-03 17:48:37 -07003663
3664 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3665 addedApps != null && mAppsCustomizeContent != null) {
3666 mAppsCustomizeContent.addApps(addedApps);
3667 }
Winson Chungd64d1762013-08-20 14:37:16 -07003668 }
3669
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003670 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003671 * Bind the items start-end from the list.
3672 *
3673 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003674 */
Winson Chung64359a52013-07-08 17:17:08 -07003675 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3676 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003677 Runnable r = new Runnable() {
3678 public void run() {
3679 bindItems(shortcuts, start, end, forceAnimateIcons);
3680 }
3681 };
3682 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003683 return;
3684 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003685
Winson Chungf0c6ae02012-03-21 16:10:31 -07003686 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003687 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3688 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003689 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003690 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003691 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003692 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003693 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003694
3695 // Short circuit if we are loading dock items for a configuration which has no dock
3696 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3697 mHotseat == null) {
3698 continue;
3699 }
3700
Joe Onorato9c1289c2009-08-17 11:03:03 -04003701 switch (item.itemType) {
3702 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3703 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003704 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003705 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003706
Winson Chung64359a52013-07-08 17:17:08 -07003707 /*
3708 * TODO: FIX collision case
3709 */
Winson Chungce376632013-07-11 16:12:41 -07003710 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3711 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3712 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3713 throw new RuntimeException("OCCUPIED");
3714 }
Winson Chung64359a52013-07-08 17:17:08 -07003715 }
3716
Adam Cohendcd297f2013-06-18 13:13:40 -07003717 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3718 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003719 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003720 // Animate all the applications up now
3721 shortcut.setAlpha(0f);
3722 shortcut.setScaleX(0f);
3723 shortcut.setScaleY(0f);
3724 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003725 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003726 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003727 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003728 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003729 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003730 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003731 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003732 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3733 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003734 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003735 default:
3736 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003737 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003738 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003739
Winson Chung997a9232013-07-24 15:33:46 -07003740 if (animateIcons) {
3741 // Animate to the correct page
3742 if (newShortcutsScreenId > -1) {
3743 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3744 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3745 if (newShortcutsScreenId != currentScreenId) {
3746 mWorkspace.snapToPage(newScreenIndex);
3747 }
3748 }
3749
Winson Chung64359a52013-07-08 17:17:08 -07003750 // We post the animation slightly delayed to prevent slowdowns when we are loading
3751 // right after we return to launcher.
3752 mWorkspace.postDelayed(new Runnable() {
3753 public void run() {
3754 anim.playTogether(bounceAnims);
3755 anim.start();
3756 }
3757 }, NEW_APPS_ANIMATION_DELAY);
3758 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003759 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003760 }
3761
Joe Onorato9c1289c2009-08-17 11:03:03 -04003762 /**
3763 * Implementation of the method from LauncherModel.Callbacks.
3764 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003765 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003766 Runnable r = new Runnable() {
3767 public void run() {
3768 bindFolders(folders);
3769 }
3770 };
3771 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003772 return;
3773 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003774 sFolders.clear();
3775 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003776 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003777
3778 /**
3779 * Add the views for a widget to the workspace.
3780 *
3781 * Implementation of the method from LauncherModel.Callbacks.
3782 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003783 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003784 Runnable r = new Runnable() {
3785 public void run() {
3786 bindAppWidget(item);
3787 }
3788 };
3789 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003790 return;
3791 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003792
Daniel Sandler843e8602010-06-07 14:59:01 -04003793 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3794 if (DEBUG_WIDGETS) {
3795 Log.d(TAG, "bindAppWidget: " + item);
3796 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 final Workspace workspace = mWorkspace;
3798
3799 final int appWidgetId = item.appWidgetId;
3800 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003801 if (DEBUG_WIDGETS) {
3802 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3803 }
3804
Joe Onorato9c1289c2009-08-17 11:03:03 -04003805 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3806
Joe Onorato9c1289c2009-08-17 11:03:03 -04003807 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003808 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003809
Adam Cohendcd297f2013-06-18 13:13:40 -07003810 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003811 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003812 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3813
Joe Onorato9c1289c2009-08-17 11:03:03 -04003814 workspace.requestLayout();
3815
Daniel Sandler843e8602010-06-07 14:59:01 -04003816 if (DEBUG_WIDGETS) {
3817 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3818 + (SystemClock.uptimeMillis()-start) + "ms");
3819 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003820 }
3821
Adam Cohen1462de32012-07-24 22:34:36 -07003822 public void onPageBoundSynchronously(int page) {
3823 mSynchronouslyBoundPages.add(page);
3824 }
3825
Joe Onorato9c1289c2009-08-17 11:03:03 -04003826 /**
3827 * Callback saying that there aren't any more items to bind.
3828 *
3829 * Implementation of the method from LauncherModel.Callbacks.
3830 */
Adam Cohene25af792013-06-06 23:08:25 -07003831 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003832 Runnable r = new Runnable() {
3833 public void run() {
3834 finishBindingItems(upgradePath);
3835 }
3836 };
3837 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003838 return;
3839 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003840 if (mSavedState != null) {
3841 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003842 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003843 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003844 mSavedState = null;
3845 }
3846
Adam Cohen1462de32012-07-24 22:34:36 -07003847 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003848
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003849 // If we received the result of any pending adds while the loader was running (e.g. the
3850 // widget configuration forced an orientation change), process them now.
3851 for (int i = 0; i < sPendingAddList.size(); i++) {
3852 completeAdd(sPendingAddList.get(i));
3853 }
3854 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003855
Winson Chungc51db6a2011-10-05 11:44:49 -07003856 // Update the market app icon as necessary (the other icons will be managed in response to
3857 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003858 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003859
Winson Chungf0c6ae02012-03-21 16:10:31 -07003860 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003861 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003862 mWorkspace.getUniqueComponents(true, null);
3863 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003864 }
Adam Cohen99894d92013-06-14 11:22:59 -07003865
Adam Cohen66a01fd2013-06-11 12:48:00 -07003866 mWorkspace.post(new Runnable() {
3867 @Override
3868 public void run() {
3869 onFinishBindingItems();
3870 }
3871 });
Adam Cohen4caf2982013-08-20 18:54:31 -07003872
3873 // Write all the logs to disk
3874 Launcher.addDumpLog(TAG, "10249126 - finishBindingItems() - dumping logs to disk", true);
3875 dumpLogsToLocalData(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003876 }
3877
Winson Chunga2413752012-04-03 14:22:34 -07003878 private boolean canRunNewAppsAnimation() {
3879 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3880 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3881 }
3882
Winson Chungc9168342013-06-26 14:54:55 -07003883 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3884 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3885 PropertyValuesHolder.ofFloat("alpha", 1f),
3886 PropertyValuesHolder.ofFloat("scaleX", 1f),
3887 PropertyValuesHolder.ofFloat("scaleY", 1f));
3888 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3889 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3890 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3891 return bounceAnim;
3892 }
3893
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003894 @Override
3895 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003896 boolean searchVisible = updateGlobalSearchIcon();
3897 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003898 if (mSearchDropTargetBar != null) {
3899 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3900 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003901 }
3902
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003903 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003904 * Add the icons for all apps.
3905 *
3906 * Implementation of the method from LauncherModel.Callbacks.
3907 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003908 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003909 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3910 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3911 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3912 getHotseat().addAllAppsFolder(mIconCache, apps,
3913 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3914 }
3915 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003916 }
Winson Chungc58497e2013-09-03 17:48:37 -07003917 } else {
3918 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3919 mAppsCustomizeContent != null) {
3920 mAppsCustomizeContent.setApps(apps);
3921 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003922 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003923 }
3924
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003925 @Override
3926 public boolean shouldShowApp(ResolveInfo app) {
3927 return true;
3928 }
3929
Joe Onorato9c1289c2009-08-17 11:03:03 -04003930 /**
3931 * A package was updated.
3932 *
3933 * Implementation of the method from LauncherModel.Callbacks.
3934 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003935 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003936 Runnable r = new Runnable() {
3937 public void run() {
3938 bindAppsUpdated(apps);
3939 }
3940 };
3941 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003942 return;
3943 }
3944
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003945 if (mWorkspace != null) {
3946 mWorkspace.updateShortcuts(apps);
3947 }
Winson Chungc58497e2013-09-03 17:48:37 -07003948
3949 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3950 mAppsCustomizeContent != null) {
3951 mAppsCustomizeContent.updateApps(apps);
3952 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003953 }
3954
3955 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003956 * A package was uninstalled. We take both the super set of packageNames
3957 * in addition to specific applications to remove, the reason being that
3958 * this can be called when a package is updated as well. In that scenario,
3959 * we only remove specific components from the workspace, where as
3960 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003961 *
3962 * Implementation of the method from LauncherModel.Callbacks.
3963 */
Winson Chung83892cc2013-05-01 16:53:33 -07003964 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003965 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003966 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003967 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003968 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003969 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003970 }
Winson Chungd64d1762013-08-20 14:37:16 -07003971 };
3972 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003973 return;
3974 }
3975
Winson Chung64359a52013-07-08 17:17:08 -07003976 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003977 mWorkspace.removeItemsByPackageName(packageNames);
3978 } else {
3979 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003980 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003981
Winson Chunga1820962011-10-03 16:31:06 -07003982 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003983 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003984
3985 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3986 mAppsCustomizeContent != null) {
3987 mAppsCustomizeContent.removeApps(appInfos);
3988 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003989 }
Joe Onoratobe386092009-11-17 17:32:16 -08003990
3991 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003992 * A number of packages were updated.
3993 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003994 private ArrayList<Object> mWidgetsAndShortcuts;
3995 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003996 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003997 bindPackagesUpdated(mWidgetsAndShortcuts);
3998 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003999 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004000 };
4001
4002 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4003 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4004 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004005 return;
4006 }
4007
Winson Chung64359a52013-07-08 17:17:08 -07004008 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004009 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4010 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004011 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004012 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004013 }
4014
Winson Chung400438b2011-01-16 17:53:48 -08004015 private int mapConfigurationOriActivityInfoOri(int configOri) {
4016 final Display d = getWindowManager().getDefaultDisplay();
4017 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4018 switch (d.getRotation()) {
4019 case Surface.ROTATION_0:
4020 case Surface.ROTATION_180:
4021 // We are currently in the same basic orientation as the natural orientation
4022 naturalOri = configOri;
4023 break;
4024 case Surface.ROTATION_90:
4025 case Surface.ROTATION_270:
4026 // We are currently in the other basic orientation to the natural orientation
4027 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4028 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4029 break;
4030 }
4031
4032 int[] oriMap = {
4033 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4034 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4035 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4036 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4037 };
4038 // Since the map starts at portrait, we need to offset if this device's natural orientation
4039 // is landscape.
4040 int indexOffset = 0;
4041 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4042 indexOffset = 1;
4043 }
4044 return oriMap[(d.getRotation() + indexOffset) % 4];
4045 }
Adam Cohen446e9402011-09-15 18:21:21 -07004046
Winson Chung4b919f82012-05-01 10:44:08 -07004047 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004048 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004049 getResources().getBoolean(R.bool.allow_rotation);
4050 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004051 }
Winson Chung4b919f82012-05-01 10:44:08 -07004052 public void lockScreenOrientation() {
4053 if (isRotationEnabled()) {
4054 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4055 .getConfiguration().orientation));
4056 }
4057 }
4058 public void unlockScreenOrientation(boolean immediate) {
4059 if (isRotationEnabled()) {
4060 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004061 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004062 } else {
4063 mHandler.postDelayed(new Runnable() {
4064 public void run() {
4065 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4066 }
4067 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004068 }
Winson Chung4b919f82012-05-01 10:44:08 -07004069 }
Winson Chung400438b2011-01-16 17:53:48 -08004070 }
4071
Winson Chung82f55532011-08-09 14:14:23 -07004072 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004073 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004074 if (DISABLE_CLINGS) {
4075 return false;
4076 }
4077
Brett Chabot2a9e2282011-08-23 15:03:13 -07004078 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004079 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004080
Michael Jurkae233a8b2013-03-19 13:49:20 +01004081 // Restricted secondary users (child mode) will potentially have very few apps
4082 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004083// boolean supportsLimitedUsers =
4084// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4085// Account[] accounts = AccountManager.get(this).getAccounts();
4086// if (supportsLimitedUsers && accounts.length == 0) {
4087// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4088// Bundle restrictions = um.getUserRestrictions();
4089// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4090// return false;
4091// }
4092// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004093 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004094 }
Michael Jurka22143132012-10-04 17:42:38 +02004095
Winson Chung7d7541e2011-09-16 20:14:36 -07004096 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02004097 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004098 if (cling != null) {
4099 cling.init(this, positionData);
4100 cling.setVisibility(View.VISIBLE);
4101 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
4102 if (animate) {
4103 cling.buildLayer();
4104 cling.setAlpha(0f);
4105 cling.animate()
4106 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07004107 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07004108 .setDuration(SHOW_CLING_DURATION)
4109 .setStartDelay(delay)
4110 .start();
4111 } else {
4112 cling.setAlpha(1f);
4113 }
Michael Jurka22143132012-10-04 17:42:38 +02004114 cling.setFocusableInTouchMode(true);
4115 cling.post(new Runnable() {
4116 public void run() {
4117 cling.setFocusable(true);
4118 cling.requestFocus();
4119 }
4120 });
4121 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
4122 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004123 }
4124 return cling;
4125 }
Michael Jurka22143132012-10-04 17:42:38 +02004126
Winson Chung7d7541e2011-09-16 20:14:36 -07004127 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08004128 // To catch cases where siblings of top-level views are made invisible, just check whether
4129 // the cling is directly set to GONE before dismissing it.
4130 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07004131 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07004132 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07004133 anim.addListener(new AnimatorListenerAdapter() {
4134 public void onAnimationEnd(Animator animation) {
4135 cling.setVisibility(View.GONE);
4136 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004137 // We should update the shared preferences on a background thread
4138 new Thread("dismissClingThread") {
4139 public void run() {
4140 SharedPreferences.Editor editor = mSharedPrefs.edit();
4141 editor.putBoolean(flag, true);
4142 editor.commit();
4143 }
4144 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07004145 };
4146 });
4147 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02004148 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07004149 }
4150 }
Michael Jurka22143132012-10-04 17:42:38 +02004151
Winson Chung9d9d74f2011-09-19 11:49:12 -07004152 private void removeCling(int id) {
4153 final View cling = findViewById(id);
4154 if (cling != null) {
4155 final ViewGroup parent = (ViewGroup) cling.getParent();
4156 parent.post(new Runnable() {
4157 @Override
4158 public void run() {
4159 parent.removeView(cling);
4160 }
4161 });
Michael Jurka22143132012-10-04 17:42:38 +02004162 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004163 }
4164 }
Michael Jurka974c3862012-05-22 22:00:31 -07004165
4166 private boolean skipCustomClingIfNoAccounts() {
4167 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4168 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4169 if (customCling) {
4170 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004171 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004172 Account[] accounts = am.getAccountsByType("com.google");
4173 return accounts.length == 0;
4174 }
4175 return false;
4176 }
4177
Winson Chung7d7541e2011-09-16 20:14:36 -07004178 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004179 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004180 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07004181 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
4182 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004183 // If we're not using the default workspace layout, replace workspace cling
4184 // with a custom workspace cling (usually specified in an overlay)
4185 // For now, only do this on tablets
4186 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02004187 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02004188 // Use a custom cling
4189 View cling = findViewById(R.id.workspace_cling);
4190 ViewGroup clingParent = (ViewGroup) cling.getParent();
4191 int clingIndex = clingParent.indexOfChild(cling);
4192 clingParent.removeViewAt(clingIndex);
4193 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4194 clingParent.addView(customCling, clingIndex);
4195 customCling.setId(R.id.workspace_cling);
4196 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004197 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004198 } else {
4199 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004200 }
4201 }
4202 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004203 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004204 if (isClingsEnabled() &&
4205 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004206 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004207 } else {
4208 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004209 }
4210 }
4211 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004212 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004213 if (isClingsEnabled() &&
4214 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4215 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004216 } else {
4217 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004218 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004219 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004220 }
Michael Jurka104c4562013-07-08 18:03:46 -07004221 protected SharedPreferences getSharedPrefs() {
4222 return mSharedPrefs;
4223 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004224 public boolean isFolderClingVisible() {
4225 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004226 if (cling != null) {
4227 return cling.getVisibility() == View.VISIBLE;
4228 }
4229 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004230 }
Winson Chung82f55532011-08-09 14:14:23 -07004231 public void dismissWorkspaceCling(View v) {
4232 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004233 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004234 }
4235 public void dismissAllAppsCling(View v) {
4236 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004237 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4238 }
4239 public void dismissFolderCling(View v) {
4240 Cling cling = (Cling) findViewById(R.id.folder_cling);
4241 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004242 }
4243
Winson Chung80baf5a2010-08-09 16:03:15 -07004244 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004245 * Prints out out state for debugging.
4246 */
4247 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004248 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004249 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004250 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4251 Log.d(TAG, "mRestoring=" + mRestoring);
4252 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4253 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004254 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004255 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004256
Winson Chung785d2eb2011-04-14 16:08:02 -07004257 if (mAppsCustomizeContent != null) {
4258 mAppsCustomizeContent.dumpState();
4259 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004260 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004261 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004262
4263 @Override
4264 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4265 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004266 synchronized (sDumpLogs) {
4267 writer.println(" ");
4268 writer.println("Debug logs: ");
4269 for (int i = 0; i < sDumpLogs.size(); i++) {
4270 writer.println(" " + sDumpLogs.get(i));
4271 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004272 }
4273 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004274
4275 public static void dumpDebugLogsToConsole() {
Adam Cohen4caf2982013-08-20 18:54:31 -07004276 synchronized (sDumpLogs) {
4277 Log.d(TAG, "");
4278 Log.d(TAG, "*********************");
4279 Log.d(TAG, "Launcher debug logs: ");
4280 for (int i = 0; i < sDumpLogs.size(); i++) {
4281 Log.d(TAG, " " + sDumpLogs.get(i));
4282 }
4283 Log.d(TAG, "*********************");
4284 Log.d(TAG, "");
Adam Cohen487f7dd2012-06-28 18:12:10 -07004285 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004286 }
4287
4288 public static void addDumpLog(String tag, String log, boolean debugLog) {
4289 if (debugLog) {
4290 Log.d(tag, log);
4291 }
4292 sDateStamp.setTime(System.currentTimeMillis());
4293 synchronized (sDumpLogs) {
4294 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
4295 }
4296 }
4297
4298 public void dumpLogsToLocalData(final boolean email) {
4299 new Thread("DumpLogsToLocalData") {
4300 @Override
4301 public void run() {
4302 boolean success = false;
4303 sDateStamp.setTime(sRunStart);
4304 String FILENAME = sDateStamp.getMonth() + "-"
4305 + sDateStamp.getDay() + "_"
4306 + sDateStamp.getHours() + "-"
4307 + sDateStamp.getMinutes() + "_"
4308 + sDateStamp.getSeconds() + ".txt";
4309
4310 FileOutputStream fos = null;
4311 File outFile = null;
4312 try {
4313 outFile = new File(getFilesDir(), FILENAME);
4314 outFile.createNewFile();
4315 fos = new FileOutputStream(outFile);
4316 } catch (Exception e) {
4317 e.printStackTrace();
4318 }
4319 if (fos != null) {
4320 PrintWriter writer = new PrintWriter(fos);
4321
4322 writer.println(" ");
4323 writer.println("Debug logs: ");
4324 synchronized (sDumpLogs) {
4325 for (int i = 0; i < sDumpLogs.size(); i++) {
4326 writer.println(" " + sDumpLogs.get(i));
4327 }
4328 }
4329 writer.close();
4330 }
4331 try {
4332 if (fos != null) {
4333 fos.close();
4334 success = true;
4335 }
4336 } catch (IOException e) {
4337 e.printStackTrace();
4338 }
4339
4340 if (success && email) {
4341 if (!emailSent()) {
4342 emailFile(outFile);
4343 }
4344 }
4345 }
4346 }.start();
4347 }
4348
4349 private void emailFile(File file) {
4350 File publicCopy = new File(Environment.getExternalStorageDirectory(), file.getName());
4351 try {
4352 copyFile(file, publicCopy);
4353 } catch (IOException e) {
4354 e.printStackTrace();
4355 return;
4356 }
4357
4358 Intent intent = new Intent(Intent.ACTION_SEND);
4359 intent.setType("text/plain");
4360 intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"adamcohen@google.com, winsonc@google.com," +
4361 "mikejurka@google"});
4362 intent.putExtra(Intent.EXTRA_SUBJECT, "Data corruption " + file.getName());
4363 intent.putExtra(Intent.EXTRA_TEXT, "Data corruption has occurred, logs attached");
4364
4365 if (!file.exists() || !file.canRead()) {
4366 Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
4367 finish();
4368 return;
4369 }
4370
4371 Toast.makeText(this, "Data corruption has occurred, please send e-mail", Toast.LENGTH_LONG);
4372 Uri uri = Uri.fromFile(publicCopy);
4373 intent.putExtra(Intent.EXTRA_STREAM, uri);
4374 startActivity(Intent.createChooser(intent, "Please send logs, consider clearing data"));
4375
4376 setEmailSent(true);
4377 }
4378
4379 public void copyFile(File src, File dst) throws IOException {
4380 InputStream in = new FileInputStream(src);
4381 OutputStream out = new FileOutputStream(dst);
4382
4383 // Transfer bytes from in to out
4384 byte[] buf = new byte[1024];
4385 int len;
4386 while ((len = in.read(buf)) > 0) {
4387 out.write(buf, 0, len);
4388 }
4389 in.close();
4390 out.close();
Adam Cohen487f7dd2012-06-28 18:12:10 -07004391 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004392}
Michael Jurka2763be32011-02-24 11:19:57 -08004393
Michael Jurkaabded662011-03-04 12:06:57 -08004394interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004395 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004396 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004397 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004398 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004399 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004400}