blob: fbc68198f5c35fb58d10a8379c6ba19a1f483f77 [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;
80import android.view.MenuItem;
81import android.view.MotionEvent;
82import android.view.Surface;
83import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070084import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewGroup;
87import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080088import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080090import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070091import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070092import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080093import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070095import android.widget.Advanceable;
96import android.widget.FrameLayout;
97import android.widget.ImageView;
98import android.widget.TextView;
99import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700100
Daniel Sandler325dc232013-06-05 22:57:57 -0400101import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800102
Adam Cohenc0dcf592011-06-01 15:30:43 -0700103import java.io.DataInputStream;
104import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700105import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700106import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700107import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700108import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700109import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700111import java.io.InputStream;
112import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700113import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700114import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700116import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700117import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700118import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700119import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700120
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121/**
122 * Default launcher application.
123 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100124public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700125 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700126 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800127 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700128 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129
Daniel Sandlerf061f822013-06-27 13:59:36 -0400130 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400131 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700132 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400133 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700134
Winson Chung70d72102011-08-12 11:24:35 -0700135 private static final int MENU_GROUP_WALLPAPER = 1;
136 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
137 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700138 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
139 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
141 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700142 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143 private static final int REQUEST_PICK_APPLICATION = 6;
144 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700145 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700146 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Michael Jurka8b805b12012-04-18 14:23:14 -0700148 private static final int REQUEST_BIND_APPWIDGET = 11;
149
Mathew Inwood876a8462013-06-14 14:12:41 +0100150 /**
151 * IntentStarter uses request codes starting with this. This must be greater than all activity
152 * request codes used internally.
153 */
154 protected static final int REQUEST_LAST = 100;
155
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
157
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800158 static final int SCREEN_COUNT = 5;
159 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Romain Guy98d01652009-06-30 16:21:04 -0700161 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800162 // To turn on these properties, type
163 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
164 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
165 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Winson Chung2672ff92012-05-04 16:22:30 -0700167 // The Intent extra that defines whether to ignore the launch animation
168 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400169 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700170
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: int
172 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700173 // Type: int
174 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
177 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
179 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700180 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700182 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 // Type: boolean
184 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
185 // Type: long
186 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700187 // Type: int
188 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
189 // Type: int
190 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
191 // Type: parcelable
192 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100194 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700195 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100196 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700197 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100198 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700199
Adam Cohen39a06042013-07-19 14:30:12 -0700200 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700201 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700202
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700203 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700204 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700205 private State mState = State.WORKSPACE;
206 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207
Joe Onorato9c1289c2009-08-17 11:03:03 -0400208 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700209 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
210 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700211 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700212 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800215 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
Winson Chunga2413752012-04-03 14:22:34 -0700217 // How long to wait before the new-shortcut animation automatically pans the workspace
218 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700219 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700220
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800221 private final BroadcastReceiver mCloseSystemDialogsReceiver
222 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800223 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
224
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225 private LayoutInflater mInflater;
226
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700228 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800229 private DragLayer mDragLayer;
230 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700231 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700232
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700233 private AppWidgetManager mAppWidgetManager;
234 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700235
Michael Jurkac9d95c52011-08-29 14:03:34 -0700236 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700237 private AppWidgetProviderInfo mPendingAddWidgetInfo;
238
Michael Jurka0280c3b2010-09-17 15:00:07 -0700239 private int[] mTmpAddItemCellCoordinates = new int[2];
240
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241 private FolderInfo mFolderInfo;
242
Winson Chung3d503fb2011-07-13 17:25:49 -0700243 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700244 private View mOverviewPanel;
245
Michael Jurka838a4ca2011-02-07 13:33:06 -0800246 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700247
Winson Chungc51db6a2011-10-05 11:44:49 -0700248 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700249 private AppsCustomizeTabHost mAppsCustomizeTabHost;
250 private AppsCustomizePagedView mAppsCustomizeContent;
251 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100252 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700255 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
256 // scroll issues (because the workspace may not have been measured yet) and extra work.
257 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
258 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259
260 private SpannableStringBuilder mDefaultKeySsb = null;
261
Joe Onorato9c1289c2009-08-17 11:03:03 -0400262 private boolean mWorkspaceLoading = true;
263
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800264 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 private boolean mRestoring;
266 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700267 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268
Michael Jurka1e2f4652013-07-08 18:03:46 -0700269 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700270 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
271
Winson Chung4a2afa32012-07-19 14:53:05 -0700272 // Keep track of whether the user has left launcher
273 private static boolean sPausedFromUserAction = false;
274
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 private Bundle mSavedInstanceState;
276
Joe Onorato9c1289c2009-08-17 11:03:03 -0400277 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800278 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800279 private boolean mUserPresent = true;
280 private boolean mVisible = false;
281 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700282 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400283
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700284 private static LocaleConfiguration sLocaleConfiguration = null;
285
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700286 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700287
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700288 private Intent mAppMarketIntent = null;
289
Adam Cohended9f8d2010-11-03 13:25:16 -0700290 // Related to the auto-advancing of widgets
291 private final int ADVANCE_MSG = 1;
292 private final int mAdvanceInterval = 20000;
293 private final int mAdvanceStagger = 250;
294 private long mAutoAdvanceSentTime;
295 private long mAutoAdvanceTimeLeft = -1;
296 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
297 new HashMap<View, AppWidgetProviderInfo>();
298
Winson Chung400438b2011-01-16 17:53:48 -0800299 // Determines how long to wait after a rotation before restoring the screen orientation to
300 // match the sensor state.
301 private final int mRestoreScreenOrientationDelay = 500;
302
Michael Jurka4ef207b2010-11-29 17:05:45 -0800303 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700304 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
305 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
306 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800307
Craig Mautner360310b2012-10-26 15:13:08 -0700308 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700309
Adam Cohen1462de32012-07-24 22:34:36 -0700310 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
311
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700312 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700313 static Date sDateStamp = new Date();
314 static DateFormat sDateFormat =
315 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
316 static long sRunStart = System.currentTimeMillis();
317 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700318
Winson Chung46353de2012-02-16 14:05:10 -0800319 // We only want to get the SharedPreferences once since it does an FS stat each time we get
320 // it from the context.
321 private SharedPreferences mSharedPrefs;
322
Adam Cohene25af792013-06-06 23:08:25 -0700323 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
324
Winson Chungf0c6ae02012-03-21 16:10:31 -0700325 // Holds the page that we need to animate to, and the icon views that we need to animate up
326 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700327 private ImageView mFolderIconImageView;
328 private Bitmap mFolderIconBitmap;
329 private Canvas mFolderIconCanvas;
330 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700331
Michael Jurkaddd62e92011-02-16 17:49:14 -0800332 private BubbleTextView mWaitingForResume;
333
Michael Jurka22143132012-10-04 17:42:38 +0200334 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
335 = new HideFromAccessibilityHelper();
336
Michael Jurkac1f5d262011-09-30 19:32:27 -0700337 private Runnable mBuildLayersRunnable = new Runnable() {
338 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700339 if (mWorkspace != null) {
340 mWorkspace.buildPageHardwareLayers();
341 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700342 }
343 };
344
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800345 private static ArrayList<PendingAddArguments> sPendingAddList
346 = new ArrayList<PendingAddArguments>();
347
Michael Jurka0a457bf2012-11-19 14:05:05 -0800348 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
349
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800350 private static class PendingAddArguments {
351 int requestCode;
352 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700353 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700354 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800355 int cellX;
356 int cellY;
357 }
358
Daniel Sandlerff02d492013-08-05 02:12:05 -0400359 private Stats mStats;
360
Michael Jurka0a457bf2012-11-19 14:05:05 -0800361 private static boolean isPropertyEnabled(String propertyName) {
362 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700363 }
364
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365 @Override
366 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700367 if (DEBUG_STRICT_MODE) {
368 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
369 .detectDiskReads()
370 .detectDiskWrites()
371 .detectNetwork() // or .detectAll() for all detectable problems
372 .penaltyLog()
373 .build());
374 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
375 .detectLeakedSqlLiteObjects()
376 .detectLeakedClosableObjects()
377 .penaltyLog()
378 .penaltyDeath()
379 .build());
380 }
381
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400383
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400384 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400385 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700386
387 // Determine the dynamic grid properties
388 Point smallestSize = new Point();
389 Point largestSize = new Point();
390 Point realSize = new Point();
391 Display display = getWindowManager().getDefaultDisplay();
392 display.getCurrentSizeRange(smallestSize, largestSize);
393 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700394 DisplayMetrics dm = new DisplayMetrics();
395 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700396 // Lazy-initialize the dynamic grid
397 DeviceProfile grid = app.initDynamicGrid(this,
398 Math.min(smallestSize.x, smallestSize.y),
399 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700400 realSize.x, realSize.y,
401 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700402
403 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400404 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700405 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800406 mModel = app.setLauncher(this);
407 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400408 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800409 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700410
Daniel Sandlerff02d492013-08-05 02:12:05 -0400411 mStats = new Stats(this);
412
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700413 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700414 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
415 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700416
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700417 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
418 // this also ensures that any synchronous binding below doesn't re-trigger another
419 // LauncherModel load.
420 mPaused = false;
421
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200423 android.os.Debug.startMethodTracing(
424 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 }
426
427 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 setContentView(R.layout.launcher);
429 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100430 grid.layout(this);
Winson Chung7d7541e2011-09-16 20:14:36 -0700431 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800433 registerContentObservers();
434
Joe Onorato7c312c12009-08-13 21:36:53 -0700435 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700436
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 mSavedState = savedInstanceState;
438 restoreState(mSavedState);
439
Winson Chunga12a2502010-12-20 14:41:35 -0800440 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700441 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200442 mAppsCustomizeContent.onPackagesUpdated(
443 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700444 }
Winson Chunga12a2502010-12-20 14:41:35 -0800445
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446 if (PROFILE_STARTUP) {
447 android.os.Debug.stopMethodTracing();
448 }
449
450 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700451 if (sPausedFromUserAction) {
452 // If the user leaves launcher, then we should just load items asynchronously when
453 // they return.
454 mModel.startLoader(true, -1);
455 } else {
456 // We only load the page synchronously if the user rotates (or triggers a
457 // configuration change) while launcher is in the foreground
458 mModel.startLoader(true, mWorkspace.getCurrentPage());
459 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 }
461
462 // For handling default keys
463 mDefaultKeySsb = new SpannableStringBuilder();
464 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800465
466 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
467 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800468
Adam Cohenf9426d52012-06-04 17:26:21 -0700469 updateGlobalIcons();
470
471 // On large interfaces, we want the screen to auto-rotate based on the current orientation
472 unlockScreenOrientation(true);
473 }
474
Winson Chung4a2afa32012-07-19 14:53:05 -0700475 protected void onUserLeaveHint() {
476 super.onUserLeaveHint();
477 sPausedFromUserAction = true;
478 }
479
Winson Chung98ca0f72013-07-29 12:58:51 -0700480 /** To be overriden by subclasses to hint to Launcher that we have custom content */
481 protected boolean hasCustomContentToLeft() {
482 return false;
483 }
484
Adam Cohenf9426d52012-06-04 17:26:21 -0700485 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700486 boolean searchVisible = false;
487 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800488 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700489 int coi = getCurrentOrientationIndexForGlobalIcons();
490 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
491 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700492 updateAppMarketIcon();
493 searchVisible = updateGlobalSearchIcon();
494 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700495 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700496 if (sGlobalSearchIcon[coi] != null) {
497 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700498 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700499 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700500 if (sVoiceSearchIcon[coi] != null) {
501 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700502 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700503 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700504 if (sAppMarketIcon[coi] != null) {
505 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800506 }
Winson Chungadf0c182012-08-23 14:59:07 -0700507 if (mSearchDropTargetBar != null) {
508 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
509 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800510 }
Romain Guycbb89e42009-06-08 15:52:54 -0700511
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800512 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700513 if (sLocaleConfiguration == null) {
514 new AsyncTask<Void, Void, LocaleConfiguration>() {
515 @Override
516 protected LocaleConfiguration doInBackground(Void... unused) {
517 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
518 readConfiguration(Launcher.this, localeConfiguration);
519 return localeConfiguration;
520 }
521
522 @Override
523 protected void onPostExecute(LocaleConfiguration result) {
524 sLocaleConfiguration = result;
525 checkForLocaleChange(); // recursive, but now with a locale configuration
526 }
527 }.execute();
528 return;
529 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700530
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 final Configuration configuration = getResources().getConfiguration();
532
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700533 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800534 final String locale = configuration.locale.toString();
535
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700536 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800537 final int mcc = configuration.mcc;
538
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700539 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800540 final int mnc = configuration.mnc;
541
Romain Guy84f296c2009-11-04 15:00:44 -0800542 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800543
Romain Guy84f296c2009-11-04 15:00:44 -0800544 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700545 sLocaleConfiguration.locale = locale;
546 sLocaleConfiguration.mcc = mcc;
547 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700548
Joe Onorato0589f0f2010-02-08 13:44:00 -0800549 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700550
551 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
552 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700553 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700554 public void run() {
555 writeConfiguration(Launcher.this, localeConfiguration);
556 }
557 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700558 }
559 }
560
561 private static class LocaleConfiguration {
562 public String locale;
563 public int mcc = -1;
564 public int mnc = -1;
565 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700566
Romain Guy98d01652009-06-30 16:21:04 -0700567 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
568 DataInputStream in = null;
569 try {
570 in = new DataInputStream(context.openFileInput(PREFERENCES));
571 configuration.locale = in.readUTF();
572 configuration.mcc = in.readInt();
573 configuration.mnc = in.readInt();
574 } catch (FileNotFoundException e) {
575 // Ignore
576 } catch (IOException e) {
577 // Ignore
578 } finally {
579 if (in != null) {
580 try {
581 in.close();
582 } catch (IOException e) {
583 // Ignore
584 }
585 }
586 }
587 }
588
589 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
590 DataOutputStream out = null;
591 try {
592 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
593 out.writeUTF(configuration.locale);
594 out.writeInt(configuration.mcc);
595 out.writeInt(configuration.mnc);
596 out.flush();
597 } catch (FileNotFoundException e) {
598 // Ignore
599 } catch (IOException e) {
600 //noinspection ResultOfMethodCallIgnored
601 context.getFileStreamPath(PREFERENCES).delete();
602 } finally {
603 if (out != null) {
604 try {
605 out.close();
606 } catch (IOException e) {
607 // Ignore
608 }
609 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800610 }
611 }
612
Bjorn Bringertc459e522013-06-07 19:36:01 +0100613 public LayoutInflater getInflater() {
614 return mInflater;
615 }
616
Adam Cohen716b51e2011-06-30 12:09:54 -0700617 public DragLayer getDragLayer() {
618 return mDragLayer;
619 }
620
Winson Chung36a62fe2012-05-06 18:04:42 -0700621 boolean isDraggingEnabled() {
622 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
623 // that is subsequently removed from the workspace in startBinding().
624 return !mModel.isLoadingWorkspace();
625 }
626
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800627 static int getScreen() {
628 synchronized (sLock) {
629 return sScreen;
630 }
631 }
632
633 static void setScreen(int screen) {
634 synchronized (sLock) {
635 sScreen = screen;
636 }
637 }
638
Winson Chung557d6ed2011-07-08 15:34:52 -0700639 /**
640 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
641 * a configuration step, this allows the proper animations to run after other transitions.
642 */
643 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700644 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800645 switch (args.requestCode) {
646 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700647 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700648 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800649 break;
650 case REQUEST_PICK_SHORTCUT:
651 processShortcut(args.intent);
652 break;
653 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700654 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700655 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700656 result = true;
657 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800658 case REQUEST_CREATE_APPWIDGET:
659 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700660 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700661 result = true;
662 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800663 case REQUEST_PICK_WALLPAPER:
664 // We just wanted the activity result here so we can clear mWaitingForResult
665 break;
666 }
Michael Jurka27614d22012-04-02 06:40:22 -0700667 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
668 // if you turned the screen off and then back while in All Apps, Launcher would not
669 // return to the workspace. Clearing mAddInfo.container here fixes this issue
670 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700671 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800672 }
673
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800674 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700675 protected void onActivityResult(
676 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700677 // Reset the startActivity waiting flag
678 mWaitingForResult = false;
679
Michael Jurka8b805b12012-04-18 14:23:14 -0700680 if (requestCode == REQUEST_BIND_APPWIDGET) {
681 int appWidgetId = data != null ?
682 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
683 if (resultCode == RESULT_CANCELED) {
684 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
685 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700686 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700687 }
688 return;
689 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700690 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800691 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
692 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700693
Adam Cohened66b2b2012-01-23 17:28:51 -0800694 // We have special handling for widgets
695 if (isWidgetDrop) {
696 int appWidgetId = data != null ?
697 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700698 if (appWidgetId < 0) {
699 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
700 "widget configuration activity.");
701 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
702 } else {
703 completeTwoStageWidgetDrop(resultCode, appWidgetId);
704 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800705 return;
706 }
707
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 // The pattern used here is that a user PICKs a specific application,
709 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700710
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
712 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700713 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800714 final PendingAddArguments args = new PendingAddArguments();
715 args.requestCode = requestCode;
716 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700717 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700718 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700719 args.cellX = mPendingAddInfo.cellX;
720 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800721 if (isWorkspaceLocked()) {
722 sPendingAddList.add(args);
723 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700724 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800726 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800727 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700728 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800729 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
730 null);
731 }
732
733 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700734 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700735 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800736 Runnable onCompleteRunnable = null;
737 int animationType = 0;
738
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700739 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800740 if (resultCode == RESULT_OK) {
741 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
742 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700743 mPendingAddWidgetInfo);
744 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800745 onCompleteRunnable = new Runnable() {
746 @Override
747 public void run() {
748 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700749 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800750 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
751 null);
752 }
753 };
754 } else if (resultCode == RESULT_CANCELED) {
755 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
756 onCompleteRunnable = new Runnable() {
757 @Override
758 public void run() {
759 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
760 null);
761 }
762 };
763 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700764 if (mDragLayer.getAnimatedView() != null) {
765 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
766 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
767 animationType, boundWidget, true);
768 } else {
769 // The animated view may be null in the case of a rotation during widget configuration
770 onCompleteRunnable.run();
771 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800772 }
773
774 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700775 protected void onStop() {
776 super.onStop();
777 FirstFrameAnimatorHelper.setIsVisible(false);
778 }
779
780 @Override
781 protected void onStart() {
782 super.onStart();
783 FirstFrameAnimatorHelper.setIsVisible(true);
784 }
785
786 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800787 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200788 long startTime = 0;
789 if (DEBUG_RESUME_TIME) {
790 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400791 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200792 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800793 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700794
Winson Chung4a2afa32012-07-19 14:53:05 -0700795 // Restore the previous launcher state
796 if (mOnResumeState == State.WORKSPACE) {
797 showWorkspace(false);
798 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700799 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700800 }
801 mOnResumeState = State.NONE;
802
Craig Mautner360310b2012-10-26 15:13:08 -0700803 // Background was set to gradient in onPause(), restore to black if in all apps.
804 setWorkspaceBackground(mState == State.WORKSPACE);
805
Winson Chungde0fb8f2012-05-08 14:37:08 -0700806 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700807 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700808
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800809 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700810 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700811 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400812 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700813 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400814 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700815 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700817 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200818 // We might have postponed some bind calls until onResume (see waitUntilResume) --
819 // execute them here
820 long startTimeCallbacks = 0;
821 if (DEBUG_RESUME_TIME) {
822 startTimeCallbacks = System.currentTimeMillis();
823 }
824
825 if (mAppsCustomizeContent != null) {
826 mAppsCustomizeContent.setBulkBind(true);
827 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700828 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
829 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200830 }
831 if (mAppsCustomizeContent != null) {
832 mAppsCustomizeContent.setBulkBind(false);
833 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700834 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200835 if (DEBUG_RESUME_TIME) {
836 Log.d(TAG, "Time spent processing callbacks in onResume: " +
837 (System.currentTimeMillis() - startTimeCallbacks));
838 }
Michael Jurka447bf842013-05-15 14:52:15 +0200839 }
Michael Jurka54554252013-08-01 12:52:23 +0200840 if (mOnResumeCallbacks.size() > 0) {
841 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
842 mOnResumeCallbacks.get(i).run();
843 }
844 mOnResumeCallbacks.clear();
845 }
Winson Chunge4e50662012-01-23 14:45:13 -0800846
847 // Reset the pressed state of icons that were locked in the press state while activities
848 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800849 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800850 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800851 mWaitingForResume.setStayPressed(false);
852 }
Winson Chunge4e50662012-01-23 14:45:13 -0800853 if (mAppsCustomizeContent != null) {
854 // Resets the previous all apps icon press state
855 mAppsCustomizeContent.resetDrawableState();
856 }
Adam Cohen06dff352012-06-01 17:17:08 -0700857 // It is possible that widgets can receive updates while launcher is not in the foreground.
858 // Consequently, the widgets will be inflated in the orientation of the foreground activity
859 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
860 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700861 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700862
863 // Again, as with the above scenario, it's possible that one or more of the global icons
864 // were updated in the wrong orientation.
865 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200866 if (DEBUG_RESUME_TIME) {
867 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
868 }
Adam Cohen4caf2982013-08-20 18:54:31 -0700869
870 // Write all the logs to disk
871 Launcher.addDumpLog(TAG, "10249126 - onResume() - dumping logs to disk", true);
872 dumpLogsToLocalData(false);
Adam Cohen06dff352012-06-01 17:17:08 -0700873 }
874
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800875 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700876 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700877 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
878 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
879 // when Launcher resumes and we are still in AllApps.
880 updateWallpaperVisibility(true);
881
Winson Chung997a9232013-07-24 15:33:46 -0700882 // Ensure that items added to Launcher are queued until Launcher returns
883 InstallShortcutReceiver.enableInstallQueue();
884
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700885 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700886 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800887 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700888 mDragController.resetLastGestureUpTime();
Adam Cohen4caf2982013-08-20 18:54:31 -0700889
890 // Write all the logs to disk
891 Launcher.addDumpLog(TAG, "10249126 - onPause() - dumping logs to disk", true);
892 dumpLogsToLocalData(false);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700893 }
Romain Guycbb89e42009-06-08 15:52:54 -0700894
Adam Cohen66a01fd2013-06-11 12:48:00 -0700895 protected void onFinishBindingItems() {
896 }
897
Adam Cohenbffe7452013-07-22 18:21:45 -0700898 QSBScroller mQsbScroller = new QSBScroller() {
899 int scrollY = 0;
900
901 @Override
902 public void setScrollY(int scroll) {
903 scrollY = scroll;
904
905 if (mWorkspace.isOnOrMovingToCustomContent()) {
906 mSearchDropTargetBar.setTranslationY(- scrollY);
907 }
908 }
909 };
910
911 public void resetQSBScroll() {
912 mSearchDropTargetBar.animate().translationY(0).start();
913 }
914
915 public interface CustomContentCallbacks {
916 // Custom content is completely shown
917 public void onShow();
918
919 // Custom content is completely hidden
920 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700921
922 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
923 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700924 }
925
Adam Cohen30bacb22013-08-29 14:25:25 -0700926 protected void startSettings() {
927 }
928
Adam Cohenbffe7452013-07-22 18:21:45 -0700929 public interface QSBScroller {
930 public void setScrollY(int scrollY);
931 }
932
Adam Cohen66a01fd2013-06-11 12:48:00 -0700933 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700934 public QSBScroller addToCustomContentPage(View customContent) {
935 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700936 }
937
Winson Chung98ca0f72013-07-29 12:58:51 -0700938 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700939 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700940 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700941 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700942 }
943
Adam Cohenedb40762013-07-18 16:45:45 -0700944 // The custom content needs to offset its content to account for the QSB
945 public int getTopOffsetForCustomContent() {
946 return mWorkspace.getPaddingTop();
947 }
948
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700949 @Override
950 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400951 // Flag the loader to stop early before switching
952 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700953 if (mAppsCustomizeContent != null) {
954 mAppsCustomizeContent.surrender();
955 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800956 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700957 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700958
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800959 // We can't hide the IME if it was forced open. So don't bother
960 /*
961 @Override
962 public void onWindowFocusChanged(boolean hasFocus) {
963 super.onWindowFocusChanged(hasFocus);
964
965 if (hasFocus) {
966 final InputMethodManager inputManager = (InputMethodManager)
967 getSystemService(Context.INPUT_METHOD_SERVICE);
968 WindowManager.LayoutParams lp = getWindow().getAttributes();
969 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
970 android.os.Handler()) {
971 protected void onReceiveResult(int resultCode, Bundle resultData) {
972 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
973 }
974 });
975 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
976 }
977 }
978 */
979
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980 private boolean acceptFilter() {
981 final InputMethodManager inputManager = (InputMethodManager)
982 getSystemService(Context.INPUT_METHOD_SERVICE);
983 return !inputManager.isFullscreenMode();
984 }
985
986 @Override
987 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700988 final int uniChar = event.getUnicodeChar();
989 final boolean handled = super.onKeyDown(keyCode, event);
990 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
991 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
993 keyCode, event);
994 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700995 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700996 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700997 // showSearchDialog()
998 // If there are multiple keystrokes before the search dialog takes focus,
999 // onSearchRequested() will be called for every keystroke,
1000 // but it is idempotent, so it's fine.
1001 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001002 }
1003 }
1004
Joe Onorato8a9625e2010-01-28 15:55:35 -08001005 // Eat the long press event so the keyboard doesn't come up.
1006 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1007 return true;
1008 }
1009
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 return handled;
1011 }
1012
Karl Rosaen138a0412009-04-23 19:00:21 -07001013 private String getTypedText() {
1014 return mDefaultKeySsb.toString();
1015 }
1016
1017 private void clearTypedText() {
1018 mDefaultKeySsb.clear();
1019 mDefaultKeySsb.clearSpans();
1020 Selection.setSelection(mDefaultKeySsb, 0);
1021 }
1022
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001024 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1025 * State
1026 */
1027 private static State intToState(int stateOrdinal) {
1028 State state = State.WORKSPACE;
1029 final State[] stateValues = State.values();
1030 for (int i = 0; i < stateValues.length; i++) {
1031 if (stateValues[i].ordinal() == stateOrdinal) {
1032 state = stateValues[i];
1033 break;
1034 }
1035 }
1036 return state;
1037 }
1038
1039 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 * Restores the previous state, if it exists.
1041 *
1042 * @param savedState The previous state.
1043 */
1044 private void restoreState(Bundle savedState) {
1045 if (savedState == null) {
1046 return;
1047 }
1048
Michael Jurka883f55b2010-10-21 15:47:14 -07001049 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001050 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001051 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001052 }
1053
Winson Chungf0c6ae02012-03-21 16:10:31 -07001054 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001056 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001057 }
1058
Winson Chung3d503fb2011-07-13 17:25:49 -07001059 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001060 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001061
Winson Chung3d503fb2011-07-13 17:25:49 -07001062 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1063 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001064 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001065 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1066 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001067 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1068 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1069 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001070 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 mRestoring = true;
1072 }
1073
1074 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1075 if (renameFolder) {
1076 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001077 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078 mRestoring = true;
1079 }
Winson Chunga12a2502010-12-20 14:41:35 -08001080
Winson Chung785d2eb2011-04-14 16:08:02 -07001081 // Restore the AppsCustomize tab
1082 if (mAppsCustomizeTabHost != null) {
1083 String curTab = savedState.getString("apps_customize_currentTab");
1084 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001085 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001086 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001087 mAppsCustomizeContent.loadAssociatedPages(
1088 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001089 }
1090
Winson Chung5afbf7b2011-07-25 11:53:08 -07001091 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1092 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001093 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 }
1095
1096 /**
1097 * Finds all the views we need and configure them properly.
1098 */
1099 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001100 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001101
Craig Mautner360310b2012-10-26 15:13:08 -07001102 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001103 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1104 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001105
John Spurlock77e1f472013-09-11 10:09:51 -04001106 mLauncherView.setSystemUiVisibility(
1107 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001108 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001109
Winson Chung4c98d922011-05-31 16:50:48 -07001110 // Setup the drag layer
1111 mDragLayer.setup(this, dragController);
1112
Winson Chung3d503fb2011-07-13 17:25:49 -07001113 // Setup the hotseat
1114 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1115 if (mHotseat != null) {
1116 mHotseat.setup(this);
1117 }
1118
Adam Cohenf358a4b2013-07-23 16:47:31 -07001119 mOverviewPanel = findViewById(R.id.overview_panel);
1120 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1121 @Override
1122 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001123 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001124 }
1125 });
1126 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1127 @Override
1128 public void onClick(View arg0) {
1129 startWallpaper();
1130 }
1131 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001132 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1133 @Override
1134 public void onClick(View arg0) {
1135 startSettings();
1136 }
1137 });
Adam Cohenf358a4b2013-07-23 16:47:31 -07001138
Winson Chung4c98d922011-05-31 16:50:48 -07001139 // Setup the workspace
1140 mWorkspace.setHapticFeedbackEnabled(false);
1141 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001142 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001143 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001144
Winson Chungf0ea4d32011-06-06 14:27:16 -07001145 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001146 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001147
Winson Chungf0ea4d32011-06-06 14:27:16 -07001148 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001149 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001150 mAppsCustomizeContent = (AppsCustomizePagedView)
1151 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1152 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001153
Winson Chung3d503fb2011-07-13 17:25:49 -07001154 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001155 dragController.setDragScoller(mWorkspace);
1156 dragController.setScrollView(mDragLayer);
1157 dragController.setMoveTarget(mWorkspace);
1158 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001159 if (mSearchDropTargetBar != null) {
1160 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001161 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001162
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001163 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001164 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001165 mWeightWatcher = new WeightWatcher(this);
1166 mWeightWatcher.setAlpha(0.5f);
1167 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001168 new FrameLayout.LayoutParams(
1169 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001170 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001171 Gravity.BOTTOM)
1172 );
Adam Cohen39a06042013-07-19 14:30:12 -07001173
1174 boolean show = shouldShowWeightWatcher();
1175 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001176 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 }
1178
1179 /**
1180 * Creates a view representing a shortcut.
1181 *
1182 * @param info The data structure describing the shortcut.
1183 *
1184 * @return A View inflated from R.layout.application.
1185 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001186 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001187 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001188 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001189 }
1190
1191 /**
1192 * Creates a view representing a shortcut inflated from the specified resource.
1193 *
1194 * @param layoutResId The id of the XML layout used to create the shortcut.
1195 * @param parent The group the shortcut belongs to.
1196 * @param info The data structure describing the shortcut.
1197 *
1198 * @return A View inflated from layoutResId.
1199 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001200 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001201 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1202 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001203 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001204 return favorite;
1205 }
1206
1207 /**
1208 * Add an application shortcut to the workspace.
1209 *
1210 * @param data The intent describing the application.
1211 * @param cellInfo The position on screen where to create the shortcut.
1212 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001213 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001214 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001215 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001216
Adam Cohenfbba09b2011-07-18 21:43:05 -07001217 // First we check if we already know the exact location where we want to add this item.
1218 if (cellX >= 0 && cellY >= 0) {
1219 cellXY[0] = cellX;
1220 cellXY[1] = cellY;
1221 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001222 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001223 return;
1224 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001226 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001227
Romain Guy73b979d2009-06-09 12:57:21 -07001228 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001229 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001231 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001232 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001233 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001234 } else {
1235 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236 }
1237 }
Romain Guycbb89e42009-06-08 15:52:54 -07001238
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 /**
1240 * Add a shortcut to the workspace.
1241 *
1242 * @param data The intent describing the shortcut.
1243 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001244 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001245 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001246 int cellY) {
1247 int[] cellXY = mTmpAddItemCellCoordinates;
1248 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001249 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001250
Michael Jurkad3ef3062010-11-23 16:23:58 -08001251 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001252
Adam Cohen558baaf2011-08-15 15:22:57 -07001253 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001254 if (info == null) {
1255 return;
1256 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001257 final View view = createShortcut(info);
1258
Adam Cohenfbba09b2011-07-18 21:43:05 -07001259 // First we check if we already know the exact location where we want to add this item.
1260 if (cellX >= 0 && cellY >= 0) {
1261 cellXY[0] = cellX;
1262 cellXY[1] = cellY;
1263 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001264
1265 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001266 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001267 true, null,null)) {
1268 return;
1269 }
1270 DragObject dragObject = new DragObject();
1271 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001272 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1273 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001274 return;
1275 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001276 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001277 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001278 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001279 foundCellSpan = (result != null);
1280 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001281 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001282 }
1283
1284 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001285 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001286 return;
1287 }
1288
Adam Cohendcd297f2013-06-18 13:13:40 -07001289 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290
1291 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001292 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001293 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001294 }
1295 }
1296
Adam Cohen2f093b62012-04-30 18:59:53 -07001297 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1298 int minHeight) {
1299 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001300 // We want to account for the extra amount of padding that we are adding to the widget
1301 // to ensure that it gets the full amount of space that it has requested
1302 int requiredWidth = minWidth + padding.left + padding.right;
1303 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001304 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001305 }
1306
Adam Cohen2f093b62012-04-30 18:59:53 -07001307 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1308 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001309 }
1310
Adam Cohen2f093b62012-04-30 18:59:53 -07001311 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1312 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001313 }
1314
Adam Cohen2f093b62012-04-30 18:59:53 -07001315 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1316 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001317 }
1318
Adam Cohen2f093b62012-04-30 18:59:53 -07001319 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1320 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001321 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001322 }
1323
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001325 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001327 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001328 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001330 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001331 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1332 if (appWidgetInfo == null) {
1333 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1334 }
Romain Guycbb89e42009-06-08 15:52:54 -07001335
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001336 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001337 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001338
Adam Cohen2f093b62012-04-30 18:59:53 -07001339 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1340 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001341
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001342 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001343 // We have saved the position to which the widget was dragged-- this really only matters
1344 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001345 int[] cellXY = mTmpAddItemCellCoordinates;
1346 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001347 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001348 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001349 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1350 cellXY[0] = mPendingAddInfo.cellX;
1351 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001352 spanXY[0] = mPendingAddInfo.spanX;
1353 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001354 foundCellSpan = true;
1355 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001356 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001357 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001358 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1359 spanXY[1], cellXY, finalSpan);
1360 spanXY[0] = finalSpan[0];
1361 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001362 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001363 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001364 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001365 }
1366
Michael Jurka0280c3b2010-09-17 15:00:07 -07001367 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001368 if (appWidgetId != -1) {
1369 // Deleting an app widget ID is a void call but writes to disk before returning
1370 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001371 new Thread("deleteAppWidgetId") {
1372 public void run() {
1373 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1374 }
1375 }.start();
1376 }
Winson Chung93eef082012-03-23 15:59:27 -07001377 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001378 return;
1379 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001381 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001382 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1383 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001384 launcherInfo.spanX = spanXY[0];
1385 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001386 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1387 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001388
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001390 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391
1392 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001393 if (hostView == null) {
1394 // Perform actual inflation because we're live
1395 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1396 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1397 } else {
1398 // The AppWidgetHostView has already been inflated and instantiated
1399 launcherInfo.hostView = hostView;
1400 }
Romain Guycbb89e42009-06-08 15:52:54 -07001401
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001402 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001403 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001404 launcherInfo.notifyWidgetSizeChanged(this);
1405
Adam Cohendcd297f2013-06-18 13:13:40 -07001406 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001407 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001408
1409 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001411 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 }
Romain Guycbb89e42009-06-08 15:52:54 -07001413
Adam Cohended9f8d2010-11-03 13:25:16 -07001414 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1415 @Override
1416 public void onReceive(Context context, Intent intent) {
1417 final String action = intent.getAction();
1418 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1419 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001420 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001421 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001422
Winson Chungc100e8e2011-08-09 16:02:43 -07001423 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001424 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001425 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1426 mAppsCustomizeTabHost.reset();
1427 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001428 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001429 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1430 mUserPresent = true;
1431 updateRunning();
1432 }
1433 }
1434 };
1435
1436 @Override
1437 public void onAttachedToWindow() {
1438 super.onAttachedToWindow();
1439
1440 // Listen for broadcasts related to user-presence
1441 final IntentFilter filter = new IntentFilter();
1442 filter.addAction(Intent.ACTION_SCREEN_OFF);
1443 filter.addAction(Intent.ACTION_USER_PRESENT);
1444 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001445 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001446 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001447 mVisible = true;
1448 }
1449
1450 @Override
1451 public void onDetachedFromWindow() {
1452 super.onDetachedFromWindow();
1453 mVisible = false;
1454
Adam Cohend113e0c2010-11-11 10:48:05 -08001455 if (mAttached) {
1456 unregisterReceiver(mReceiver);
1457 mAttached = false;
1458 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001459 updateRunning();
1460 }
1461
1462 public void onWindowVisibilityChanged(int visibility) {
1463 mVisible = visibility == View.VISIBLE;
1464 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001465 // The following code used to be in onResume, but it turns out onResume is called when
1466 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1467 // is a more appropriate event to handle
1468 if (mVisible) {
1469 mAppsCustomizeTabHost.onWindowVisible();
1470 if (!mWorkspaceLoading) {
1471 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001472 // We want to let Launcher draw itself at least once before we force it to build
1473 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001474 // apps is nice and speedy.
1475 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001476 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001477 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001478 if (mStarted) return;
1479 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001480 // We delay the layer building a bit in order to give
1481 // other message processing a time to run. In particular
1482 // this avoids a delay in hiding the IME if it was
1483 // currently shown, because doing that may involve
1484 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001485 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001486 final ViewTreeObserver.OnDrawListener listener = this;
1487 mWorkspace.post(new Runnable() {
1488 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001489 if (mWorkspace != null &&
1490 mWorkspace.getViewTreeObserver() != null) {
1491 mWorkspace.getViewTreeObserver().
1492 removeOnDrawListener(listener);
1493 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001494 }
1495 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001496 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001497 }
1498 });
1499 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001500 // When Launcher comes back to foreground, a different Activity might be responsible for
1501 // the app market intent, so refresh the icon
1502 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001503 clearTypedText();
1504 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001505 }
1506
1507 private void sendAdvanceMessage(long delay) {
1508 mHandler.removeMessages(ADVANCE_MSG);
1509 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1510 mHandler.sendMessageDelayed(msg, delay);
1511 mAutoAdvanceSentTime = System.currentTimeMillis();
1512 }
1513
1514 private void updateRunning() {
1515 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1516 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1517 mAutoAdvanceRunning = autoAdvanceRunning;
1518 if (autoAdvanceRunning) {
1519 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1520 sendAdvanceMessage(delay);
1521 } else {
1522 if (!mWidgetsToAdvance.isEmpty()) {
1523 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1524 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1525 }
1526 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001527 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001528 }
1529 }
1530 }
1531
1532 private final Handler mHandler = new Handler() {
1533 @Override
1534 public void handleMessage(Message msg) {
1535 if (msg.what == ADVANCE_MSG) {
1536 int i = 0;
1537 for (View key: mWidgetsToAdvance.keySet()) {
1538 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1539 final int delay = mAdvanceStagger * i;
1540 if (v instanceof Advanceable) {
1541 postDelayed(new Runnable() {
1542 public void run() {
1543 ((Advanceable) v).advance();
1544 }
1545 }, delay);
1546 }
1547 i++;
1548 }
1549 sendAdvanceMessage(mAdvanceInterval);
1550 }
1551 }
1552 };
1553
1554 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001555 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001556 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1557 if (v instanceof Advanceable) {
1558 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001559 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001560 updateRunning();
1561 }
1562 }
1563
1564 void removeWidgetToAutoAdvance(View hostView) {
1565 if (mWidgetsToAdvance.containsKey(hostView)) {
1566 mWidgetsToAdvance.remove(hostView);
1567 updateRunning();
1568 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001569 }
1570
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001572 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001573 launcherInfo.hostView = null;
1574 }
1575
Winson Chung93eef082012-03-23 15:59:27 -07001576 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1577 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1578 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001579 }
1580
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001581 public LauncherAppWidgetHost getAppWidgetHost() {
1582 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001583 }
Romain Guycbb89e42009-06-08 15:52:54 -07001584
Winson Chunga9abd0e2010-10-27 17:18:37 -07001585 public LauncherModel getModel() {
1586 return mModel;
1587 }
1588
Bjorn Bringertc459e522013-06-07 19:36:01 +01001589 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001590 getWindow().closeAllPanels();
1591
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001592 // Whatever we were doing is hereby canceled.
1593 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001594 }
1595
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 @Override
1597 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001598 long startTime = 0;
1599 if (DEBUG_RESUME_TIME) {
1600 startTime = System.currentTimeMillis();
1601 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 super.onNewIntent(intent);
1603
1604 // Close the menu
1605 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001606 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001607 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001608
Jamie Genniscb222e82012-10-23 15:44:26 -07001609 final boolean alreadyOnHome =
1610 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001611 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001612
Jamie Genniscb222e82012-10-23 15:44:26 -07001613 Runnable processIntent = new Runnable() {
1614 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001615 if (mWorkspace == null) {
1616 // Can be cases where mWorkspace is null, this prevents a NPE
1617 return;
1618 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001619 Folder openFolder = mWorkspace.getOpenFolder();
1620 // In all these cases, only animate if we're already on home
1621 mWorkspace.exitWidgetResizeMode();
1622 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1623 openFolder == null) {
1624 mWorkspace.moveToDefaultScreen(true);
1625 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001626
Jamie Genniscb222e82012-10-23 15:44:26 -07001627 closeFolder();
1628 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001629
Jamie Genniscb222e82012-10-23 15:44:26 -07001630 // If we are already on home, then just animate back to the workspace,
1631 // otherwise, just wait until onResume to set the state back to Workspace
1632 if (alreadyOnHome) {
1633 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001634 if (mWorkspace.isInOverviewMode()) {
1635 mWorkspace.exitOverviewMode();
1636 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001637 } else {
1638 mOnResumeState = State.WORKSPACE;
1639 }
1640
1641 final View v = getWindow().peekDecorView();
1642 if (v != null && v.getWindowToken() != null) {
1643 InputMethodManager imm = (InputMethodManager)getSystemService(
1644 INPUT_METHOD_SERVICE);
1645 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1646 }
1647
1648 // Reset AllApps to its initial state
1649 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1650 mAppsCustomizeTabHost.reset();
1651 }
1652 }
1653 };
1654
1655 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1656 // Delay processing of the intent to allow the status bar animation to finish
1657 // first in order to avoid janky animations.
1658 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001659 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001660 // Process the intent immediately.
1661 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001662 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001663
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001664 }
Michael Jurka447bf842013-05-15 14:52:15 +02001665 if (DEBUG_RESUME_TIME) {
1666 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1667 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001668 }
1669
1670 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001671 public void onRestoreInstanceState(Bundle state) {
1672 super.onRestoreInstanceState(state);
1673 for (int page: mSynchronouslyBoundPages) {
1674 mWorkspace.restoreInstanceStateForChild(page);
1675 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001676 }
1677
1678 @Override
1679 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001680 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001681 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001682
Michael Jurka883f55b2010-10-21 15:47:14 -07001683 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001684 // We close any open folder since it will not be re-opened, and we need to make sure
1685 // this state is reflected.
1686 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001687
Adam Cohendcd297f2013-06-18 13:13:40 -07001688 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001689 mWaitingForResult) {
1690 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001691 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001692 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1693 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001694 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1695 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1696 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 }
1698
1699 if (mFolderInfo != null && mWaitingForResult) {
1700 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1701 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1702 }
Michael Jurka946ad472010-07-09 18:05:18 -07001703
Winson Chung785d2eb2011-04-14 16:08:02 -07001704 // Save the current AppsCustomize tab
1705 if (mAppsCustomizeTabHost != null) {
1706 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1707 if (currentTabTag != null) {
1708 outState.putString("apps_customize_currentTab", currentTabTag);
1709 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001710 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1711 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001712 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713 }
1714
1715 @Override
1716 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001718
Winson Chunge7a03942011-08-05 15:05:12 -07001719 // Remove all pending runnables
1720 mHandler.removeMessages(ADVANCE_MSG);
1721 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001722 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001723
Winson Chungcd2b0142011-06-08 16:02:26 -07001724 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001725 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001726 mModel.stopLoader();
1727 app.setLauncher(null);
1728
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001730 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001731 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001732 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001734 mAppWidgetHost = null;
1735
1736 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737
1738 TextKeyListener.getInstance().release();
1739
Winson Chung81b52252012-08-27 15:34:29 -07001740 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1741 // to prevent leaking Launcher activities on orientation change.
1742 if (mModel != null) {
1743 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1744 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001745
1746 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001747 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001748
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001749 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001750 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1751 mWorkspace.removeAllViews();
1752 mWorkspace = null;
1753 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001754
Michael Jurka2ecf9952012-06-18 12:52:28 -07001755 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001756 }
1757
Adam Cohena9cf38f2011-05-02 15:36:58 -07001758 public DragController getDragController() {
1759 return mDragController;
1760 }
1761
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 @Override
1763 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001764 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001765 super.startActivityForResult(intent, requestCode);
1766 }
1767
Winson Chung70d72102011-08-12 11:24:35 -07001768 /**
1769 * Indicates that we want global search for this activity by setting the globalSearch
1770 * argument for {@link #startSearch} to true.
1771 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001773 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001775
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001776 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001777
Karl Rosaen138a0412009-04-23 19:00:21 -07001778 if (initialQuery == null) {
1779 // Use any text typed in the launcher as the initial query
1780 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001781 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001782 if (appSearchData == null) {
1783 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001784 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 }
Winson Chungadf0c182012-08-23 14:59:07 -07001786 Rect sourceBounds = new Rect();
1787 if (mSearchDropTargetBar != null) {
1788 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1789 }
Romain Guycbb89e42009-06-08 15:52:54 -07001790
Bjorn Bringertc459e522013-06-07 19:36:01 +01001791 startSearch(initialQuery, selectInitialQuery,
1792 appSearchData, sourceBounds);
1793 }
1794
1795 public void startSearch(String initialQuery,
1796 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001797 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001798 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001799 }
1800
1801 /**
1802 * Starts the global search activity. This code is a copied from SearchManager
1803 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001804 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001805 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001806 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001807 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1808 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1809 if (globalSearchActivity == null) {
1810 Log.w(TAG, "No global search activity found.");
1811 return;
1812 }
1813 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1814 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1815 intent.setComponent(globalSearchActivity);
1816 // Make sure that we have a Bundle to put source in
1817 if (appSearchData == null) {
1818 appSearchData = new Bundle();
1819 } else {
1820 appSearchData = new Bundle(appSearchData);
1821 }
1822 // Set source to package name of app that starts global search, if not set already.
1823 if (!appSearchData.containsKey("source")) {
1824 appSearchData.putString("source", getPackageName());
1825 }
1826 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1827 if (!TextUtils.isEmpty(initialQuery)) {
1828 intent.putExtra(SearchManager.QUERY, initialQuery);
1829 }
1830 if (selectInitialQuery) {
1831 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1832 }
1833 intent.setSourceBounds(sourceBounds);
1834 try {
1835 startActivity(intent);
1836 } catch (ActivityNotFoundException ex) {
1837 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1838 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839 }
1840
Winson Chung70d72102011-08-12 11:24:35 -07001841 @Override
1842 public boolean onCreateOptionsMenu(Menu menu) {
1843 if (isWorkspaceLocked()) {
1844 return false;
1845 }
1846
1847 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001848
1849 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1850 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1851 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001852 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1853 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1854 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001855 String helpUrl = getString(R.string.help_url);
1856 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001857 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1858 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1859
Winson Chung70d72102011-08-12 11:24:35 -07001860 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1861 .setIcon(android.R.drawable.ic_menu_gallery)
1862 .setAlphabeticShortcut('W');
1863 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1864 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001865 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001866 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001867 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1868 .setIcon(android.R.drawable.ic_menu_preferences)
1869 .setIntent(settings)
1870 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001871 if (!helpUrl.isEmpty()) {
1872 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1873 .setIcon(android.R.drawable.ic_menu_help)
1874 .setIntent(help)
1875 .setAlphabeticShortcut('H');
1876 }
Winson Chung70d72102011-08-12 11:24:35 -07001877 return true;
1878 }
1879
1880 @Override
1881 public boolean onPrepareOptionsMenu(Menu menu) {
1882 super.onPrepareOptionsMenu(menu);
1883
1884 if (mAppsCustomizeTabHost.isTransitioning()) {
1885 return false;
1886 }
1887 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1888 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1889
1890 return true;
1891 }
1892
1893 @Override
1894 public boolean onOptionsItemSelected(MenuItem item) {
1895 switch (item.getItemId()) {
1896 case MENU_WALLPAPER_SETTINGS:
1897 startWallpaper();
1898 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001899 }
1900
1901 return super.onOptionsItemSelected(item);
1902 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001904 @Override
1905 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001906 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001907 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001908 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001909 }
1910
Joe Onorato9c1289c2009-08-17 11:03:03 -04001911 public boolean isWorkspaceLocked() {
1912 return mWorkspaceLoading || mWaitingForResult;
1913 }
1914
Michael Jurka0280c3b2010-09-17 15:00:07 -07001915 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001916 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001917 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001918 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1919 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001920 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001921 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001922 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001923
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001924 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1925 AppWidgetProviderInfo appWidgetInfo) {
1926 if (appWidgetInfo.configure != null) {
1927 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001928
Bjorn Bringert7984c942009-12-09 15:38:25 +00001929 // Launch over to configure widget, if needed
1930 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001931 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001932 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001933 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001934 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001935 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001936 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001937 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001938 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001939 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 }
1941 }
Romain Guycbb89e42009-06-08 15:52:54 -07001942
Adam Cohenfbba09b2011-07-18 21:43:05 -07001943 /**
1944 * Process a shortcut drop.
1945 *
1946 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001947 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001948 * @param cell The cell it should be added to, optional
1949 * @param position The location on the screen where it was dropped, optional
1950 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001951 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001952 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001953 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001954 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001955 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001957
1958 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 mPendingAddInfo.cellX = cell[0];
1960 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001961 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001962
1963 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1964 createShortcutIntent.setComponent(componentName);
1965 processShortcut(createShortcutIntent);
1966 }
1967
Adam Cohenfbba09b2011-07-18 21:43:05 -07001968 /**
1969 * Process a widget drop.
1970 *
1971 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001972 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001973 * @param cell The cell it should be added to, optional
1974 * @param position The location on the screen where it was dropped, optional
1975 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001976 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001977 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001978 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001979 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001980 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001981 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001982 mPendingAddInfo.minSpanX = info.minSpanX;
1983 mPendingAddInfo.minSpanY = info.minSpanY;
1984
Adam Cohenfbba09b2011-07-18 21:43:05 -07001985 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001986 mPendingAddInfo.cellX = cell[0];
1987 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001988 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001989 if (span != null) {
1990 mPendingAddInfo.spanX = span[0];
1991 mPendingAddInfo.spanY = span[1];
1992 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001993
Adam Cohened66b2b2012-01-23 17:28:51 -08001994 AppWidgetHostView hostView = info.boundWidget;
1995 int appWidgetId;
1996 if (hostView != null) {
1997 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001998 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001999 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002000 // In this case, we either need to start an activity to get permission to bind
2001 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002002 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002003 Bundle options = info.bindOptions;
2004
2005 boolean success = false;
2006 if (options != null) {
2007 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2008 info.componentName, options);
2009 } else {
2010 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2011 info.componentName);
2012 }
2013 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002014 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002015 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002016 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002017 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2018 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2019 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002020 // TODO: we need to make sure that this accounts for the options bundle.
2021 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002022 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2023 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002024 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002025 }
2026
Joe Onoratodeb98af2010-02-19 14:59:39 -08002027 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002028 // Handle case where user selected "Applications"
2029 String applicationName = getResources().getString(R.string.group_applications);
2030 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002031
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002032 if (applicationName != null && applicationName.equals(shortcutName)) {
2033 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2034 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002035
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002036 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2037 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002038 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002039 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002040 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002041 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002042 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043 }
2044
Winson Chung24ab2f12010-09-16 14:10:47 -07002045 void processWallpaper(Intent intent) {
2046 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2047 }
2048
Adam Cohendcd297f2013-06-18 13:13:40 -07002049 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002050 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002051 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 folderInfo.title = getText(R.string.folder_name);
2053
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002055 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002056 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002057 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058
2059 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002060 FolderIcon newFolder =
2061 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002062 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002063 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002064 // Force measure the new folder icon
2065 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2066 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002067 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068 }
Romain Guycbb89e42009-06-08 15:52:54 -07002069
Joe Onorato9c1289c2009-08-17 11:03:03 -04002070 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002071 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002072 }
2073
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002074 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002075 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002077 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002078 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 }
2080
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002081 protected ComponentName getWallpaperPickerComponent() {
2082 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2083 }
2084
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002085 /**
2086 * Registers various content observers. The current implementation registers
2087 * only a favorites observer to keep track of the favorites applications.
2088 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002089 private void registerContentObservers() {
2090 ContentResolver resolver = getContentResolver();
2091 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2092 true, mWidgetObserver);
2093 }
2094
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 @Override
2096 public boolean dispatchKeyEvent(KeyEvent event) {
2097 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2098 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002100 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002101 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002102 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002103 dumpState();
2104 return true;
2105 }
2106 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002107 }
2108 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2109 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002110 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002111 return true;
2112 }
2113 }
2114
2115 return super.dispatchKeyEvent(event);
2116 }
2117
Joe Onorato88ec0992009-11-19 13:16:06 -08002118 @Override
2119 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002120 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002121 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002122 } else if (mWorkspace.isInOverviewMode()) {
2123 mWorkspace.exitOverviewMode();
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002124 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002125 Folder openFolder = mWorkspace.getOpenFolder();
2126 if (openFolder.isEditingName()) {
2127 openFolder.dismissEditingName();
2128 } else {
2129 closeFolder();
2130 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002131 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002132 mWorkspace.exitWidgetResizeMode();
2133
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002134 // Back button is a no-op here, but give at least some feedback for the button press
2135 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002136 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002137 }
2138
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002139 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002140 * Re-listen when widgets are reset.
2141 */
2142 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002143 if (mAppWidgetHost != null) {
2144 mAppWidgetHost.startListening();
2145 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002146 }
2147
2148 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002149 * Launches the intent referred by the clicked shortcut.
2150 *
2151 * @param v The view representing the clicked shortcut.
2152 */
2153 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002154 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2155 // view has detached (it's possible for this to happen if the view is removed mid touch).
2156 if (v.getWindowToken() == null) {
2157 return;
2158 }
2159
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002160 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002161 return;
2162 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002163
Adam Cohenf358a4b2013-07-23 16:47:31 -07002164 if (v instanceof PageIndicator) {
2165 if (!mWorkspace.isInOverviewMode()) {
2166 mWorkspace.enterOverviewMode();
2167 }
2168 return;
2169 }
2170
2171 if (v instanceof CellLayout) {
2172 if (mWorkspace.isInOverviewMode()) {
2173 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v));
2174 }
2175 }
2176
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002178 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002179 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002180 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2181 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002182
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002183 // Check for special shortcuts
2184 if (intent.getComponent() != null) {
2185 final String shortcutClass = intent.getComponent().getClassName();
2186
2187 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002188 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002189 return;
2190 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2191 MemoryDumpActivity.startDump(this);
2192 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002193 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2194 toggleShowWeightWatcher();
2195 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002196 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002197 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002198
2199 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002200 int[] pos = new int[2];
2201 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002202 intent.setSourceBounds(new Rect(pos[0], pos[1],
2203 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002204
2205 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002206
Daniel Sandlerff02d492013-08-05 02:12:05 -04002207 mStats.recordLaunch(intent, shortcut);
2208
Michael Jurkaddd62e92011-02-16 17:49:14 -08002209 if (success && v instanceof BubbleTextView) {
2210 mWaitingForResume = (BubbleTextView) v;
2211 mWaitingForResume.setStayPressed(true);
2212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002213 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002214 if (v instanceof FolderIcon) {
2215 FolderIcon fi = (FolderIcon) v;
2216 handleFolderClick(fi);
2217 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002218 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002219 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002220 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002221 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002222 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002223 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002224 }
2225 }
2226
Michael Jurka0e260592010-06-30 17:07:39 -07002227 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002228 return false;
2229 }
2230
Michael Jurkaaf442092010-06-10 17:01:57 -07002231 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002232 * Event handler for the search button
2233 *
2234 * @param v The view that was clicked.
2235 */
2236 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002237 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2238
Amith Yamasania135ba82011-08-09 17:42:01 -07002239 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002240 }
2241
2242 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002243 * Event handler for the voice button
2244 *
2245 * @param v The view that was clicked.
2246 */
2247 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002248 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002249
Bjorn Bringertc459e522013-06-07 19:36:01 +01002250 startVoice();
2251 }
2252
2253 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002254 try {
2255 final SearchManager searchManager =
2256 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2257 ComponentName activityName = searchManager.getGlobalSearchActivity();
2258 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002259 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002260 if (activityName != null) {
2261 intent.setPackage(activityName.getPackageName());
2262 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002263 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002264 } catch (ActivityNotFoundException e) {
2265 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002266 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002267 startActivitySafely(null, intent, "onClickVoiceButton");
2268 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002269 }
2270
2271 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002272 * Event handler for the "grid" button that appears on the home screen, which
2273 * enters all apps mode.
2274 *
2275 * @param v The view that was clicked.
2276 */
2277 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002278 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002279 }
2280
2281 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002282 // Provide the same haptic feedback that the system offers for virtual keys.
2283 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002284 }
2285
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002286 public void onClickAppMarketButton(View v) {
2287 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002288 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002289 } else {
2290 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002291 }
2292 }
2293
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002294 void startApplicationDetailsActivity(ComponentName componentName) {
2295 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002296 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2297 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002298 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002299 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002300 }
2301
Michael Jurka1e2f4652013-07-08 18:03:46 -07002302 // returns true if the activity was started
2303 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002304 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002305 // System applications cannot be installed. For now, show a toast explaining that.
2306 // We may give them the option of disabling apps this way.
2307 int messageId = R.string.uninstall_system_app_text;
2308 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002309 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002310 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002311 String packageName = componentName.getPackageName();
2312 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002313 Intent intent = new Intent(
2314 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002315 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2316 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002317 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002318 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002319 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002320 }
2321
Michael Jurka86a720e2012-05-09 11:23:23 -07002322 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002323 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002324
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002325 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002326 // Only launch using the new animation if the shortcut has not opted out (this is a
2327 // private contract between launcher and may be ignored in the future).
2328 boolean useLaunchAnimation = (v != null) &&
2329 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2330 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002331 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2332 v.getMeasuredWidth(), v.getMeasuredHeight());
2333
2334 startActivity(intent, opts.toBundle());
2335 } else {
2336 startActivity(intent);
2337 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002338 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 } catch (SecurityException e) {
2340 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002341 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002343 "or use the exported attribute for this activity. "
2344 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002345 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002346 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002347 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002348
Michael Jurka86a720e2012-05-09 11:23:23 -07002349 boolean startActivitySafely(View v, Intent intent, Object tag) {
2350 boolean success = false;
2351 try {
2352 success = startActivity(v, intent, tag);
2353 } catch (ActivityNotFoundException e) {
2354 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2355 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2356 }
2357 return success;
2358 }
2359
Adam Cohena9cf38f2011-05-02 15:36:58 -07002360 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002361 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002362 Folder openFolder = mWorkspace.getFolderForTag(info);
2363
2364 // If the folder info reports that the associated folder is open, then verify that
2365 // it is actually opened. There have been a few instances where this gets out of sync.
2366 if (info.opened && openFolder == null) {
2367 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002368 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002369 info.opened = false;
2370 }
2371
Adam Cohenfb91f302012-06-11 15:45:18 -07002372 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 // Close any open folder
2374 closeFolder();
2375 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002376 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002377 } else {
2378 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 int folderScreen;
2380 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002381 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 // .. and close it
2383 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002384 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 // Close any folder open on the current screen
2386 closeFolder();
2387 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002388 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002389 }
2390 }
2391 }
2392 }
2393
Adam Cohen268c4752012-06-06 17:47:33 -07002394 /**
2395 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2396 * in the DragLayer in the exact absolute location of the original FolderIcon.
2397 */
2398 private void copyFolderIconToImage(FolderIcon fi) {
2399 final int width = fi.getMeasuredWidth();
2400 final int height = fi.getMeasuredHeight();
2401
2402 // Lazy load ImageView, Bitmap and Canvas
2403 if (mFolderIconImageView == null) {
2404 mFolderIconImageView = new ImageView(this);
2405 }
2406 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2407 mFolderIconBitmap.getHeight() != height) {
2408 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2409 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2410 }
2411
2412 DragLayer.LayoutParams lp;
2413 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2414 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2415 } else {
2416 lp = new DragLayer.LayoutParams(width, height);
2417 }
2418
Adam Cohen307fe232012-08-16 17:55:58 -07002419 // The layout from which the folder is being opened may be scaled, adjust the starting
2420 // view size by this scale factor.
2421 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002422 lp.customPosition = true;
2423 lp.x = mRectForFolderAnimation.left;
2424 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002425 lp.width = (int) (scale * width);
2426 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002427
2428 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2429 fi.draw(mFolderIconCanvas);
2430 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002431 if (fi.getFolder() != null) {
2432 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2433 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002434 }
Adam Cohen268c4752012-06-06 17:47:33 -07002435 // Just in case this image view is still in the drag layer from a previous animation,
2436 // we remove it and re-add it.
2437 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2438 mDragLayer.removeView(mFolderIconImageView);
2439 }
2440 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002441 if (fi.getFolder() != null) {
2442 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002443 }
Adam Cohen268c4752012-06-06 17:47:33 -07002444 }
2445
Adam Cohen2801caf2011-05-13 20:57:39 -07002446 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002447 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002448 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2449 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2450 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2451
Adam Cohenc51934b2011-07-26 21:07:43 -07002452 FolderInfo info = (FolderInfo) fi.getTag();
2453 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2454 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002455 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2456 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002457 }
2458
Adam Cohen268c4752012-06-06 17:47:33 -07002459 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2460 copyFolderIconToImage(fi);
2461 fi.setVisibility(View.INVISIBLE);
2462
Michael Jurka2ecf9952012-06-18 12:52:28 -07002463 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002464 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002465 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2466 oa.start();
2467 }
2468
Adam Cohen268c4752012-06-06 17:47:33 -07002469 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002470 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002471 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2472 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2473 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2474
Adam Cohen268c4752012-06-06 17:47:33 -07002475 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002476
Adam Cohen268c4752012-06-06 17:47:33 -07002477 // We remove and re-draw the FolderIcon in-case it has changed
2478 mDragLayer.removeView(mFolderIconImageView);
2479 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002480 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002481 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002482 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002483 oa.addListener(new AnimatorListenerAdapter() {
2484 @Override
2485 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002486 if (cl != null) {
2487 cl.clearFolderLeaveBehind();
2488 // Remove the ImageView copy of the FolderIcon and make the original visible.
2489 mDragLayer.removeView(mFolderIconImageView);
2490 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002491 }
2492 }
2493 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002494 oa.start();
2495 }
2496
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002497 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002498 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002499 * is animated relative to the specified View. If the View is null, no animation
2500 * is played.
2501 *
2502 * @param folderInfo The FolderInfo describing the folder to open.
2503 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002504 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002505 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002506 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002507
Adam Cohena9cf38f2011-05-02 15:36:58 -07002508 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002509
Adam Cohen4554ee12011-08-03 16:13:21 -07002510 // Just verify that the folder hasn't already been added to the DragLayer.
2511 // There was a one-off crash where the folder had a parent already.
2512 if (folder.getParent() == null) {
2513 mDragLayer.addView(folder);
2514 mDragController.addDropTarget((DropTarget) folder);
2515 } else {
2516 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2517 folder.getParent() + ").");
2518 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002519 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002520 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002521
2522 // Notify the accessibility manager that this folder "window" has appeared and occluded
2523 // the workspace items
2524 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2525 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002526 }
2527
2528 public void closeFolder() {
2529 Folder folder = mWorkspace.getOpenFolder();
2530 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002531 if (folder.isEditingName()) {
2532 folder.dismissEditingName();
2533 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002534 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002535
2536 // Dismiss the folder cling
2537 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002538 }
2539 }
2540
2541 void closeFolder(Folder folder) {
2542 folder.getInfo().opened = false;
2543
2544 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2545 if (parent != null) {
2546 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2547 shrinkAndFadeInFolderIcon(fi);
2548 }
2549 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002550
2551 // Notify the accessibility manager that this folder "window" has disappeard and no
2552 // longer occludeds the workspace items
2553 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002554 }
2555
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002556 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002557 if (!isDraggingEnabled()) return false;
2558 if (isWorkspaceLocked()) return false;
2559 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002560
2561 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002562 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002563 }
2564
Michael Jurka0280c3b2010-09-17 15:00:07 -07002565 resetAddInfo();
2566 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002568 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002569 return true;
2570 }
2571
Winson Chung3d503fb2011-07-13 17:25:49 -07002572 // The hotseat touch handling does not go through Workspace, and we always allow long press
2573 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002574 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002575 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2576 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002577 if (itemUnderLongClick == null) {
Winson Chung0e6a7132013-08-23 12:55:10 -07002578 if (mWorkspace.hasNonCustomEmptyScreens()) {
2579 // User long pressed on empty space
2580 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2581 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2582 // Disabling reordering until we sort out some issues.
2583 if (mWorkspace.isInOverviewMode()) {
2584 mWorkspace.startReordering(v);
2585 } else {
2586 mWorkspace.enterOverviewMode();
2587 }
Adam Cohendedbd962013-07-11 14:21:49 -07002588 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002589 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002590 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002592 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002593 }
2594 }
2595 }
2596 return true;
2597 }
2598
Winson Chung3d503fb2011-07-13 17:25:49 -07002599 boolean isHotseatLayout(View layout) {
2600 return mHotseat != null && layout != null &&
2601 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2602 }
2603 Hotseat getHotseat() {
2604 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002605 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002606 View getOverviewPanel() {
2607 return mOverviewPanel;
2608 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002609 SearchDropTargetBar getSearchBar() {
2610 return mSearchDropTargetBar;
2611 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002612
Winson Chung3d503fb2011-07-13 17:25:49 -07002613 /**
2614 * Returns the CellLayout of the specified container at the specified screen.
2615 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002616 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002617 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2618 if (mHotseat != null) {
2619 return mHotseat.getLayout();
2620 } else {
2621 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002622 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002623 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002624 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002625 }
2626 }
2627
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002628 Workspace getWorkspace() {
2629 return mWorkspace;
2630 }
2631
Daniel Sandler843e8602010-06-07 14:59:01 -04002632 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002633 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002634 }
2635
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002636 /**
2637 * Helper method for the cameraZoomIn/cameraZoomOut animations
2638 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002639 * @param scaleFactor The scale factor used for the zoom
2640 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002641 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002642 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002643 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002645
Winson Chung18f41f82012-05-09 13:28:10 -07002646 void disableWallpaperIfInAllApps() {
2647 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002648 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002649 if (mAppsCustomizeTabHost != null &&
2650 !mAppsCustomizeTabHost.isTransitioning()) {
2651 updateWallpaperVisibility(false);
2652 }
2653 }
2654 }
2655
Craig Mautner360310b2012-10-26 15:13:08 -07002656 private void setWorkspaceBackground(boolean workspace) {
2657 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002658 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002659 }
2660
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002661 void updateWallpaperVisibility(boolean visible) {
2662 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2663 int curflags = getWindow().getAttributes().flags
2664 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2665 if (wpflags != curflags) {
2666 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2667 }
Craig Mautner360310b2012-10-26 15:13:08 -07002668 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002669 }
2670
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002671 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2672 if (v instanceof LauncherTransitionable) {
2673 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2674 }
2675 }
2676
Michael Jurkabed61d22012-02-14 22:51:29 -08002677 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2678 if (v instanceof LauncherTransitionable) {
2679 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2680 }
Winson Chung70442722012-02-10 15:43:22 -08002681
2682 // Update the workspace transition step as well
2683 dispatchOnLauncherTransitionStep(v, 0f);
2684 }
2685
2686 private void dispatchOnLauncherTransitionStep(View v, float t) {
2687 if (v instanceof LauncherTransitionable) {
2688 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2689 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002690 }
2691
2692 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2693 if (v instanceof LauncherTransitionable) {
2694 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2695 }
Winson Chung70442722012-02-10 15:43:22 -08002696
2697 // Update the workspace transition step as well
2698 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002699 }
2700
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002701 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002702 * Things to test when changing the following seven functions.
2703 * - Home from workspace
2704 * - from center screen
2705 * - from other screens
2706 * - Home from all apps
2707 * - from center screen
2708 * - from other screens
2709 * - Back from all apps
2710 * - from center screen
2711 * - from other screens
2712 * - Launch app from workspace and quit
2713 * - with back
2714 * - with home
2715 * - Launch app from all apps and quit
2716 * - with back
2717 * - with home
2718 * - Go to a screen that's not the default, then all
2719 * apps, and launch and app, and go back
2720 * - with back
2721 * -with home
2722 * - On workspace, long press power and go back
2723 * - with back
2724 * - with home
2725 * - On all apps, long press power and go back
2726 * - with back
2727 * - with home
2728 * - On workspace, power off
2729 * - On all apps, power off
2730 * - Launch an app and turn off the screen while in that app
2731 * - Go back with home key
2732 * - Go back with back key TODO: make this not go to workspace
2733 * - From all apps
2734 * - From workspace
2735 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2736 * - From all apps
2737 * - From the center workspace
2738 * - From another workspace
2739 */
2740
2741 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002742 * Zoom the camera out from the workspace to reveal 'toView'.
2743 * Assumes that the view to show is anchored at either the very top or very bottom
2744 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002745 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002746 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002747 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2748 showAppsCustomizeHelper(animated, springLoaded, contentType);
2749 }
2750 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2751 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002752 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002753 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002754 mStateAnimation.cancel();
2755 mStateAnimation = null;
2756 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002757 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002758
Winson Chungf0ea4d32011-06-06 14:27:16 -07002759 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2760 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2761 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002762 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002763 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002764 final int startDelay =
2765 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002766
Michael Jurkab3e22d92011-10-31 15:58:33 -07002767 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002768
Michael Jurkad74c9842011-07-10 12:44:21 -07002769 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002770 Animator workspaceAnim =
2771 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002772 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2773 // Set the content type for the all apps space
2774 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2775 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002776
2777 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002778 toView.setScaleX(scale);
2779 toView.setScaleY(scale);
2780 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2781 scaleAnim.
2782 scaleX(1f).scaleY(1f).
2783 setDuration(duration).
2784 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002785
Winson Chungf0ea4d32011-06-06 14:27:16 -07002786 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002787 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002788 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002789 .ofFloat(toView, "alpha", 0f, 1f)
2790 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002791 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002792 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2793 @Override
2794 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002795 if (animation == null) {
2796 throw new RuntimeException("animation is null");
2797 }
Winson Chung70442722012-02-10 15:43:22 -08002798 float t = (Float) animation.getAnimatedValue();
2799 dispatchOnLauncherTransitionStep(fromView, t);
2800 dispatchOnLauncherTransitionStep(toView, t);
2801 }
2802 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002803
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002804 // toView should appear right at the end of the workspace shrink
2805 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002806 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002807 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002808 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002809
2810 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002811 boolean animationCancelled = false;
2812
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002813 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002814 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002815 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002816 // Prepare the position
2817 toView.setTranslationX(0.0f);
2818 toView.setTranslationY(0.0f);
2819 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002820 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002821 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002822 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002823 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002824 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2825 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002826
Adam Cohenf4ddea32011-09-12 13:46:42 -07002827 if (!animationCancelled) {
2828 updateWallpaperVisibility(false);
2829 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002830
2831 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002832 if (mSearchDropTargetBar != null) {
2833 mSearchDropTargetBar.hideSearchBar(false);
2834 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002835 }
2836
Adam Cohencff6af82011-09-13 14:51:53 -07002837 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002838 public void onAnimationCancel(Animator animation) {
2839 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002840 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002841 });
2842
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002843 if (workspaceAnim != null) {
2844 mStateAnimation.play(workspaceAnim);
2845 }
Michael Jurka1899a362011-11-03 13:50:45 -07002846
2847 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002848
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002849 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2850 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002851
2852 // If any of the objects being animated haven't been measured/laid out
2853 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002854 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855 (mWorkspace.getMeasuredWidth() == 0) ||
2856 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002857 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002858 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002859
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002860 final AnimatorSet stateAnimation = mStateAnimation;
2861 final Runnable startAnimRunnable = new Runnable() {
2862 public void run() {
2863 // Check that mStateAnimation hasn't changed while
2864 // we waited for a layout/draw pass
2865 if (mStateAnimation != stateAnimation)
2866 return;
2867 setPivotsForZoom(toView, scale);
2868 dispatchOnLauncherTransitionStart(fromView, animated, false);
2869 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002870 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002871 }
2872 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002873 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002874 final ViewTreeObserver observer = toView.getViewTreeObserver();
2875 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2876 public void onGlobalLayout() {
2877 startAnimRunnable.run();
2878 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2879 }
2880 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002881 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002882 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002883 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002884 } else {
2885 toView.setTranslationX(0.0f);
2886 toView.setTranslationY(0.0f);
2887 toView.setScaleX(1.0f);
2888 toView.setScaleY(1.0f);
2889 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002890 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002891
Daniel Sandlere4f98912013-06-25 15:13:26 -04002892 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002893 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002894 if (mSearchDropTargetBar != null) {
2895 mSearchDropTargetBar.hideSearchBar(false);
2896 }
Michael Jurkaabded662011-03-04 12:06:57 -08002897 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002898 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002899 dispatchOnLauncherTransitionStart(fromView, animated, false);
2900 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002901 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002902 dispatchOnLauncherTransitionStart(toView, animated, false);
2903 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002904 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002905 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002906 }
2907
2908 /**
2909 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002910 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002911 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002912 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002913 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2914 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002915
Michael Jurkab3e22d92011-10-31 15:58:33 -07002916 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002917 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002918 mStateAnimation.cancel();
2919 mStateAnimation = null;
2920 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002921 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002922
Winson Chungf0ea4d32011-06-06 14:27:16 -07002923 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002924 final int fadeOutDuration =
2925 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002926 final float scaleFactor = (float)
2927 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2928 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002929 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002930 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002931 if (toState == State.WORKSPACE) {
2932 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2933 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002934 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002935 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2936 workspaceAnim = mWorkspace.getChangeStateAnimation(
2937 Workspace.State.SPRING_LOADED, animated);
2938 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002939
Michael Jurkab3e22d92011-10-31 15:58:33 -07002940 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002941 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002942 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002943 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002944 final LauncherViewPropertyAnimator scaleAnim =
2945 new LauncherViewPropertyAnimator(fromView);
2946 scaleAnim.
2947 scaleX(scaleFactor).scaleY(scaleFactor).
2948 setDuration(duration).
2949 setInterpolator(new Workspace.ZoomInInterpolator());
2950
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002951 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002952 .ofFloat(fromView, "alpha", 1f, 0f)
2953 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002954 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002955 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2956 @Override
2957 public void onAnimationUpdate(ValueAnimator animation) {
2958 float t = 1f - (Float) animation.getAnimatedValue();
2959 dispatchOnLauncherTransitionStep(fromView, t);
2960 dispatchOnLauncherTransitionStep(toView, t);
2961 }
2962 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002963
Michael Jurka2ecf9952012-06-18 12:52:28 -07002964 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002965
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002966 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2967 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002968 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002969
2970 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002971 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002972 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002973 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002974 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002975 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2976 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002977 if (onCompleteRunnable != null) {
2978 onCompleteRunnable.run();
2979 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002980 mAppsCustomizeContent.updateCurrentPageScroll();
2981 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002982 }
2983 });
2984
Winson Chungf0ea4d32011-06-06 14:27:16 -07002985 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002986 if (workspaceAnim != null) {
2987 mStateAnimation.play(workspaceAnim);
2988 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002989 dispatchOnLauncherTransitionStart(fromView, animated, true);
2990 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002991 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002992 } else {
2993 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002994 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002995 dispatchOnLauncherTransitionStart(fromView, animated, true);
2996 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002997 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002998 dispatchOnLauncherTransitionStart(toView, animated, true);
2999 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003000 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003001 }
3002
Michael Jurkae326f182011-11-21 14:05:46 -08003003 @Override
3004 public void onTrimMemory(int level) {
3005 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003006 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003007 mAppsCustomizeTabHost.onTrimMemory();
3008 }
3009 }
3010
Winson Chung18f41f82012-05-09 13:28:10 -07003011 @Override
3012 public void onWindowFocusChanged(boolean hasFocus) {
3013 if (!hasFocus) {
3014 // When another window occludes launcher (like the notification shade, or recents),
3015 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3016 updateWallpaperVisibility(true);
3017 } else {
3018 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003019 mWorkspace.postDelayed(new Runnable() {
3020 @Override
3021 public void run() {
3022 disableWallpaperIfInAllApps();
3023 }
3024 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003025 }
3026 }
3027
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003028 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003029 showWorkspace(animated, null);
3030 }
3031
3032 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003033 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003034 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003035 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003036 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003037
Winson Chungc7d2b602012-05-16 17:02:20 -07003038 // Show the search bar (only animate if we were showing the drop target bar in spring
3039 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003040 if (mSearchDropTargetBar != null) {
3041 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3042 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003043
Michael Jurkab3e22d92011-10-31 15:58:33 -07003044 // Set focus to the AppsCustomize button
3045 if (mAllAppsButton != null) {
3046 mAllAppsButton.requestFocus();
3047 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003048 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003049
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003050 // Change the state *after* we've called all the transition code
3051 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003052
Winson Chung5fb63472011-02-02 17:03:37 -08003053 // Resume the auto-advance of widgets
3054 mUserPresent = true;
3055 updateRunning();
3056
alanv1d4fde62012-10-17 13:15:47 -07003057 // Send an accessibility event to announce the context change
3058 getWindow().getDecorView()
3059 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003060
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003061 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003062 }
3063
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003064 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003065 }
3066
Winson Chungc58497e2013-09-03 17:48:37 -07003067 void showAllApps(boolean animated,
3068 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003069 if (mState != State.WORKSPACE) return;
3070
Winson Chungc58497e2013-09-03 17:48:37 -07003071 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003072 mAppsCustomizeTabHost.requestFocus();
3073
Michael Jurkab3e22d92011-10-31 15:58:33 -07003074 // Change the state *after* we've called all the transition code
3075 mState = State.APPS_CUSTOMIZE;
3076
3077 // Pause the auto-advance of widgets until we are out of AllApps
3078 mUserPresent = false;
3079 updateRunning();
3080 closeFolder();
3081
3082 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003083 getWindow().getDecorView()
3084 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 }
3086
Adam Cohen7777d962011-08-18 18:58:38 -07003087 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003088 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003089 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003090 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003091 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003092 }
Adam Cohen7777d962011-08-18 18:58:38 -07003093
Adam Cohened66b2b2012-01-23 17:28:51 -08003094 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3095 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003096 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3097
Winson Chunge7a03942011-08-05 15:05:12 -07003098 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003099 @Override
3100 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003101 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003102 // Before we show workspace, hide all apps again because
3103 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3104 // clean up our state transition functions
3105 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003106 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003107 } else {
3108 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003109 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003110 }
3111 }, (extendedDelay ?
3112 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3113 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3114 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003115
Michael Jurkad3ef3062010-11-23 16:23:58 -08003116 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003117 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003118 final boolean animated = true;
3119 final boolean springLoaded = true;
3120 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003121 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003122 }
3123 // Otherwise, we are not in spring loaded mode, so don't do anything.
3124 }
3125
Michael Jurkab3e22d92011-10-31 15:58:33 -07003126 void lockAllApps() {
3127 // TODO
3128 }
3129
3130 void unlockAllApps() {
3131 // TODO
3132 }
3133
Winson Chungf0ea4d32011-06-06 14:27:16 -07003134 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003135 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003136 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003137 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003138 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003139 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003140 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003141 int duration = 0;
3142 if (mSearchDropTargetBar != null) {
3143 duration = mSearchDropTargetBar.getTransitionInDuration();
3144 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003145 mHotseat.animate().alpha(1f).setDuration(duration);
3146 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003147 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003148 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003149 }
3150 }
3151 }
3152
3153 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003154 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003155 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003156 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003157 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003158 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003159 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003160 int duration = 0;
3161 if (mSearchDropTargetBar != null) {
3162 duration = mSearchDropTargetBar.getTransitionOutDuration();
3163 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003164 mHotseat.animate().alpha(0f).setDuration(duration);
3165 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003166 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003167 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003168 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003169 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003170 }
3171
Patrick Dubroy5f445422011-02-18 14:35:21 -08003172 /**
3173 * Add an item from all apps or customize onto the given workspace screen.
3174 * If layout is null, add to the current screen.
3175 */
3176 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003177 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003178 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003179 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003180 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003181
Winson Chungdff8ebb2011-09-08 17:25:31 -07003182 /** Maps the current orientation to an index for referencing orientation correct global icons */
3183 private int getCurrentOrientationIndexForGlobalIcons() {
3184 // default - 0, landscape - 1
3185 switch (getResources().getConfiguration().orientation) {
3186 case Configuration.ORIENTATION_LANDSCAPE:
3187 return 1;
3188 default:
3189 return 0;
3190 }
3191 }
3192
Michael Jurkaae65ee32012-04-30 11:45:54 -07003193 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003194 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003195 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003196 // Look for the toolbar icon specified in the activity meta-data
3197 Bundle metaData = packageManager.getActivityInfo(
3198 activityName, PackageManager.GET_META_DATA).metaData;
3199 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003200 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003201 if (iconResId != 0) {
3202 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003203 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003204 }
3205 }
3206 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003207 // This can happen if the activity defines an invalid drawable
3208 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3209 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003210 } catch (Resources.NotFoundException nfe) {
3211 // This can happen if the activity defines an invalid drawable
3212 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3213 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003214 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003215 return null;
3216 }
3217
3218 // if successful in getting icon, return it; otherwise, set button to use default drawable
3219 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003220 int buttonId, ComponentName activityName, int fallbackDrawableId,
3221 String toolbarResourceName) {
3222 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003223 Resources r = getResources();
3224 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3225 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003226
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003227 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003228 // If we were unable to find the icon via the meta-data, use a generic one
3229 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003230 toolbarIcon = r.getDrawable(fallbackDrawableId);
3231 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003232 if (button != null) {
3233 button.setCompoundDrawables(toolbarIcon, null, null, null);
3234 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003235 return null;
3236 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003237 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003238 if (button != null) {
3239 button.setCompoundDrawables(toolbarIcon, null, null, null);
3240 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003241 return toolbarIcon.getConstantState();
3242 }
3243 }
3244
3245 // if successful in getting icon, return it; otherwise, set button to use default drawable
3246 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003247 int buttonId, ComponentName activityName, int fallbackDrawableId,
3248 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003249 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003250 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003251
Michael Jurka19e0fc52011-07-22 18:00:21 -07003252 if (button != null) {
3253 // If we were unable to find the icon via the meta-data, use a
3254 // generic one
3255 if (toolbarIcon == null) {
3256 button.setImageResource(fallbackDrawableId);
3257 } else {
3258 button.setImageDrawable(toolbarIcon);
3259 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003260 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003261
3262 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3263
Michael Jurka0423dcf2010-10-05 14:56:18 -07003264 }
3265
Winson Chung1b884092012-06-08 17:13:02 -07003266 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003267 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003268 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003269 }
3270
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003271 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003272 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003273 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003274 }
3275
Winson Chungbb185bd2011-11-21 12:31:42 -08003276 private void invalidatePressedFocusedStates(View container, View button) {
3277 if (container instanceof HolographicLinearLayout) {
3278 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3279 layout.invalidatePressedFocusedStates();
3280 } else if (button instanceof HolographicImageView) {
3281 HolographicImageView view = (HolographicImageView) button;
3282 view.invalidatePressedFocusedStates();
3283 }
3284 }
3285
Cristina Stancu476493b2013-08-07 17:20:14 +01003286 public View getQsbBar() {
3287 if (mQsbBar == null) {
3288 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3289 }
3290 return mQsbBar;
3291 }
3292
3293 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003294 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003295 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003296 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003297 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003298
Winson Chung1cad91e2011-05-25 17:41:01 -07003299 final SearchManager searchManager =
3300 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3301 ComponentName activityName = searchManager.getGlobalSearchActivity();
3302 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003303 int coi = getCurrentOrientationIndexForGlobalIcons();
3304 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003305 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3306 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3307 if (sGlobalSearchIcon[coi] == null) {
3308 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3309 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3310 TOOLBAR_ICON_METADATA_NAME);
3311 }
3312
Winson Chungc51db6a2011-10-05 11:44:49 -07003313 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3314 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003315 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003316 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003317 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003318 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003319 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3320 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3321 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003322 voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003323 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003324 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003325 }
3326 }
3327
Cristina Stancu476493b2013-08-07 17:20:14 +01003328 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003329 final View searchButtonContainer = findViewById(R.id.search_button_container);
3330 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003331 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003332 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003333 }
3334
Cristina Stancu476493b2013-08-07 17:20:14 +01003335 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003336 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003337 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003338
Winson Chungc51db6a2011-10-05 11:44:49 -07003339 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003340 final SearchManager searchManager =
3341 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3342 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3343
3344 ComponentName activityName = null;
3345 if (globalSearchActivity != null) {
3346 // Check if the global search activity handles voice search
3347 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3348 intent.setPackage(globalSearchActivity.getPackageName());
3349 activityName = intent.resolveActivity(getPackageManager());
3350 }
3351
3352 if (activityName == null) {
3353 // Fallback: check if an activity other than the global search activity
3354 // resolves this
3355 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3356 activityName = intent.resolveActivity(getPackageManager());
3357 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003358 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003359 int coi = getCurrentOrientationIndexForGlobalIcons();
3360 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003361 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3362 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3363 if (sVoiceSearchIcon[coi] == null) {
3364 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3365 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3366 TOOLBAR_ICON_METADATA_NAME);
3367 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003368 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003369 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003370 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003371 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003372 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003373 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003374 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003375 voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003376 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003377 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003378 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003379 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003380
Cristina Stancu476493b2013-08-07 17:20:14 +01003381 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003382 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3383 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003384 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003385 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003386 }
3387
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003388 public void setVoiceButtonProxyVisible(boolean visible) {
3389 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3390 if (voiceButtonProxy != null) {
3391 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3392 }
3393 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003394 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003395 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003396 */
3397 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003398 final View marketButton = findViewById(R.id.market_button);
3399 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3400 // Find the app market activity by resolving an intent.
3401 // (If multiple app markets are installed, it will return the ResolverActivity.)
3402 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003403 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003404 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003405 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003406 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003407 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3408 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003409 marketButton.setVisibility(View.VISIBLE);
3410 } else {
3411 // We should hide and disable the view so that we don't try and restore the visibility
3412 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3413 marketButton.setVisibility(View.GONE);
3414 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003415 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003416 }
3417
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003418 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003419 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3420 Resources r = getResources();
3421 Drawable marketIconDrawable = d.newDrawable(r);
3422 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3423 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3424 marketIconDrawable.setBounds(0, 0, w, h);
3425
3426 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003427 }
3428
Michael Jurkad7c28052012-04-27 15:43:36 -07003429 @Override
3430 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003431 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003432 final List<CharSequence> text = event.getText();
3433 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003434 // Populate event with a fake title based on the current state.
3435 if (mState == State.APPS_CUSTOMIZE) {
3436 text.add(getString(R.string.all_apps_button_label));
3437 } else {
3438 text.add(getString(R.string.all_apps_home_button_label));
3439 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003440 return result;
3441 }
3442
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003443 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003444 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003445 */
3446 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3447 @Override
3448 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003449 closeSystemDialogs();
3450 }
3451 }
3452
3453 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003454 * Receives notifications whenever the appwidgets are reset.
3455 */
3456 private class AppWidgetResetObserver extends ContentObserver {
3457 public AppWidgetResetObserver() {
3458 super(new Handler());
3459 }
3460
3461 @Override
3462 public void onChange(boolean selfChange) {
3463 onAppWidgetReset();
3464 }
3465 }
3466
3467 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003468 * If the activity is currently paused, signal that we need to run the passed Runnable
3469 * in onResume.
3470 *
3471 * This needs to be called from incoming places where resources might have been loaded
3472 * while we are paused. That is becaues the Configuration might be wrong
3473 * when we're not running, and if it comes back to what it was when we
3474 * were paused, we are not restarted.
3475 *
3476 * Implementation of the method from LauncherModel.Callbacks.
3477 *
3478 * @return true if we are currently paused. The caller might be able to
3479 * skip some work in that case since we will come back again.
3480 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003481 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003482 if (mPaused) {
3483 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003484 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003485 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003486 }
3487 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003488 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003489 return true;
3490 } else {
3491 return false;
3492 }
3493 }
3494
Michael Jurkac402cd92013-05-20 15:49:32 +02003495 private boolean waitUntilResume(Runnable run) {
3496 return waitUntilResume(run, false);
3497 }
3498
Michael Jurka1e2f4652013-07-08 18:03:46 -07003499 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003500 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003501 }
3502
Michael Jurka7607c2f2013-04-03 14:33:19 -07003503 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003504 * If the activity is currently paused, signal that we need to re-run the loader
3505 * in onResume.
3506 *
3507 * This needs to be called from incoming places where resources might have been loaded
3508 * while we are paused. That is becaues the Configuration might be wrong
3509 * when we're not running, and if it comes back to what it was when we
3510 * were paused, we are not restarted.
3511 *
3512 * Implementation of the method from LauncherModel.Callbacks.
3513 *
3514 * @return true if we are currently paused. The caller might be able to
3515 * skip some work in that case since we will come back again.
3516 */
3517 public boolean setLoadOnResume() {
3518 if (mPaused) {
3519 Log.i(TAG, "setLoadOnResume");
3520 mOnResumeNeedsLoad = true;
3521 return true;
3522 } else {
3523 return false;
3524 }
3525 }
3526
3527 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003528 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003529 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003530 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003531 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003532 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003533 } else {
3534 return SCREEN_COUNT / 2;
3535 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003536 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003537
Joe Onorato9c1289c2009-08-17 11:03:03 -04003538 /**
3539 * Refreshes the shortcuts shown on the workspace.
3540 *
3541 * Implementation of the method from LauncherModel.Callbacks.
3542 */
3543 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003544 // If we're starting binding all over again, clear any bind calls we'd postponed in
3545 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3546 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003547 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003548
Winson Chungd64d1762013-08-20 14:37:16 -07003549 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003550 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003551 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003552
Michael Jurka05bf6442011-11-30 20:28:53 -08003553 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003554 if (mHotseat != null) {
3555 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003556 }
3557 }
3558
Adam Cohendcd297f2013-06-18 13:13:40 -07003559 @Override
3560 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003561 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003562
Adam Cohen5084cba2013-09-03 12:01:16 -07003563 // If there are no screens, we need to have an empty screen
3564 if (orderedScreenIds.size() == 0) {
3565 mWorkspace.addExtraEmptyScreen();
3566 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003567
3568 // Create the custom content page (this call updates mDefaultScreen which calls
3569 // setCurrentPage() so ensure that all pages are added before calling this)
3570 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3571 mWorkspace.createCustomContentPage();
3572 }
Winson Chung64359a52013-07-08 17:17:08 -07003573 }
3574
3575 @Override
3576 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003577 int count = orderedScreenIds.size();
3578 for (int i = 0; i < count; i++) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003579 Launcher.addDumpLog(TAG, "10249126 - bindAddScreens(" + orderedScreenIds.get(i) + ")", true);
Adam Cohen89bddfa2013-08-20 11:57:13 -07003580 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003581 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003582 }
3583
Adam Cohen39a06042013-07-19 14:30:12 -07003584 private boolean shouldShowWeightWatcher() {
3585 String spKey = LauncherAppState.getSharedPreferencesKey();
3586 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003587 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003588
3589 return show;
3590 }
3591
Adam Cohen4caf2982013-08-20 18:54:31 -07003592 private boolean emailSent() {
3593 String spKey = LauncherAppState.getSharedPreferencesKey();
3594 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3595 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3596 return show;
3597 }
3598
3599 private void setEmailSent(boolean sent) {
3600 String spKey = LauncherAppState.getSharedPreferencesKey();
3601 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3602
3603 SharedPreferences.Editor editor = sp.edit();
3604 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3605 editor.commit();
3606 }
3607
Adam Cohen39a06042013-07-19 14:30:12 -07003608 private void toggleShowWeightWatcher() {
3609 String spKey = LauncherAppState.getSharedPreferencesKey();
3610 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3611 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3612
3613 show = !show;
3614
3615 SharedPreferences.Editor editor = sp.edit();
3616 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3617 editor.commit();
3618
3619 if (mWeightWatcher != null) {
3620 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3621 }
3622 }
3623
Winson Chungd64d1762013-08-20 14:37:16 -07003624 public void bindAppsAdded(final ArrayList<Long> newScreens,
3625 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003626 final ArrayList<ItemInfo> addAnimated,
3627 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003628 Runnable r = new Runnable() {
3629 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003630 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003631 }
3632 };
3633 if (waitUntilResume(r)) {
3634 return;
3635 }
3636
Adam Cohen4caf2982013-08-20 18:54:31 -07003637 Launcher.addDumpLog(TAG, "10249126 - bindAppsAdded(" + newScreens.size() + ")", true);
Winson Chungd64d1762013-08-20 14:37:16 -07003638
3639 // Add the new screens
3640 bindAddScreens(newScreens);
3641
3642 // We add the items without animation on non-visible pages, and with
3643 // animations on the new page (which we will try and snap to).
3644 if (!addNotAnimated.isEmpty()) {
3645 bindItems(addNotAnimated, 0,
3646 addNotAnimated.size(), false);
3647 }
3648 if (!addAnimated.isEmpty()) {
3649 bindItems(addAnimated, 0,
3650 addAnimated.size(), true);
3651 }
Winson Chungc58497e2013-09-03 17:48:37 -07003652
3653 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3654 addedApps != null && mAppsCustomizeContent != null) {
3655 mAppsCustomizeContent.addApps(addedApps);
3656 }
Winson Chungd64d1762013-08-20 14:37:16 -07003657 }
3658
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003659 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003660 * Bind the items start-end from the list.
3661 *
3662 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003663 */
Winson Chung64359a52013-07-08 17:17:08 -07003664 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3665 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003666 Runnable r = new Runnable() {
3667 public void run() {
3668 bindItems(shortcuts, start, end, forceAnimateIcons);
3669 }
3670 };
3671 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003672 return;
3673 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003674
Winson Chungf0c6ae02012-03-21 16:10:31 -07003675 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003676 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3677 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003678 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003679 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003680 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003681 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003682 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003683
3684 // Short circuit if we are loading dock items for a configuration which has no dock
3685 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3686 mHotseat == null) {
3687 continue;
3688 }
3689
Joe Onorato9c1289c2009-08-17 11:03:03 -04003690 switch (item.itemType) {
3691 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3692 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003693 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003694 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003695
Winson Chung64359a52013-07-08 17:17:08 -07003696 /*
3697 * TODO: FIX collision case
3698 */
Winson Chungce376632013-07-11 16:12:41 -07003699 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3700 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3701 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3702 throw new RuntimeException("OCCUPIED");
3703 }
Winson Chung64359a52013-07-08 17:17:08 -07003704 }
3705
Adam Cohendcd297f2013-06-18 13:13:40 -07003706 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3707 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003708 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003709 // Animate all the applications up now
3710 shortcut.setAlpha(0f);
3711 shortcut.setScaleX(0f);
3712 shortcut.setScaleY(0f);
3713 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003714 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003715 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003716 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003717 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003718 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003719 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003720 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003721 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3722 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003723 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003724 default:
3725 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003726 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003727 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003728
Winson Chung997a9232013-07-24 15:33:46 -07003729 if (animateIcons) {
3730 // Animate to the correct page
3731 if (newShortcutsScreenId > -1) {
3732 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3733 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3734 if (newShortcutsScreenId != currentScreenId) {
3735 mWorkspace.snapToPage(newScreenIndex);
3736 }
3737 }
3738
Winson Chung64359a52013-07-08 17:17:08 -07003739 // We post the animation slightly delayed to prevent slowdowns when we are loading
3740 // right after we return to launcher.
3741 mWorkspace.postDelayed(new Runnable() {
3742 public void run() {
3743 anim.playTogether(bounceAnims);
3744 anim.start();
3745 }
3746 }, NEW_APPS_ANIMATION_DELAY);
3747 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003748 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003749 }
3750
Joe Onorato9c1289c2009-08-17 11:03:03 -04003751 /**
3752 * Implementation of the method from LauncherModel.Callbacks.
3753 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003754 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003755 Runnable r = new Runnable() {
3756 public void run() {
3757 bindFolders(folders);
3758 }
3759 };
3760 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003761 return;
3762 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003763 sFolders.clear();
3764 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003765 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003766
3767 /**
3768 * Add the views for a widget to the workspace.
3769 *
3770 * Implementation of the method from LauncherModel.Callbacks.
3771 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003772 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003773 Runnable r = new Runnable() {
3774 public void run() {
3775 bindAppWidget(item);
3776 }
3777 };
3778 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003779 return;
3780 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003781
Daniel Sandler843e8602010-06-07 14:59:01 -04003782 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3783 if (DEBUG_WIDGETS) {
3784 Log.d(TAG, "bindAppWidget: " + item);
3785 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003786 final Workspace workspace = mWorkspace;
3787
3788 final int appWidgetId = item.appWidgetId;
3789 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003790 if (DEBUG_WIDGETS) {
3791 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3792 }
3793
Joe Onorato9c1289c2009-08-17 11:03:03 -04003794 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3795
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003797 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003798
Adam Cohendcd297f2013-06-18 13:13:40 -07003799 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003800 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003801 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3802
Joe Onorato9c1289c2009-08-17 11:03:03 -04003803 workspace.requestLayout();
3804
Daniel Sandler843e8602010-06-07 14:59:01 -04003805 if (DEBUG_WIDGETS) {
3806 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3807 + (SystemClock.uptimeMillis()-start) + "ms");
3808 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003809 }
3810
Adam Cohen1462de32012-07-24 22:34:36 -07003811 public void onPageBoundSynchronously(int page) {
3812 mSynchronouslyBoundPages.add(page);
3813 }
3814
Joe Onorato9c1289c2009-08-17 11:03:03 -04003815 /**
3816 * Callback saying that there aren't any more items to bind.
3817 *
3818 * Implementation of the method from LauncherModel.Callbacks.
3819 */
Adam Cohene25af792013-06-06 23:08:25 -07003820 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003821 Runnable r = new Runnable() {
3822 public void run() {
3823 finishBindingItems(upgradePath);
3824 }
3825 };
3826 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003827 return;
3828 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003829 if (mSavedState != null) {
3830 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003831 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003832 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003833 mSavedState = null;
3834 }
3835
Adam Cohen1462de32012-07-24 22:34:36 -07003836 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003837
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003838 // If we received the result of any pending adds while the loader was running (e.g. the
3839 // widget configuration forced an orientation change), process them now.
3840 for (int i = 0; i < sPendingAddList.size(); i++) {
3841 completeAdd(sPendingAddList.get(i));
3842 }
3843 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003844
Winson Chungc51db6a2011-10-05 11:44:49 -07003845 // Update the market app icon as necessary (the other icons will be managed in response to
3846 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003847 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003848
Winson Chungf0c6ae02012-03-21 16:10:31 -07003849 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003850 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003851 mWorkspace.getUniqueComponents(true, null);
3852 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003853 }
Adam Cohen99894d92013-06-14 11:22:59 -07003854
Adam Cohen66a01fd2013-06-11 12:48:00 -07003855 mWorkspace.post(new Runnable() {
3856 @Override
3857 public void run() {
3858 onFinishBindingItems();
3859 }
3860 });
Adam Cohen4caf2982013-08-20 18:54:31 -07003861
3862 // Write all the logs to disk
3863 Launcher.addDumpLog(TAG, "10249126 - finishBindingItems() - dumping logs to disk", true);
3864 dumpLogsToLocalData(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003865 }
3866
Winson Chunga2413752012-04-03 14:22:34 -07003867 private boolean canRunNewAppsAnimation() {
3868 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3869 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3870 }
3871
Winson Chungc9168342013-06-26 14:54:55 -07003872 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3873 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3874 PropertyValuesHolder.ofFloat("alpha", 1f),
3875 PropertyValuesHolder.ofFloat("scaleX", 1f),
3876 PropertyValuesHolder.ofFloat("scaleY", 1f));
3877 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3878 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3879 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3880 return bounceAnim;
3881 }
3882
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003883 @Override
3884 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003885 boolean searchVisible = updateGlobalSearchIcon();
3886 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003887 if (mSearchDropTargetBar != null) {
3888 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3889 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003890 }
3891
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003892 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003893 * Add the icons for all apps.
3894 *
3895 * Implementation of the method from LauncherModel.Callbacks.
3896 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003897 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003898 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3899 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3900 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3901 getHotseat().addAllAppsFolder(mIconCache, apps,
3902 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3903 }
3904 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003905 }
Winson Chungc58497e2013-09-03 17:48:37 -07003906 } else {
3907 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3908 mAppsCustomizeContent != null) {
3909 mAppsCustomizeContent.setApps(apps);
3910 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003911 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003912 }
3913
Bjorn Bringert85f418d2013-09-06 12:50:05 +01003914 @Override
3915 public boolean shouldShowApp(ResolveInfo app) {
3916 return true;
3917 }
3918
Joe Onorato9c1289c2009-08-17 11:03:03 -04003919 /**
3920 * A package was updated.
3921 *
3922 * Implementation of the method from LauncherModel.Callbacks.
3923 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003924 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003925 Runnable r = new Runnable() {
3926 public void run() {
3927 bindAppsUpdated(apps);
3928 }
3929 };
3930 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003931 return;
3932 }
3933
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003934 if (mWorkspace != null) {
3935 mWorkspace.updateShortcuts(apps);
3936 }
Winson Chungc58497e2013-09-03 17:48:37 -07003937
3938 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3939 mAppsCustomizeContent != null) {
3940 mAppsCustomizeContent.updateApps(apps);
3941 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003942 }
3943
3944 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003945 * A package was uninstalled. We take both the super set of packageNames
3946 * in addition to specific applications to remove, the reason being that
3947 * this can be called when a package is updated as well. In that scenario,
3948 * we only remove specific components from the workspace, where as
3949 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003950 *
3951 * Implementation of the method from LauncherModel.Callbacks.
3952 */
Winson Chung83892cc2013-05-01 16:53:33 -07003953 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003954 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003955 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003956 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003957 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003958 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003959 }
Winson Chungd64d1762013-08-20 14:37:16 -07003960 };
3961 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003962 return;
3963 }
3964
Winson Chung64359a52013-07-08 17:17:08 -07003965 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003966 mWorkspace.removeItemsByPackageName(packageNames);
3967 } else {
3968 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003969 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003970
Winson Chunga1820962011-10-03 16:31:06 -07003971 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003972 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003973
3974 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3975 mAppsCustomizeContent != null) {
3976 mAppsCustomizeContent.removeApps(appInfos);
3977 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003978 }
Joe Onoratobe386092009-11-17 17:32:16 -08003979
3980 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003981 * A number of packages were updated.
3982 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003983 private ArrayList<Object> mWidgetsAndShortcuts;
3984 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003985 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003986 bindPackagesUpdated(mWidgetsAndShortcuts);
3987 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003988 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003989 };
3990
3991 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3992 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3993 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003994 return;
3995 }
3996
Winson Chung64359a52013-07-08 17:17:08 -07003997 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003998 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3999 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004000 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004001 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004002 }
4003
Winson Chung400438b2011-01-16 17:53:48 -08004004 private int mapConfigurationOriActivityInfoOri(int configOri) {
4005 final Display d = getWindowManager().getDefaultDisplay();
4006 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4007 switch (d.getRotation()) {
4008 case Surface.ROTATION_0:
4009 case Surface.ROTATION_180:
4010 // We are currently in the same basic orientation as the natural orientation
4011 naturalOri = configOri;
4012 break;
4013 case Surface.ROTATION_90:
4014 case Surface.ROTATION_270:
4015 // We are currently in the other basic orientation to the natural orientation
4016 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4017 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4018 break;
4019 }
4020
4021 int[] oriMap = {
4022 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4023 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4024 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4025 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4026 };
4027 // Since the map starts at portrait, we need to offset if this device's natural orientation
4028 // is landscape.
4029 int indexOffset = 0;
4030 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4031 indexOffset = 1;
4032 }
4033 return oriMap[(d.getRotation() + indexOffset) % 4];
4034 }
Adam Cohen446e9402011-09-15 18:21:21 -07004035
Winson Chung4b919f82012-05-01 10:44:08 -07004036 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004037 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004038 getResources().getBoolean(R.bool.allow_rotation);
4039 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004040 }
Winson Chung4b919f82012-05-01 10:44:08 -07004041 public void lockScreenOrientation() {
4042 if (isRotationEnabled()) {
4043 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4044 .getConfiguration().orientation));
4045 }
4046 }
4047 public void unlockScreenOrientation(boolean immediate) {
4048 if (isRotationEnabled()) {
4049 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004050 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004051 } else {
4052 mHandler.postDelayed(new Runnable() {
4053 public void run() {
4054 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4055 }
4056 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004057 }
Winson Chung4b919f82012-05-01 10:44:08 -07004058 }
Winson Chung400438b2011-01-16 17:53:48 -08004059 }
4060
Winson Chung82f55532011-08-09 14:14:23 -07004061 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004062 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004063 if (DISABLE_CLINGS) {
4064 return false;
4065 }
4066
Brett Chabot2a9e2282011-08-23 15:03:13 -07004067 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004068 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004069
Michael Jurkae233a8b2013-03-19 13:49:20 +01004070 // Restricted secondary users (child mode) will potentially have very few apps
4071 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004072// boolean supportsLimitedUsers =
4073// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4074// Account[] accounts = AccountManager.get(this).getAccounts();
4075// if (supportsLimitedUsers && accounts.length == 0) {
4076// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4077// Bundle restrictions = um.getUserRestrictions();
4078// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4079// return false;
4080// }
4081// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004082 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004083 }
Michael Jurka22143132012-10-04 17:42:38 +02004084
Winson Chung7d7541e2011-09-16 20:14:36 -07004085 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02004086 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004087 if (cling != null) {
4088 cling.init(this, positionData);
4089 cling.setVisibility(View.VISIBLE);
4090 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
4091 if (animate) {
4092 cling.buildLayer();
4093 cling.setAlpha(0f);
4094 cling.animate()
4095 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07004096 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07004097 .setDuration(SHOW_CLING_DURATION)
4098 .setStartDelay(delay)
4099 .start();
4100 } else {
4101 cling.setAlpha(1f);
4102 }
Michael Jurka22143132012-10-04 17:42:38 +02004103 cling.setFocusableInTouchMode(true);
4104 cling.post(new Runnable() {
4105 public void run() {
4106 cling.setFocusable(true);
4107 cling.requestFocus();
4108 }
4109 });
4110 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
4111 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004112 }
4113 return cling;
4114 }
Michael Jurka22143132012-10-04 17:42:38 +02004115
Winson Chung7d7541e2011-09-16 20:14:36 -07004116 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08004117 // To catch cases where siblings of top-level views are made invisible, just check whether
4118 // the cling is directly set to GONE before dismissing it.
4119 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07004120 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07004121 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07004122 anim.addListener(new AnimatorListenerAdapter() {
4123 public void onAnimationEnd(Animator animation) {
4124 cling.setVisibility(View.GONE);
4125 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004126 // We should update the shared preferences on a background thread
4127 new Thread("dismissClingThread") {
4128 public void run() {
4129 SharedPreferences.Editor editor = mSharedPrefs.edit();
4130 editor.putBoolean(flag, true);
4131 editor.commit();
4132 }
4133 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07004134 };
4135 });
4136 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02004137 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07004138 }
4139 }
Michael Jurka22143132012-10-04 17:42:38 +02004140
Winson Chung9d9d74f2011-09-19 11:49:12 -07004141 private void removeCling(int id) {
4142 final View cling = findViewById(id);
4143 if (cling != null) {
4144 final ViewGroup parent = (ViewGroup) cling.getParent();
4145 parent.post(new Runnable() {
4146 @Override
4147 public void run() {
4148 parent.removeView(cling);
4149 }
4150 });
Michael Jurka22143132012-10-04 17:42:38 +02004151 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004152 }
4153 }
Michael Jurka974c3862012-05-22 22:00:31 -07004154
4155 private boolean skipCustomClingIfNoAccounts() {
4156 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4157 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4158 if (customCling) {
4159 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004160 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004161 Account[] accounts = am.getAccountsByType("com.google");
4162 return accounts.length == 0;
4163 }
4164 return false;
4165 }
4166
Winson Chung7d7541e2011-09-16 20:14:36 -07004167 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004168 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004169 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07004170 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
4171 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004172 // If we're not using the default workspace layout, replace workspace cling
4173 // with a custom workspace cling (usually specified in an overlay)
4174 // For now, only do this on tablets
4175 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02004176 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02004177 // Use a custom cling
4178 View cling = findViewById(R.id.workspace_cling);
4179 ViewGroup clingParent = (ViewGroup) cling.getParent();
4180 int clingIndex = clingParent.indexOfChild(cling);
4181 clingParent.removeViewAt(clingIndex);
4182 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4183 clingParent.addView(customCling, clingIndex);
4184 customCling.setId(R.id.workspace_cling);
4185 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004186 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004187 } else {
4188 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004189 }
4190 }
4191 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004192 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004193 if (isClingsEnabled() &&
4194 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004195 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004196 } else {
4197 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004198 }
4199 }
4200 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004201 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004202 if (isClingsEnabled() &&
4203 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4204 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004205 } else {
4206 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004207 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004208 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004209 }
Michael Jurka104c4562013-07-08 18:03:46 -07004210 protected SharedPreferences getSharedPrefs() {
4211 return mSharedPrefs;
4212 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004213 public boolean isFolderClingVisible() {
4214 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004215 if (cling != null) {
4216 return cling.getVisibility() == View.VISIBLE;
4217 }
4218 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004219 }
Winson Chung82f55532011-08-09 14:14:23 -07004220 public void dismissWorkspaceCling(View v) {
4221 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004222 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004223 }
4224 public void dismissAllAppsCling(View v) {
4225 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004226 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4227 }
4228 public void dismissFolderCling(View v) {
4229 Cling cling = (Cling) findViewById(R.id.folder_cling);
4230 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004231 }
4232
Winson Chung80baf5a2010-08-09 16:03:15 -07004233 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004234 * Prints out out state for debugging.
4235 */
4236 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004237 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004238 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004239 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4240 Log.d(TAG, "mRestoring=" + mRestoring);
4241 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4242 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004243 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004244 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004245
Winson Chung785d2eb2011-04-14 16:08:02 -07004246 if (mAppsCustomizeContent != null) {
4247 mAppsCustomizeContent.dumpState();
4248 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004249 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004250 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004251
4252 @Override
4253 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4254 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004255 synchronized (sDumpLogs) {
4256 writer.println(" ");
4257 writer.println("Debug logs: ");
4258 for (int i = 0; i < sDumpLogs.size(); i++) {
4259 writer.println(" " + sDumpLogs.get(i));
4260 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004261 }
4262 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004263
4264 public static void dumpDebugLogsToConsole() {
Adam Cohen4caf2982013-08-20 18:54:31 -07004265 synchronized (sDumpLogs) {
4266 Log.d(TAG, "");
4267 Log.d(TAG, "*********************");
4268 Log.d(TAG, "Launcher debug logs: ");
4269 for (int i = 0; i < sDumpLogs.size(); i++) {
4270 Log.d(TAG, " " + sDumpLogs.get(i));
4271 }
4272 Log.d(TAG, "*********************");
4273 Log.d(TAG, "");
Adam Cohen487f7dd2012-06-28 18:12:10 -07004274 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004275 }
4276
4277 public static void addDumpLog(String tag, String log, boolean debugLog) {
4278 if (debugLog) {
4279 Log.d(tag, log);
4280 }
4281 sDateStamp.setTime(System.currentTimeMillis());
4282 synchronized (sDumpLogs) {
4283 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
4284 }
4285 }
4286
4287 public void dumpLogsToLocalData(final boolean email) {
4288 new Thread("DumpLogsToLocalData") {
4289 @Override
4290 public void run() {
4291 boolean success = false;
4292 sDateStamp.setTime(sRunStart);
4293 String FILENAME = sDateStamp.getMonth() + "-"
4294 + sDateStamp.getDay() + "_"
4295 + sDateStamp.getHours() + "-"
4296 + sDateStamp.getMinutes() + "_"
4297 + sDateStamp.getSeconds() + ".txt";
4298
4299 FileOutputStream fos = null;
4300 File outFile = null;
4301 try {
4302 outFile = new File(getFilesDir(), FILENAME);
4303 outFile.createNewFile();
4304 fos = new FileOutputStream(outFile);
4305 } catch (Exception e) {
4306 e.printStackTrace();
4307 }
4308 if (fos != null) {
4309 PrintWriter writer = new PrintWriter(fos);
4310
4311 writer.println(" ");
4312 writer.println("Debug logs: ");
4313 synchronized (sDumpLogs) {
4314 for (int i = 0; i < sDumpLogs.size(); i++) {
4315 writer.println(" " + sDumpLogs.get(i));
4316 }
4317 }
4318 writer.close();
4319 }
4320 try {
4321 if (fos != null) {
4322 fos.close();
4323 success = true;
4324 }
4325 } catch (IOException e) {
4326 e.printStackTrace();
4327 }
4328
4329 if (success && email) {
4330 if (!emailSent()) {
4331 emailFile(outFile);
4332 }
4333 }
4334 }
4335 }.start();
4336 }
4337
4338 private void emailFile(File file) {
4339 File publicCopy = new File(Environment.getExternalStorageDirectory(), file.getName());
4340 try {
4341 copyFile(file, publicCopy);
4342 } catch (IOException e) {
4343 e.printStackTrace();
4344 return;
4345 }
4346
4347 Intent intent = new Intent(Intent.ACTION_SEND);
4348 intent.setType("text/plain");
4349 intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"adamcohen@google.com, winsonc@google.com," +
4350 "mikejurka@google"});
4351 intent.putExtra(Intent.EXTRA_SUBJECT, "Data corruption " + file.getName());
4352 intent.putExtra(Intent.EXTRA_TEXT, "Data corruption has occurred, logs attached");
4353
4354 if (!file.exists() || !file.canRead()) {
4355 Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
4356 finish();
4357 return;
4358 }
4359
4360 Toast.makeText(this, "Data corruption has occurred, please send e-mail", Toast.LENGTH_LONG);
4361 Uri uri = Uri.fromFile(publicCopy);
4362 intent.putExtra(Intent.EXTRA_STREAM, uri);
4363 startActivity(Intent.createChooser(intent, "Please send logs, consider clearing data"));
4364
4365 setEmailSent(true);
4366 }
4367
4368 public void copyFile(File src, File dst) throws IOException {
4369 InputStream in = new FileInputStream(src);
4370 OutputStream out = new FileOutputStream(dst);
4371
4372 // Transfer bytes from in to out
4373 byte[] buf = new byte[1024];
4374 int len;
4375 while ((len = in.read(buf)) > 0) {
4376 out.write(buf, 0, len);
4377 }
4378 in.close();
4379 out.close();
Adam Cohen487f7dd2012-06-28 18:12:10 -07004380 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004381}
Michael Jurka2763be32011-02-24 11:19:57 -08004382
Michael Jurkaabded662011-03-04 12:06:57 -08004383interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004384 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004385 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004386 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004387 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004388 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004389}