blob: ec84a9ac02f3307a9b33502537218a8d6badb6c9 [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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070053import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070054import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040057import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070058import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020060import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080061import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070062import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070063import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040064import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080066import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.text.Selection;
68import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070069import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070071import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070073import android.view.Display;
74import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
76import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
79import android.view.MenuItem;
80import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070091import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileInputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700108import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.IOException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.io.InputStream;
111import java.io.OutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700118import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120/**
121 * Default launcher application.
122 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100123public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700124 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700125 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800126 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700127 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
Daniel Sandlerf061f822013-06-27 13:59:36 -0400129 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400130 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700131 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400132 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700133
Winson Chung70d72102011-08-12 11:24:35 -0700134 private static final int MENU_GROUP_WALLPAPER = 1;
135 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
136 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700137 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
138 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
140 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700141 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142 private static final int REQUEST_PICK_APPLICATION = 6;
143 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700144 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700145 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Michael Jurka8b805b12012-04-18 14:23:14 -0700147 private static final int REQUEST_BIND_APPWIDGET = 11;
148
Mathew Inwood876a8462013-06-14 14:12:41 +0100149 /**
150 * IntentStarter uses request codes starting with this. This must be greater than all activity
151 * request codes used internally.
152 */
153 protected static final int REQUEST_LAST = 100;
154
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
156
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800157 static final int SCREEN_COUNT = 5;
158 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Romain Guy98d01652009-06-30 16:21:04 -0700160 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800161 // To turn on these properties, type
162 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
163 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
164 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165
Winson Chung2672ff92012-05-04 16:22:30 -0700166 // The Intent extra that defines whether to ignore the launch animation
167 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400168 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700169
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 // Type: int
171 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700172 // Type: int
173 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700175 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
176 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
178 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700179 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700181 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: boolean
183 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
184 // Type: long
185 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700186 // Type: int
187 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
188 // Type: int
189 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
190 // Type: parcelable
191 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100193 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700194 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100195 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700196 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100197 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700198
Adam Cohen39a06042013-07-19 14:30:12 -0700199 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700200 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700201
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700202 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700203 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700204 private State mState = State.WORKSPACE;
205 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700206
Joe Onorato9c1289c2009-08-17 11:03:03 -0400207 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700208 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
209 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700210 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700211 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800214 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215
Winson Chunga2413752012-04-03 14:22:34 -0700216 // How long to wait before the new-shortcut animation automatically pans the workspace
217 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
Winson Chung64359a52013-07-08 17:17:08 -0700218 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700219
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800220 private final BroadcastReceiver mCloseSystemDialogsReceiver
221 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800222 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
223
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 private LayoutInflater mInflater;
225
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700227 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800228 private DragLayer mDragLayer;
229 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700230 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700231
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700232 private AppWidgetManager mAppWidgetManager;
233 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700234
Michael Jurkac9d95c52011-08-29 14:03:34 -0700235 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700236 private AppWidgetProviderInfo mPendingAddWidgetInfo;
237
Michael Jurka0280c3b2010-09-17 15:00:07 -0700238 private int[] mTmpAddItemCellCoordinates = new int[2];
239
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800240 private FolderInfo mFolderInfo;
241
Winson Chung3d503fb2011-07-13 17:25:49 -0700242 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700243 private View mOverviewPanel;
244
Michael Jurka838a4ca2011-02-07 13:33:06 -0800245 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700246
Winson Chungc51db6a2011-10-05 11:44:49 -0700247 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700248 private AppsCustomizeTabHost mAppsCustomizeTabHost;
249 private AppsCustomizePagedView mAppsCustomizeContent;
250 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100251 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700254 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
255 // scroll issues (because the workspace may not have been measured yet) and extra work.
256 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
257 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258
259 private SpannableStringBuilder mDefaultKeySsb = null;
260
Joe Onorato9c1289c2009-08-17 11:03:03 -0400261 private boolean mWorkspaceLoading = true;
262
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800263 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 private boolean mRestoring;
265 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700266 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267
Michael Jurka1e2f4652013-07-08 18:03:46 -0700268 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700269 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
270
Winson Chung4a2afa32012-07-19 14:53:05 -0700271 // Keep track of whether the user has left launcher
272 private static boolean sPausedFromUserAction = false;
273
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800274 private Bundle mSavedInstanceState;
275
Joe Onorato9c1289c2009-08-17 11:03:03 -0400276 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800277 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800278 private boolean mUserPresent = true;
279 private boolean mVisible = false;
280 private boolean mAttached = false;
Adam Cohen7564d982013-06-06 23:11:58 -0700281 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400282
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700283 private static LocaleConfiguration sLocaleConfiguration = null;
284
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700285 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700286
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700287 private Intent mAppMarketIntent = null;
288
Adam Cohended9f8d2010-11-03 13:25:16 -0700289 // Related to the auto-advancing of widgets
290 private final int ADVANCE_MSG = 1;
291 private final int mAdvanceInterval = 20000;
292 private final int mAdvanceStagger = 250;
293 private long mAutoAdvanceSentTime;
294 private long mAutoAdvanceTimeLeft = -1;
295 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
296 new HashMap<View, AppWidgetProviderInfo>();
297
Winson Chung400438b2011-01-16 17:53:48 -0800298 // Determines how long to wait after a rotation before restoring the screen orientation to
299 // match the sensor state.
300 private final int mRestoreScreenOrientationDelay = 500;
301
Michael Jurka4ef207b2010-11-29 17:05:45 -0800302 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700303 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
304 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
305 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800306
Craig Mautner360310b2012-10-26 15:13:08 -0700307 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700308
Adam Cohen1462de32012-07-24 22:34:36 -0700309 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
310
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700311 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700312 static Date sDateStamp = new Date();
313 static DateFormat sDateFormat =
314 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
315 static long sRunStart = System.currentTimeMillis();
316 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700317
Winson Chung46353de2012-02-16 14:05:10 -0800318 // We only want to get the SharedPreferences once since it does an FS stat each time we get
319 // it from the context.
320 private SharedPreferences mSharedPrefs;
321
Adam Cohene25af792013-06-06 23:08:25 -0700322 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
323
Winson Chungf0c6ae02012-03-21 16:10:31 -0700324 // Holds the page that we need to animate to, and the icon views that we need to animate up
325 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700326 private ImageView mFolderIconImageView;
327 private Bitmap mFolderIconBitmap;
328 private Canvas mFolderIconCanvas;
329 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700330
Michael Jurkaddd62e92011-02-16 17:49:14 -0800331 private BubbleTextView mWaitingForResume;
332
Michael Jurka22143132012-10-04 17:42:38 +0200333 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
334 = new HideFromAccessibilityHelper();
335
Michael Jurkac1f5d262011-09-30 19:32:27 -0700336 private Runnable mBuildLayersRunnable = new Runnable() {
337 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700338 if (mWorkspace != null) {
339 mWorkspace.buildPageHardwareLayers();
340 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700341 }
342 };
343
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800344 private static ArrayList<PendingAddArguments> sPendingAddList
345 = new ArrayList<PendingAddArguments>();
346
Michael Jurka0a457bf2012-11-19 14:05:05 -0800347 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
348
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800349 private static class PendingAddArguments {
350 int requestCode;
351 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700352 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700353 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 int cellX;
355 int cellY;
356 }
357
Daniel Sandlerff02d492013-08-05 02:12:05 -0400358 private Stats mStats;
359
Michael Jurka0a457bf2012-11-19 14:05:05 -0800360 private static boolean isPropertyEnabled(String propertyName) {
361 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700362 }
363
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 @Override
365 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700366 if (DEBUG_STRICT_MODE) {
367 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
368 .detectDiskReads()
369 .detectDiskWrites()
370 .detectNetwork() // or .detectAll() for all detectable problems
371 .penaltyLog()
372 .build());
373 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
374 .detectLeakedSqlLiteObjects()
375 .detectLeakedClosableObjects()
376 .penaltyLog()
377 .penaltyDeath()
378 .build());
379 }
380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400382
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400383 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400384 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700385
386 // Determine the dynamic grid properties
387 Point smallestSize = new Point();
388 Point largestSize = new Point();
389 Point realSize = new Point();
390 Display display = getWindowManager().getDefaultDisplay();
391 display.getCurrentSizeRange(smallestSize, largestSize);
392 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700393 DisplayMetrics dm = new DisplayMetrics();
394 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700395 // Lazy-initialize the dynamic grid
396 DeviceProfile grid = app.initDynamicGrid(this,
397 Math.min(smallestSize.x, smallestSize.y),
398 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700399 realSize.x, realSize.y,
400 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700401
402 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400403 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700404 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800405 mModel = app.setLauncher(this);
406 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400407 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700409
Daniel Sandlerff02d492013-08-05 02:12:05 -0400410 mStats = new Stats(this);
411
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700412 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700413 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
414 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700415
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700416 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
417 // this also ensures that any synchronous binding below doesn't re-trigger another
418 // LauncherModel load.
419 mPaused = false;
420
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200422 android.os.Debug.startMethodTracing(
423 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 }
425
426 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 setContentView(R.layout.launcher);
428 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100429 grid.layout(this);
Winson Chung7d7541e2011-09-16 20:14:36 -0700430 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800432 registerContentObservers();
433
Joe Onorato7c312c12009-08-13 21:36:53 -0700434 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700435
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 mSavedState = savedInstanceState;
437 restoreState(mSavedState);
438
Winson Chunga12a2502010-12-20 14:41:35 -0800439 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700440 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200441 mAppsCustomizeContent.onPackagesUpdated(
442 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700443 }
Winson Chunga12a2502010-12-20 14:41:35 -0800444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 if (PROFILE_STARTUP) {
446 android.os.Debug.stopMethodTracing();
447 }
448
449 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700450 if (sPausedFromUserAction) {
451 // If the user leaves launcher, then we should just load items asynchronously when
452 // they return.
453 mModel.startLoader(true, -1);
454 } else {
455 // We only load the page synchronously if the user rotates (or triggers a
456 // configuration change) while launcher is in the foreground
457 mModel.startLoader(true, mWorkspace.getCurrentPage());
458 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 }
460
461 // For handling default keys
462 mDefaultKeySsb = new SpannableStringBuilder();
463 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800464
465 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
466 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800467
Adam Cohenf9426d52012-06-04 17:26:21 -0700468 updateGlobalIcons();
469
470 // On large interfaces, we want the screen to auto-rotate based on the current orientation
471 unlockScreenOrientation(true);
472 }
473
Winson Chung4a2afa32012-07-19 14:53:05 -0700474 protected void onUserLeaveHint() {
475 super.onUserLeaveHint();
476 sPausedFromUserAction = true;
477 }
478
Winson Chung98ca0f72013-07-29 12:58:51 -0700479 /** To be overriden by subclasses to hint to Launcher that we have custom content */
480 protected boolean hasCustomContentToLeft() {
481 return false;
482 }
483
Adam Cohenf9426d52012-06-04 17:26:21 -0700484 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700485 boolean searchVisible = false;
486 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800487 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700488 int coi = getCurrentOrientationIndexForGlobalIcons();
489 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
490 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700491 updateAppMarketIcon();
492 searchVisible = updateGlobalSearchIcon();
493 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700494 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700495 if (sGlobalSearchIcon[coi] != null) {
496 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700497 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700498 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700499 if (sVoiceSearchIcon[coi] != null) {
500 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700501 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700502 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700503 if (sAppMarketIcon[coi] != null) {
504 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800505 }
Winson Chungadf0c182012-08-23 14:59:07 -0700506 if (mSearchDropTargetBar != null) {
507 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
508 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800509 }
Romain Guycbb89e42009-06-08 15:52:54 -0700510
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800511 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700512 if (sLocaleConfiguration == null) {
513 new AsyncTask<Void, Void, LocaleConfiguration>() {
514 @Override
515 protected LocaleConfiguration doInBackground(Void... unused) {
516 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
517 readConfiguration(Launcher.this, localeConfiguration);
518 return localeConfiguration;
519 }
520
521 @Override
522 protected void onPostExecute(LocaleConfiguration result) {
523 sLocaleConfiguration = result;
524 checkForLocaleChange(); // recursive, but now with a locale configuration
525 }
526 }.execute();
527 return;
528 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700529
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800530 final Configuration configuration = getResources().getConfiguration();
531
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700532 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800533 final String locale = configuration.locale.toString();
534
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700535 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800536 final int mcc = configuration.mcc;
537
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700538 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800539 final int mnc = configuration.mnc;
540
Romain Guy84f296c2009-11-04 15:00:44 -0800541 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800542
Romain Guy84f296c2009-11-04 15:00:44 -0800543 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700544 sLocaleConfiguration.locale = locale;
545 sLocaleConfiguration.mcc = mcc;
546 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700547
Joe Onorato0589f0f2010-02-08 13:44:00 -0800548 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700549
550 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
551 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700552 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700553 public void run() {
554 writeConfiguration(Launcher.this, localeConfiguration);
555 }
556 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700557 }
558 }
559
560 private static class LocaleConfiguration {
561 public String locale;
562 public int mcc = -1;
563 public int mnc = -1;
564 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700565
Romain Guy98d01652009-06-30 16:21:04 -0700566 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
567 DataInputStream in = null;
568 try {
569 in = new DataInputStream(context.openFileInput(PREFERENCES));
570 configuration.locale = in.readUTF();
571 configuration.mcc = in.readInt();
572 configuration.mnc = in.readInt();
573 } catch (FileNotFoundException e) {
574 // Ignore
575 } catch (IOException e) {
576 // Ignore
577 } finally {
578 if (in != null) {
579 try {
580 in.close();
581 } catch (IOException e) {
582 // Ignore
583 }
584 }
585 }
586 }
587
588 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
589 DataOutputStream out = null;
590 try {
591 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
592 out.writeUTF(configuration.locale);
593 out.writeInt(configuration.mcc);
594 out.writeInt(configuration.mnc);
595 out.flush();
596 } catch (FileNotFoundException e) {
597 // Ignore
598 } catch (IOException e) {
599 //noinspection ResultOfMethodCallIgnored
600 context.getFileStreamPath(PREFERENCES).delete();
601 } finally {
602 if (out != null) {
603 try {
604 out.close();
605 } catch (IOException e) {
606 // Ignore
607 }
608 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609 }
610 }
611
Bjorn Bringertc459e522013-06-07 19:36:01 +0100612 public LayoutInflater getInflater() {
613 return mInflater;
614 }
615
Adam Cohen716b51e2011-06-30 12:09:54 -0700616 public DragLayer getDragLayer() {
617 return mDragLayer;
618 }
619
Winson Chung36a62fe2012-05-06 18:04:42 -0700620 boolean isDraggingEnabled() {
621 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
622 // that is subsequently removed from the workspace in startBinding().
623 return !mModel.isLoadingWorkspace();
624 }
625
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800626 static int getScreen() {
627 synchronized (sLock) {
628 return sScreen;
629 }
630 }
631
632 static void setScreen(int screen) {
633 synchronized (sLock) {
634 sScreen = screen;
635 }
636 }
637
Winson Chung557d6ed2011-07-08 15:34:52 -0700638 /**
639 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
640 * a configuration step, this allows the proper animations to run after other transitions.
641 */
642 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700643 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800644 switch (args.requestCode) {
645 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700646 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700647 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800648 break;
649 case REQUEST_PICK_SHORTCUT:
650 processShortcut(args.intent);
651 break;
652 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700653 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700654 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700655 result = true;
656 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800657 case REQUEST_CREATE_APPWIDGET:
658 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700659 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700660 result = true;
661 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800662 case REQUEST_PICK_WALLPAPER:
663 // We just wanted the activity result here so we can clear mWaitingForResult
664 break;
665 }
Michael Jurka27614d22012-04-02 06:40:22 -0700666 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
667 // if you turned the screen off and then back while in All Apps, Launcher would not
668 // return to the workspace. Clearing mAddInfo.container here fixes this issue
669 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700670 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800671 }
672
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700674 protected void onActivityResult(
675 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700676 // Reset the startActivity waiting flag
677 mWaitingForResult = false;
678
Michael Jurka8b805b12012-04-18 14:23:14 -0700679 if (requestCode == REQUEST_BIND_APPWIDGET) {
680 int appWidgetId = data != null ?
681 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
682 if (resultCode == RESULT_CANCELED) {
683 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
684 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700685 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700686 }
687 return;
688 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700689 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800690 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
691 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700692
Adam Cohened66b2b2012-01-23 17:28:51 -0800693 // We have special handling for widgets
694 if (isWidgetDrop) {
695 int appWidgetId = data != null ?
696 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700697 if (appWidgetId < 0) {
698 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
699 "widget configuration activity.");
700 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
701 } else {
702 completeTwoStageWidgetDrop(resultCode, appWidgetId);
703 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800704 return;
705 }
706
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 // The pattern used here is that a user PICKs a specific application,
708 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700709
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
711 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700712 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800713 final PendingAddArguments args = new PendingAddArguments();
714 args.requestCode = requestCode;
715 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700716 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700717 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700718 args.cellX = mPendingAddInfo.cellX;
719 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800720 if (isWorkspaceLocked()) {
721 sPendingAddList.add(args);
722 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700723 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800724 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800726 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700727 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800728 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
729 null);
730 }
731
732 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700733 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700734 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800735 Runnable onCompleteRunnable = null;
736 int animationType = 0;
737
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700738 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800739 if (resultCode == RESULT_OK) {
740 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
741 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700742 mPendingAddWidgetInfo);
743 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800744 onCompleteRunnable = new Runnable() {
745 @Override
746 public void run() {
747 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700748 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800749 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
750 null);
751 }
752 };
753 } else if (resultCode == RESULT_CANCELED) {
754 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
755 onCompleteRunnable = new Runnable() {
756 @Override
757 public void run() {
758 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
759 null);
760 }
761 };
762 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700763 if (mDragLayer.getAnimatedView() != null) {
764 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
765 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
766 animationType, boundWidget, true);
767 } else {
768 // The animated view may be null in the case of a rotation during widget configuration
769 onCompleteRunnable.run();
770 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800771 }
772
773 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700774 protected void onStop() {
775 super.onStop();
776 FirstFrameAnimatorHelper.setIsVisible(false);
777 }
778
779 @Override
780 protected void onStart() {
781 super.onStart();
782 FirstFrameAnimatorHelper.setIsVisible(true);
783 }
784
785 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800786 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200787 long startTime = 0;
788 if (DEBUG_RESUME_TIME) {
789 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400790 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200791 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800792 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700793
Winson Chung4a2afa32012-07-19 14:53:05 -0700794 // Restore the previous launcher state
795 if (mOnResumeState == State.WORKSPACE) {
796 showWorkspace(false);
797 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700798 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700799 }
800 mOnResumeState = State.NONE;
801
Craig Mautner360310b2012-10-26 15:13:08 -0700802 // Background was set to gradient in onPause(), restore to black if in all apps.
803 setWorkspaceBackground(mState == State.WORKSPACE);
804
Winson Chungde0fb8f2012-05-08 14:37:08 -0700805 // Process any items that were added while Launcher was away
Winson Chung997a9232013-07-24 15:33:46 -0700806 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
Winson Chungde0fb8f2012-05-08 14:37:08 -0700807
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800808 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700809 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700810 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400811 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700812 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400813 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700814 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700816 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200817 // We might have postponed some bind calls until onResume (see waitUntilResume) --
818 // execute them here
819 long startTimeCallbacks = 0;
820 if (DEBUG_RESUME_TIME) {
821 startTimeCallbacks = System.currentTimeMillis();
822 }
823
824 if (mAppsCustomizeContent != null) {
825 mAppsCustomizeContent.setBulkBind(true);
826 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700827 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
828 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200829 }
830 if (mAppsCustomizeContent != null) {
831 mAppsCustomizeContent.setBulkBind(false);
832 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700833 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200834 if (DEBUG_RESUME_TIME) {
835 Log.d(TAG, "Time spent processing callbacks in onResume: " +
836 (System.currentTimeMillis() - startTimeCallbacks));
837 }
Michael Jurka447bf842013-05-15 14:52:15 +0200838 }
Michael Jurka54554252013-08-01 12:52:23 +0200839 if (mOnResumeCallbacks.size() > 0) {
840 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
841 mOnResumeCallbacks.get(i).run();
842 }
843 mOnResumeCallbacks.clear();
844 }
Winson Chunge4e50662012-01-23 14:45:13 -0800845
846 // Reset the pressed state of icons that were locked in the press state while activities
847 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800848 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800849 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800850 mWaitingForResume.setStayPressed(false);
851 }
Winson Chunge4e50662012-01-23 14:45:13 -0800852 if (mAppsCustomizeContent != null) {
853 // Resets the previous all apps icon press state
854 mAppsCustomizeContent.resetDrawableState();
855 }
Adam Cohen06dff352012-06-01 17:17:08 -0700856 // It is possible that widgets can receive updates while launcher is not in the foreground.
857 // Consequently, the widgets will be inflated in the orientation of the foreground activity
858 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
859 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700860 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700861
862 // Again, as with the above scenario, it's possible that one or more of the global icons
863 // were updated in the wrong orientation.
864 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200865 if (DEBUG_RESUME_TIME) {
866 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
867 }
Adam Cohen4caf2982013-08-20 18:54:31 -0700868
869 // Write all the logs to disk
870 Launcher.addDumpLog(TAG, "10249126 - onResume() - dumping logs to disk", true);
871 dumpLogsToLocalData(false);
Adam Cohen06dff352012-06-01 17:17:08 -0700872 }
873
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700875 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700876 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
877 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
878 // when Launcher resumes and we are still in AllApps.
879 updateWallpaperVisibility(true);
880
Winson Chung997a9232013-07-24 15:33:46 -0700881 // Ensure that items added to Launcher are queued until Launcher returns
882 InstallShortcutReceiver.enableInstallQueue();
883
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700884 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700885 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800886 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700887 mDragController.resetLastGestureUpTime();
Adam Cohen4caf2982013-08-20 18:54:31 -0700888
889 // Write all the logs to disk
890 Launcher.addDumpLog(TAG, "10249126 - onPause() - dumping logs to disk", true);
891 dumpLogsToLocalData(false);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700892 }
Romain Guycbb89e42009-06-08 15:52:54 -0700893
Adam Cohen66a01fd2013-06-11 12:48:00 -0700894 protected void onFinishBindingItems() {
895 }
896
Adam Cohenbffe7452013-07-22 18:21:45 -0700897 QSBScroller mQsbScroller = new QSBScroller() {
898 int scrollY = 0;
899
900 @Override
901 public void setScrollY(int scroll) {
902 scrollY = scroll;
903
904 if (mWorkspace.isOnOrMovingToCustomContent()) {
905 mSearchDropTargetBar.setTranslationY(- scrollY);
906 }
907 }
908 };
909
910 public void resetQSBScroll() {
911 mSearchDropTargetBar.animate().translationY(0).start();
912 }
913
914 public interface CustomContentCallbacks {
915 // Custom content is completely shown
916 public void onShow();
917
918 // Custom content is completely hidden
919 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700920
921 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
922 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700923 }
924
Adam Cohen30bacb22013-08-29 14:25:25 -0700925 protected void startSettings() {
926 }
927
Adam Cohenbffe7452013-07-22 18:21:45 -0700928 public interface QSBScroller {
929 public void setScrollY(int scrollY);
930 }
931
Adam Cohen66a01fd2013-06-11 12:48:00 -0700932 // Add a fullscreen unpadded view to the workspace to the left all other screens.
Winson Chung98ca0f72013-07-29 12:58:51 -0700933 public QSBScroller addToCustomContentPage(View customContent) {
934 return addToCustomContentPage(customContent, null);
Adam Cohenbffe7452013-07-22 18:21:45 -0700935 }
936
Winson Chung98ca0f72013-07-29 12:58:51 -0700937 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohenbffe7452013-07-22 18:21:45 -0700938 CustomContentCallbacks callbacks) {
Winson Chung98ca0f72013-07-29 12:58:51 -0700939 mWorkspace.addToCustomContentPage(customContent, callbacks);
Adam Cohenbffe7452013-07-22 18:21:45 -0700940 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700941 }
942
Adam Cohenedb40762013-07-18 16:45:45 -0700943 // The custom content needs to offset its content to account for the QSB
944 public int getTopOffsetForCustomContent() {
945 return mWorkspace.getPaddingTop();
946 }
947
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700948 @Override
949 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400950 // Flag the loader to stop early before switching
951 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700952 if (mAppsCustomizeContent != null) {
953 mAppsCustomizeContent.surrender();
954 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800955 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700956 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700957
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800958 // We can't hide the IME if it was forced open. So don't bother
959 /*
960 @Override
961 public void onWindowFocusChanged(boolean hasFocus) {
962 super.onWindowFocusChanged(hasFocus);
963
964 if (hasFocus) {
965 final InputMethodManager inputManager = (InputMethodManager)
966 getSystemService(Context.INPUT_METHOD_SERVICE);
967 WindowManager.LayoutParams lp = getWindow().getAttributes();
968 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
969 android.os.Handler()) {
970 protected void onReceiveResult(int resultCode, Bundle resultData) {
971 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
972 }
973 });
974 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
975 }
976 }
977 */
978
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800979 private boolean acceptFilter() {
980 final InputMethodManager inputManager = (InputMethodManager)
981 getSystemService(Context.INPUT_METHOD_SERVICE);
982 return !inputManager.isFullscreenMode();
983 }
984
985 @Override
986 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700987 final int uniChar = event.getUnicodeChar();
988 final boolean handled = super.onKeyDown(keyCode, event);
989 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
990 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800991 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
992 keyCode, event);
993 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700994 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700995 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700996 // showSearchDialog()
997 // If there are multiple keystrokes before the search dialog takes focus,
998 // onSearchRequested() will be called for every keystroke,
999 // but it is idempotent, so it's fine.
1000 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 }
1002 }
1003
Joe Onorato8a9625e2010-01-28 15:55:35 -08001004 // Eat the long press event so the keyboard doesn't come up.
1005 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1006 return true;
1007 }
1008
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001009 return handled;
1010 }
1011
Karl Rosaen138a0412009-04-23 19:00:21 -07001012 private String getTypedText() {
1013 return mDefaultKeySsb.toString();
1014 }
1015
1016 private void clearTypedText() {
1017 mDefaultKeySsb.clear();
1018 mDefaultKeySsb.clearSpans();
1019 Selection.setSelection(mDefaultKeySsb, 0);
1020 }
1021
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001023 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1024 * State
1025 */
1026 private static State intToState(int stateOrdinal) {
1027 State state = State.WORKSPACE;
1028 final State[] stateValues = State.values();
1029 for (int i = 0; i < stateValues.length; i++) {
1030 if (stateValues[i].ordinal() == stateOrdinal) {
1031 state = stateValues[i];
1032 break;
1033 }
1034 }
1035 return state;
1036 }
1037
1038 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001039 * Restores the previous state, if it exists.
1040 *
1041 * @param savedState The previous state.
1042 */
1043 private void restoreState(Bundle savedState) {
1044 if (savedState == null) {
1045 return;
1046 }
1047
Michael Jurka883f55b2010-10-21 15:47:14 -07001048 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001049 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001050 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001051 }
1052
Winson Chungf0c6ae02012-03-21 16:10:31 -07001053 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001054 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001055 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001056 }
1057
Winson Chung3d503fb2011-07-13 17:25:49 -07001058 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001059 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001060
Winson Chung3d503fb2011-07-13 17:25:49 -07001061 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1062 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001063 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001064 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1065 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001066 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1067 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1068 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001069 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001070 mRestoring = true;
1071 }
1072
1073 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1074 if (renameFolder) {
1075 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001076 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 mRestoring = true;
1078 }
Winson Chunga12a2502010-12-20 14:41:35 -08001079
Winson Chung785d2eb2011-04-14 16:08:02 -07001080 // Restore the AppsCustomize tab
1081 if (mAppsCustomizeTabHost != null) {
1082 String curTab = savedState.getString("apps_customize_currentTab");
1083 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001084 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001085 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001086 mAppsCustomizeContent.loadAssociatedPages(
1087 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001088 }
1089
Winson Chung5afbf7b2011-07-25 11:53:08 -07001090 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1091 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001092 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001093 }
1094
1095 /**
1096 * Finds all the views we need and configure them properly.
1097 */
1098 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001099 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001100
Craig Mautner360310b2012-10-26 15:13:08 -07001101 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001102 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1103 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001104
1105 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
1106 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107
Winson Chung4c98d922011-05-31 16:50:48 -07001108 // Setup the drag layer
1109 mDragLayer.setup(this, dragController);
1110
Winson Chung3d503fb2011-07-13 17:25:49 -07001111 // Setup the hotseat
1112 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1113 if (mHotseat != null) {
1114 mHotseat.setup(this);
1115 }
1116
Adam Cohenf358a4b2013-07-23 16:47:31 -07001117 mOverviewPanel = findViewById(R.id.overview_panel);
1118 findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
1119 @Override
1120 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001121 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001122 }
1123 });
1124 findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
1125 @Override
1126 public void onClick(View arg0) {
1127 startWallpaper();
1128 }
1129 });
Adam Cohen30bacb22013-08-29 14:25:25 -07001130 findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
1131 @Override
1132 public void onClick(View arg0) {
1133 startSettings();
1134 }
1135 });
Adam Cohenf358a4b2013-07-23 16:47:31 -07001136
Winson Chung4c98d922011-05-31 16:50:48 -07001137 // Setup the workspace
1138 mWorkspace.setHapticFeedbackEnabled(false);
1139 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001140 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001141 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001142
Winson Chungf0ea4d32011-06-06 14:27:16 -07001143 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001144 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001145
Winson Chungf0ea4d32011-06-06 14:27:16 -07001146 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001147 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001148 mAppsCustomizeContent = (AppsCustomizePagedView)
1149 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1150 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001151
Winson Chung3d503fb2011-07-13 17:25:49 -07001152 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001153 dragController.setDragScoller(mWorkspace);
1154 dragController.setScrollView(mDragLayer);
1155 dragController.setMoveTarget(mWorkspace);
1156 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001157 if (mSearchDropTargetBar != null) {
1158 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001159 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001160
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001161 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001162 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001163 mWeightWatcher = new WeightWatcher(this);
1164 mWeightWatcher.setAlpha(0.5f);
1165 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001166 new FrameLayout.LayoutParams(
1167 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001168 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001169 Gravity.BOTTOM)
1170 );
Adam Cohen39a06042013-07-19 14:30:12 -07001171
1172 boolean show = shouldShowWeightWatcher();
1173 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001174 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 }
1176
1177 /**
1178 * Creates a view representing a shortcut.
1179 *
1180 * @param info The data structure describing the shortcut.
1181 *
1182 * @return A View inflated from R.layout.application.
1183 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001184 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001186 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001187 }
1188
1189 /**
1190 * Creates a view representing a shortcut inflated from the specified resource.
1191 *
1192 * @param layoutResId The id of the XML layout used to create the shortcut.
1193 * @param parent The group the shortcut belongs to.
1194 * @param info The data structure describing the shortcut.
1195 *
1196 * @return A View inflated from layoutResId.
1197 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001198 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001199 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1200 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 return favorite;
1203 }
1204
1205 /**
1206 * Add an application shortcut to the workspace.
1207 *
1208 * @param data The intent describing the application.
1209 * @param cellInfo The position on screen where to create the shortcut.
1210 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001211 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001212 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001213 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001214
Adam Cohenfbba09b2011-07-18 21:43:05 -07001215 // First we check if we already know the exact location where we want to add this item.
1216 if (cellX >= 0 && cellY >= 0) {
1217 cellXY[0] = cellX;
1218 cellXY[1] = cellY;
1219 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001220 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001221 return;
1222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001224 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001225
Romain Guy73b979d2009-06-09 12:57:21 -07001226 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001227 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001229 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001230 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001231 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001232 } else {
1233 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234 }
1235 }
Romain Guycbb89e42009-06-08 15:52:54 -07001236
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 /**
1238 * Add a shortcut to the workspace.
1239 *
1240 * @param data The intent describing the shortcut.
1241 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001242 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001243 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001244 int cellY) {
1245 int[] cellXY = mTmpAddItemCellCoordinates;
1246 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001247 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001248
Michael Jurkad3ef3062010-11-23 16:23:58 -08001249 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001250
Adam Cohen558baaf2011-08-15 15:22:57 -07001251 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001252 if (info == null) {
1253 return;
1254 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001255 final View view = createShortcut(info);
1256
Adam Cohenfbba09b2011-07-18 21:43:05 -07001257 // First we check if we already know the exact location where we want to add this item.
1258 if (cellX >= 0 && cellY >= 0) {
1259 cellXY[0] = cellX;
1260 cellXY[1] = cellY;
1261 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001262
1263 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001264 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001265 true, null,null)) {
1266 return;
1267 }
1268 DragObject dragObject = new DragObject();
1269 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001270 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1271 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001272 return;
1273 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001274 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001275 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001276 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001277 foundCellSpan = (result != null);
1278 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001279 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001280 }
1281
1282 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001283 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001284 return;
1285 }
1286
Adam Cohendcd297f2013-06-18 13:13:40 -07001287 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288
1289 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001290 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001291 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001292 }
1293 }
1294
Adam Cohen2f093b62012-04-30 18:59:53 -07001295 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1296 int minHeight) {
1297 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001298 // We want to account for the extra amount of padding that we are adding to the widget
1299 // to ensure that it gets the full amount of space that it has requested
1300 int requiredWidth = minWidth + padding.left + padding.right;
1301 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001302 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001303 }
1304
Adam Cohen2f093b62012-04-30 18:59:53 -07001305 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1306 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001307 }
1308
Adam Cohen2f093b62012-04-30 18:59:53 -07001309 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1310 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001311 }
1312
Adam Cohen2f093b62012-04-30 18:59:53 -07001313 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1314 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001315 }
1316
Adam Cohen2f093b62012-04-30 18:59:53 -07001317 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1318 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001319 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001320 }
1321
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001323 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001325 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001326 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001327 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001328 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001329 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1330 if (appWidgetInfo == null) {
1331 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1332 }
Romain Guycbb89e42009-06-08 15:52:54 -07001333
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001334 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001335 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001336
Adam Cohen2f093b62012-04-30 18:59:53 -07001337 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1338 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001339
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001340 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001341 // We have saved the position to which the widget was dragged-- this really only matters
1342 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001343 int[] cellXY = mTmpAddItemCellCoordinates;
1344 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001345 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001346 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001347 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1348 cellXY[0] = mPendingAddInfo.cellX;
1349 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001350 spanXY[0] = mPendingAddInfo.spanX;
1351 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001352 foundCellSpan = true;
1353 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001354 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001355 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001356 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1357 spanXY[1], cellXY, finalSpan);
1358 spanXY[0] = finalSpan[0];
1359 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001360 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001361 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001362 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001363 }
1364
Michael Jurka0280c3b2010-09-17 15:00:07 -07001365 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001366 if (appWidgetId != -1) {
1367 // Deleting an app widget ID is a void call but writes to disk before returning
1368 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001369 new Thread("deleteAppWidgetId") {
1370 public void run() {
1371 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1372 }
1373 }.start();
1374 }
Winson Chung93eef082012-03-23 15:59:27 -07001375 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001376 return;
1377 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001379 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001380 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1381 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001382 launcherInfo.spanX = spanXY[0];
1383 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001384 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1385 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001386
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001387 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001388 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389
1390 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001391 if (hostView == null) {
1392 // Perform actual inflation because we're live
1393 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1394 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1395 } else {
1396 // The AppWidgetHostView has already been inflated and instantiated
1397 launcherInfo.hostView = hostView;
1398 }
Romain Guycbb89e42009-06-08 15:52:54 -07001399
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001400 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001401 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001402 launcherInfo.notifyWidgetSizeChanged(this);
1403
Adam Cohendcd297f2013-06-18 13:13:40 -07001404 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001405 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001406
1407 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001409 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 }
Romain Guycbb89e42009-06-08 15:52:54 -07001411
Adam Cohended9f8d2010-11-03 13:25:16 -07001412 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1413 @Override
1414 public void onReceive(Context context, Intent intent) {
1415 final String action = intent.getAction();
1416 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1417 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001418 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001419 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001420
Winson Chungc100e8e2011-08-09 16:02:43 -07001421 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001422 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001423 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1424 mAppsCustomizeTabHost.reset();
1425 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001426 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001427 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1428 mUserPresent = true;
1429 updateRunning();
1430 }
1431 }
1432 };
1433
1434 @Override
1435 public void onAttachedToWindow() {
1436 super.onAttachedToWindow();
1437
1438 // Listen for broadcasts related to user-presence
1439 final IntentFilter filter = new IntentFilter();
1440 filter.addAction(Intent.ACTION_SCREEN_OFF);
1441 filter.addAction(Intent.ACTION_USER_PRESENT);
1442 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001443 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001444 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001445 mVisible = true;
1446 }
1447
1448 @Override
1449 public void onDetachedFromWindow() {
1450 super.onDetachedFromWindow();
1451 mVisible = false;
1452
Adam Cohend113e0c2010-11-11 10:48:05 -08001453 if (mAttached) {
1454 unregisterReceiver(mReceiver);
1455 mAttached = false;
1456 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001457 updateRunning();
1458 }
1459
1460 public void onWindowVisibilityChanged(int visibility) {
1461 mVisible = visibility == View.VISIBLE;
1462 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001463 // The following code used to be in onResume, but it turns out onResume is called when
1464 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1465 // is a more appropriate event to handle
1466 if (mVisible) {
1467 mAppsCustomizeTabHost.onWindowVisible();
1468 if (!mWorkspaceLoading) {
1469 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001470 // We want to let Launcher draw itself at least once before we force it to build
1471 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001472 // apps is nice and speedy.
1473 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001474 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001475 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001476 if (mStarted) return;
1477 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001478 // We delay the layer building a bit in order to give
1479 // other message processing a time to run. In particular
1480 // this avoids a delay in hiding the IME if it was
1481 // currently shown, because doing that may involve
1482 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001483 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001484 final ViewTreeObserver.OnDrawListener listener = this;
1485 mWorkspace.post(new Runnable() {
1486 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001487 if (mWorkspace != null &&
1488 mWorkspace.getViewTreeObserver() != null) {
1489 mWorkspace.getViewTreeObserver().
1490 removeOnDrawListener(listener);
1491 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001492 }
1493 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001494 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001495 }
1496 });
1497 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001498 // When Launcher comes back to foreground, a different Activity might be responsible for
1499 // the app market intent, so refresh the icon
1500 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001501 clearTypedText();
1502 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001503 }
1504
1505 private void sendAdvanceMessage(long delay) {
1506 mHandler.removeMessages(ADVANCE_MSG);
1507 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1508 mHandler.sendMessageDelayed(msg, delay);
1509 mAutoAdvanceSentTime = System.currentTimeMillis();
1510 }
1511
1512 private void updateRunning() {
1513 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1514 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1515 mAutoAdvanceRunning = autoAdvanceRunning;
1516 if (autoAdvanceRunning) {
1517 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1518 sendAdvanceMessage(delay);
1519 } else {
1520 if (!mWidgetsToAdvance.isEmpty()) {
1521 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1522 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1523 }
1524 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001525 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001526 }
1527 }
1528 }
1529
1530 private final Handler mHandler = new Handler() {
1531 @Override
1532 public void handleMessage(Message msg) {
1533 if (msg.what == ADVANCE_MSG) {
1534 int i = 0;
1535 for (View key: mWidgetsToAdvance.keySet()) {
1536 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1537 final int delay = mAdvanceStagger * i;
1538 if (v instanceof Advanceable) {
1539 postDelayed(new Runnable() {
1540 public void run() {
1541 ((Advanceable) v).advance();
1542 }
1543 }, delay);
1544 }
1545 i++;
1546 }
1547 sendAdvanceMessage(mAdvanceInterval);
1548 }
1549 }
1550 };
1551
1552 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001553 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001554 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1555 if (v instanceof Advanceable) {
1556 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001557 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001558 updateRunning();
1559 }
1560 }
1561
1562 void removeWidgetToAutoAdvance(View hostView) {
1563 if (mWidgetsToAdvance.containsKey(hostView)) {
1564 mWidgetsToAdvance.remove(hostView);
1565 updateRunning();
1566 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001567 }
1568
Joe Onorato9c1289c2009-08-17 11:03:03 -04001569 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001570 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 launcherInfo.hostView = null;
1572 }
1573
Winson Chung93eef082012-03-23 15:59:27 -07001574 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1575 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1576 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001577 }
1578
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001579 public LauncherAppWidgetHost getAppWidgetHost() {
1580 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001581 }
Romain Guycbb89e42009-06-08 15:52:54 -07001582
Winson Chunga9abd0e2010-10-27 17:18:37 -07001583 public LauncherModel getModel() {
1584 return mModel;
1585 }
1586
Bjorn Bringertc459e522013-06-07 19:36:01 +01001587 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001588 getWindow().closeAllPanels();
1589
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001590 // Whatever we were doing is hereby canceled.
1591 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001592 }
1593
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 @Override
1595 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001596 long startTime = 0;
1597 if (DEBUG_RESUME_TIME) {
1598 startTime = System.currentTimeMillis();
1599 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001600 super.onNewIntent(intent);
1601
1602 // Close the menu
1603 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001604 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001605 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001606
Jamie Genniscb222e82012-10-23 15:44:26 -07001607 final boolean alreadyOnHome =
1608 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001609 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001610
Jamie Genniscb222e82012-10-23 15:44:26 -07001611 Runnable processIntent = new Runnable() {
1612 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001613 if (mWorkspace == null) {
1614 // Can be cases where mWorkspace is null, this prevents a NPE
1615 return;
1616 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001617 Folder openFolder = mWorkspace.getOpenFolder();
1618 // In all these cases, only animate if we're already on home
1619 mWorkspace.exitWidgetResizeMode();
1620 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1621 openFolder == null) {
1622 mWorkspace.moveToDefaultScreen(true);
1623 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001624
Jamie Genniscb222e82012-10-23 15:44:26 -07001625 closeFolder();
1626 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001627
Jamie Genniscb222e82012-10-23 15:44:26 -07001628 // If we are already on home, then just animate back to the workspace,
1629 // otherwise, just wait until onResume to set the state back to Workspace
1630 if (alreadyOnHome) {
1631 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001632 if (mWorkspace.isInOverviewMode()) {
1633 mWorkspace.exitOverviewMode();
1634 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001635 } else {
1636 mOnResumeState = State.WORKSPACE;
1637 }
1638
1639 final View v = getWindow().peekDecorView();
1640 if (v != null && v.getWindowToken() != null) {
1641 InputMethodManager imm = (InputMethodManager)getSystemService(
1642 INPUT_METHOD_SERVICE);
1643 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1644 }
1645
1646 // Reset AllApps to its initial state
1647 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1648 mAppsCustomizeTabHost.reset();
1649 }
1650 }
1651 };
1652
1653 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1654 // Delay processing of the intent to allow the status bar animation to finish
1655 // first in order to avoid janky animations.
1656 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001657 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001658 // Process the intent immediately.
1659 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001660 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001661
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001662 }
Michael Jurka447bf842013-05-15 14:52:15 +02001663 if (DEBUG_RESUME_TIME) {
1664 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1665 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001666 }
1667
1668 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001669 public void onRestoreInstanceState(Bundle state) {
1670 super.onRestoreInstanceState(state);
1671 for (int page: mSynchronouslyBoundPages) {
1672 mWorkspace.restoreInstanceStateForChild(page);
1673 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001674 }
1675
1676 @Override
1677 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001678 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001679 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001680
Michael Jurka883f55b2010-10-21 15:47:14 -07001681 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001682 // We close any open folder since it will not be re-opened, and we need to make sure
1683 // this state is reflected.
1684 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001685
Adam Cohendcd297f2013-06-18 13:13:40 -07001686 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001687 mWaitingForResult) {
1688 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001689 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001690 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1691 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001692 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1693 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1694 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001695 }
1696
1697 if (mFolderInfo != null && mWaitingForResult) {
1698 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1699 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1700 }
Michael Jurka946ad472010-07-09 18:05:18 -07001701
Winson Chung785d2eb2011-04-14 16:08:02 -07001702 // Save the current AppsCustomize tab
1703 if (mAppsCustomizeTabHost != null) {
1704 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1705 if (currentTabTag != null) {
1706 outState.putString("apps_customize_currentTab", currentTabTag);
1707 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001708 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1709 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001710 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
1712
1713 @Override
1714 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001716
Winson Chunge7a03942011-08-05 15:05:12 -07001717 // Remove all pending runnables
1718 mHandler.removeMessages(ADVANCE_MSG);
1719 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001720 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001721
Winson Chungcd2b0142011-06-08 16:02:26 -07001722 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001723 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001724 mModel.stopLoader();
1725 app.setLauncher(null);
1726
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001728 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001730 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001731 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001732 mAppWidgetHost = null;
1733
1734 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735
1736 TextKeyListener.getInstance().release();
1737
Winson Chung81b52252012-08-27 15:34:29 -07001738 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1739 // to prevent leaking Launcher activities on orientation change.
1740 if (mModel != null) {
1741 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1742 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001743
1744 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001745 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001746
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001747 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001748 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1749 mWorkspace.removeAllViews();
1750 mWorkspace = null;
1751 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001752
Michael Jurka2ecf9952012-06-18 12:52:28 -07001753 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001754 }
1755
Adam Cohena9cf38f2011-05-02 15:36:58 -07001756 public DragController getDragController() {
1757 return mDragController;
1758 }
1759
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001760 @Override
1761 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001762 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001763 super.startActivityForResult(intent, requestCode);
1764 }
1765
Winson Chung70d72102011-08-12 11:24:35 -07001766 /**
1767 * Indicates that we want global search for this activity by setting the globalSearch
1768 * argument for {@link #startSearch} to true.
1769 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001770 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001771 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001773
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001774 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001775
Karl Rosaen138a0412009-04-23 19:00:21 -07001776 if (initialQuery == null) {
1777 // Use any text typed in the launcher as the initial query
1778 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001779 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001780 if (appSearchData == null) {
1781 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001782 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 }
Winson Chungadf0c182012-08-23 14:59:07 -07001784 Rect sourceBounds = new Rect();
1785 if (mSearchDropTargetBar != null) {
1786 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1787 }
Romain Guycbb89e42009-06-08 15:52:54 -07001788
Bjorn Bringertc459e522013-06-07 19:36:01 +01001789 startSearch(initialQuery, selectInitialQuery,
1790 appSearchData, sourceBounds);
1791 }
1792
1793 public void startSearch(String initialQuery,
1794 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001795 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001796 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001797 }
1798
1799 /**
1800 * Starts the global search activity. This code is a copied from SearchManager
1801 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001802 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001803 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001804 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001805 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1806 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1807 if (globalSearchActivity == null) {
1808 Log.w(TAG, "No global search activity found.");
1809 return;
1810 }
1811 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1812 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1813 intent.setComponent(globalSearchActivity);
1814 // Make sure that we have a Bundle to put source in
1815 if (appSearchData == null) {
1816 appSearchData = new Bundle();
1817 } else {
1818 appSearchData = new Bundle(appSearchData);
1819 }
1820 // Set source to package name of app that starts global search, if not set already.
1821 if (!appSearchData.containsKey("source")) {
1822 appSearchData.putString("source", getPackageName());
1823 }
1824 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1825 if (!TextUtils.isEmpty(initialQuery)) {
1826 intent.putExtra(SearchManager.QUERY, initialQuery);
1827 }
1828 if (selectInitialQuery) {
1829 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1830 }
1831 intent.setSourceBounds(sourceBounds);
1832 try {
1833 startActivity(intent);
1834 } catch (ActivityNotFoundException ex) {
1835 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1836 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 }
1838
Winson Chung70d72102011-08-12 11:24:35 -07001839 @Override
1840 public boolean onCreateOptionsMenu(Menu menu) {
1841 if (isWorkspaceLocked()) {
1842 return false;
1843 }
1844
1845 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001846
1847 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1848 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1849 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001850 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1851 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1852 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001853 String helpUrl = getString(R.string.help_url);
1854 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001855 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1856 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1857
Winson Chung70d72102011-08-12 11:24:35 -07001858 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1859 .setIcon(android.R.drawable.ic_menu_gallery)
1860 .setAlphabeticShortcut('W');
1861 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1862 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001863 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001864 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001865 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1866 .setIcon(android.R.drawable.ic_menu_preferences)
1867 .setIntent(settings)
1868 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001869 if (!helpUrl.isEmpty()) {
1870 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1871 .setIcon(android.R.drawable.ic_menu_help)
1872 .setIntent(help)
1873 .setAlphabeticShortcut('H');
1874 }
Winson Chung70d72102011-08-12 11:24:35 -07001875 return true;
1876 }
1877
1878 @Override
1879 public boolean onPrepareOptionsMenu(Menu menu) {
1880 super.onPrepareOptionsMenu(menu);
1881
1882 if (mAppsCustomizeTabHost.isTransitioning()) {
1883 return false;
1884 }
1885 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1886 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1887
1888 return true;
1889 }
1890
1891 @Override
1892 public boolean onOptionsItemSelected(MenuItem item) {
1893 switch (item.getItemId()) {
1894 case MENU_WALLPAPER_SETTINGS:
1895 startWallpaper();
1896 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001897 }
1898
1899 return super.onOptionsItemSelected(item);
1900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001901
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001902 @Override
1903 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001904 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001905 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001906 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001907 }
1908
Joe Onorato9c1289c2009-08-17 11:03:03 -04001909 public boolean isWorkspaceLocked() {
1910 return mWorkspaceLoading || mWaitingForResult;
1911 }
1912
Michael Jurka0280c3b2010-09-17 15:00:07 -07001913 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001914 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001915 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001916 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1917 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001918 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001919 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001920 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001921
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001922 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1923 AppWidgetProviderInfo appWidgetInfo) {
1924 if (appWidgetInfo.configure != null) {
1925 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001926
Bjorn Bringert7984c942009-12-09 15:38:25 +00001927 // Launch over to configure widget, if needed
1928 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001929 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001930 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001931 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001933 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001934 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001935 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001936 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001937 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001938 }
1939 }
Romain Guycbb89e42009-06-08 15:52:54 -07001940
Adam Cohenfbba09b2011-07-18 21:43:05 -07001941 /**
1942 * Process a shortcut drop.
1943 *
1944 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001945 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001946 * @param cell The cell it should be added to, optional
1947 * @param position The location on the screen where it was dropped, optional
1948 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001949 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001950 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001951 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001952 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001953 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001954 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001955
1956 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001957 mPendingAddInfo.cellX = cell[0];
1958 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001959 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001960
1961 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1962 createShortcutIntent.setComponent(componentName);
1963 processShortcut(createShortcutIntent);
1964 }
1965
Adam Cohenfbba09b2011-07-18 21:43:05 -07001966 /**
1967 * Process a widget drop.
1968 *
1969 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001970 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001971 * @param cell The cell it should be added to, optional
1972 * @param position The location on the screen where it was dropped, optional
1973 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001974 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001975 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001976 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001977 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001978 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001979 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001980 mPendingAddInfo.minSpanX = info.minSpanX;
1981 mPendingAddInfo.minSpanY = info.minSpanY;
1982
Adam Cohenfbba09b2011-07-18 21:43:05 -07001983 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001984 mPendingAddInfo.cellX = cell[0];
1985 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001986 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001987 if (span != null) {
1988 mPendingAddInfo.spanX = span[0];
1989 mPendingAddInfo.spanY = span[1];
1990 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001991
Adam Cohened66b2b2012-01-23 17:28:51 -08001992 AppWidgetHostView hostView = info.boundWidget;
1993 int appWidgetId;
1994 if (hostView != null) {
1995 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001996 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001997 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001998 // In this case, we either need to start an activity to get permission to bind
1999 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002000 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002001 Bundle options = info.bindOptions;
2002
2003 boolean success = false;
2004 if (options != null) {
2005 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2006 info.componentName, options);
2007 } else {
2008 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2009 info.componentName);
2010 }
2011 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002012 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002013 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002014 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002015 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2016 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2017 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002018 // TODO: we need to make sure that this accounts for the options bundle.
2019 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002020 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2021 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002022 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002023 }
2024
Joe Onoratodeb98af2010-02-19 14:59:39 -08002025 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002026 // Handle case where user selected "Applications"
2027 String applicationName = getResources().getString(R.string.group_applications);
2028 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002029
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002030 if (applicationName != null && applicationName.equals(shortcutName)) {
2031 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2032 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002033
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002034 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2035 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002036 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002037 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002038 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002039 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002040 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002041 }
2042
Winson Chung24ab2f12010-09-16 14:10:47 -07002043 void processWallpaper(Intent intent) {
2044 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2045 }
2046
Adam Cohendcd297f2013-06-18 13:13:40 -07002047 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002048 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002049 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 folderInfo.title = getText(R.string.folder_name);
2051
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002052 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002053 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002054 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002055 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056
2057 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002058 FolderIcon newFolder =
2059 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002060 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002061 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002062 // Force measure the new folder icon
2063 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2064 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002065 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002066 }
Romain Guycbb89e42009-06-08 15:52:54 -07002067
Joe Onorato9c1289c2009-08-17 11:03:03 -04002068 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002069 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002070 }
2071
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002072 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002073 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002075 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002076 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 }
2078
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002079 protected ComponentName getWallpaperPickerComponent() {
2080 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2081 }
2082
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002083 /**
2084 * Registers various content observers. The current implementation registers
2085 * only a favorites observer to keep track of the favorites applications.
2086 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002087 private void registerContentObservers() {
2088 ContentResolver resolver = getContentResolver();
2089 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2090 true, mWidgetObserver);
2091 }
2092
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002093 @Override
2094 public boolean dispatchKeyEvent(KeyEvent event) {
2095 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2096 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002097 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002098 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002099 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002100 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002101 dumpState();
2102 return true;
2103 }
2104 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002105 }
2106 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2107 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002108 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002109 return true;
2110 }
2111 }
2112
2113 return super.dispatchKeyEvent(event);
2114 }
2115
Joe Onorato88ec0992009-11-19 13:16:06 -08002116 @Override
2117 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002118 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002119 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002120 } else if (mWorkspace.isInOverviewMode()) {
2121 mWorkspace.exitOverviewMode();
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002122 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002123 Folder openFolder = mWorkspace.getOpenFolder();
2124 if (openFolder.isEditingName()) {
2125 openFolder.dismissEditingName();
2126 } else {
2127 closeFolder();
2128 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002129 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002130 mWorkspace.exitWidgetResizeMode();
2131
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002132 // Back button is a no-op here, but give at least some feedback for the button press
2133 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002134 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002135 }
2136
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002137 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002138 * Re-listen when widgets are reset.
2139 */
2140 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002141 if (mAppWidgetHost != null) {
2142 mAppWidgetHost.startListening();
2143 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002144 }
2145
2146 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002147 * Launches the intent referred by the clicked shortcut.
2148 *
2149 * @param v The view representing the clicked shortcut.
2150 */
2151 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002152 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2153 // view has detached (it's possible for this to happen if the view is removed mid touch).
2154 if (v.getWindowToken() == null) {
2155 return;
2156 }
2157
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002158 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002159 return;
2160 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002161
Adam Cohenf358a4b2013-07-23 16:47:31 -07002162 if (v instanceof PageIndicator) {
2163 if (!mWorkspace.isInOverviewMode()) {
2164 mWorkspace.enterOverviewMode();
2165 }
2166 return;
2167 }
2168
2169 if (v instanceof CellLayout) {
2170 if (mWorkspace.isInOverviewMode()) {
2171 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v));
2172 }
2173 }
2174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002175 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002176 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002178 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2179 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002180
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002181 // Check for special shortcuts
2182 if (intent.getComponent() != null) {
2183 final String shortcutClass = intent.getComponent().getClassName();
2184
2185 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002186 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002187 return;
2188 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2189 MemoryDumpActivity.startDump(this);
2190 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002191 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2192 toggleShowWeightWatcher();
2193 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002194 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002195 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002196
2197 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002198 int[] pos = new int[2];
2199 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002200 intent.setSourceBounds(new Rect(pos[0], pos[1],
2201 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002202
2203 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002204
Daniel Sandlerff02d492013-08-05 02:12:05 -04002205 mStats.recordLaunch(intent, shortcut);
2206
Michael Jurkaddd62e92011-02-16 17:49:14 -08002207 if (success && v instanceof BubbleTextView) {
2208 mWaitingForResume = (BubbleTextView) v;
2209 mWaitingForResume.setStayPressed(true);
2210 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002211 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002212 if (v instanceof FolderIcon) {
2213 FolderIcon fi = (FolderIcon) v;
2214 handleFolderClick(fi);
2215 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002216 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002217 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002218 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002219 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002220 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002221 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002222 }
2223 }
2224
Michael Jurka0e260592010-06-30 17:07:39 -07002225 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002226 return false;
2227 }
2228
Michael Jurkaaf442092010-06-10 17:01:57 -07002229 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002230 * Event handler for the search button
2231 *
2232 * @param v The view that was clicked.
2233 */
2234 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002235 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2236
Amith Yamasania135ba82011-08-09 17:42:01 -07002237 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002238 }
2239
2240 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002241 * Event handler for the voice button
2242 *
2243 * @param v The view that was clicked.
2244 */
2245 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002246 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002247
Bjorn Bringertc459e522013-06-07 19:36:01 +01002248 startVoice();
2249 }
2250
2251 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002252 try {
2253 final SearchManager searchManager =
2254 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2255 ComponentName activityName = searchManager.getGlobalSearchActivity();
2256 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002257 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002258 if (activityName != null) {
2259 intent.setPackage(activityName.getPackageName());
2260 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002261 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002262 } catch (ActivityNotFoundException e) {
2263 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002264 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002265 startActivitySafely(null, intent, "onClickVoiceButton");
2266 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002267 }
2268
2269 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002270 * Event handler for the "grid" button that appears on the home screen, which
2271 * enters all apps mode.
2272 *
2273 * @param v The view that was clicked.
2274 */
2275 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002276 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002277 }
2278
2279 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002280 // Provide the same haptic feedback that the system offers for virtual keys.
2281 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002282 }
2283
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002284 public void onClickAppMarketButton(View v) {
2285 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002286 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002287 } else {
2288 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002289 }
2290 }
2291
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002292 void startApplicationDetailsActivity(ComponentName componentName) {
2293 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002294 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2295 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002296 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002297 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002298 }
2299
Michael Jurka1e2f4652013-07-08 18:03:46 -07002300 // returns true if the activity was started
2301 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002302 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002303 // System applications cannot be installed. For now, show a toast explaining that.
2304 // We may give them the option of disabling apps this way.
2305 int messageId = R.string.uninstall_system_app_text;
2306 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002307 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002308 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002309 String packageName = componentName.getPackageName();
2310 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002311 Intent intent = new Intent(
2312 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002313 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2314 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002315 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002316 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002317 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002318 }
2319
Michael Jurka86a720e2012-05-09 11:23:23 -07002320 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002321 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002322
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002323 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002324 // Only launch using the new animation if the shortcut has not opted out (this is a
2325 // private contract between launcher and may be ignored in the future).
2326 boolean useLaunchAnimation = (v != null) &&
2327 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2328 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002329 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2330 v.getMeasuredWidth(), v.getMeasuredHeight());
2331
2332 startActivity(intent, opts.toBundle());
2333 } else {
2334 startActivity(intent);
2335 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002336 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002337 } catch (SecurityException e) {
2338 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002339 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002341 "or use the exported attribute for this activity. "
2342 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002343 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002344 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002345 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002346
Michael Jurka86a720e2012-05-09 11:23:23 -07002347 boolean startActivitySafely(View v, Intent intent, Object tag) {
2348 boolean success = false;
2349 try {
2350 success = startActivity(v, intent, tag);
2351 } catch (ActivityNotFoundException e) {
2352 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2353 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2354 }
2355 return success;
2356 }
2357
Adam Cohena9cf38f2011-05-02 15:36:58 -07002358 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002359 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002360 Folder openFolder = mWorkspace.getFolderForTag(info);
2361
2362 // If the folder info reports that the associated folder is open, then verify that
2363 // it is actually opened. There have been a few instances where this gets out of sync.
2364 if (info.opened && openFolder == null) {
2365 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002366 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002367 info.opened = false;
2368 }
2369
Adam Cohenfb91f302012-06-11 15:45:18 -07002370 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 // Close any open folder
2372 closeFolder();
2373 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002374 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 } else {
2376 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002377 int folderScreen;
2378 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002379 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002380 // .. and close it
2381 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002382 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002383 // Close any folder open on the current screen
2384 closeFolder();
2385 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002386 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 }
2388 }
2389 }
2390 }
2391
Adam Cohen268c4752012-06-06 17:47:33 -07002392 /**
2393 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2394 * in the DragLayer in the exact absolute location of the original FolderIcon.
2395 */
2396 private void copyFolderIconToImage(FolderIcon fi) {
2397 final int width = fi.getMeasuredWidth();
2398 final int height = fi.getMeasuredHeight();
2399
2400 // Lazy load ImageView, Bitmap and Canvas
2401 if (mFolderIconImageView == null) {
2402 mFolderIconImageView = new ImageView(this);
2403 }
2404 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2405 mFolderIconBitmap.getHeight() != height) {
2406 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2407 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2408 }
2409
2410 DragLayer.LayoutParams lp;
2411 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2412 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2413 } else {
2414 lp = new DragLayer.LayoutParams(width, height);
2415 }
2416
Adam Cohen307fe232012-08-16 17:55:58 -07002417 // The layout from which the folder is being opened may be scaled, adjust the starting
2418 // view size by this scale factor.
2419 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002420 lp.customPosition = true;
2421 lp.x = mRectForFolderAnimation.left;
2422 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002423 lp.width = (int) (scale * width);
2424 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002425
2426 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2427 fi.draw(mFolderIconCanvas);
2428 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002429 if (fi.getFolder() != null) {
2430 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2431 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002432 }
Adam Cohen268c4752012-06-06 17:47:33 -07002433 // Just in case this image view is still in the drag layer from a previous animation,
2434 // we remove it and re-add it.
2435 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2436 mDragLayer.removeView(mFolderIconImageView);
2437 }
2438 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002439 if (fi.getFolder() != null) {
2440 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002441 }
Adam Cohen268c4752012-06-06 17:47:33 -07002442 }
2443
Adam Cohen2801caf2011-05-13 20:57:39 -07002444 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002445 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002446 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2447 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2448 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2449
Adam Cohenc51934b2011-07-26 21:07:43 -07002450 FolderInfo info = (FolderInfo) fi.getTag();
2451 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2452 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002453 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2454 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002455 }
2456
Adam Cohen268c4752012-06-06 17:47:33 -07002457 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2458 copyFolderIconToImage(fi);
2459 fi.setVisibility(View.INVISIBLE);
2460
Michael Jurka2ecf9952012-06-18 12:52:28 -07002461 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002462 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002463 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2464 oa.start();
2465 }
2466
Adam Cohen268c4752012-06-06 17:47:33 -07002467 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002468 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002469 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2470 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2471 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2472
Adam Cohen268c4752012-06-06 17:47:33 -07002473 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002474
Adam Cohen268c4752012-06-06 17:47:33 -07002475 // We remove and re-draw the FolderIcon in-case it has changed
2476 mDragLayer.removeView(mFolderIconImageView);
2477 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002478 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002479 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002480 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002481 oa.addListener(new AnimatorListenerAdapter() {
2482 @Override
2483 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002484 if (cl != null) {
2485 cl.clearFolderLeaveBehind();
2486 // Remove the ImageView copy of the FolderIcon and make the original visible.
2487 mDragLayer.removeView(mFolderIconImageView);
2488 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002489 }
2490 }
2491 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002492 oa.start();
2493 }
2494
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002495 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002496 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002497 * is animated relative to the specified View. If the View is null, no animation
2498 * is played.
2499 *
2500 * @param folderInfo The FolderInfo describing the folder to open.
2501 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002502 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002503 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002504 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002505
Adam Cohena9cf38f2011-05-02 15:36:58 -07002506 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002507
Adam Cohen4554ee12011-08-03 16:13:21 -07002508 // Just verify that the folder hasn't already been added to the DragLayer.
2509 // There was a one-off crash where the folder had a parent already.
2510 if (folder.getParent() == null) {
2511 mDragLayer.addView(folder);
2512 mDragController.addDropTarget((DropTarget) folder);
2513 } else {
2514 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2515 folder.getParent() + ").");
2516 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002517 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002518 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002519
2520 // Notify the accessibility manager that this folder "window" has appeared and occluded
2521 // the workspace items
2522 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2523 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002524 }
2525
2526 public void closeFolder() {
2527 Folder folder = mWorkspace.getOpenFolder();
2528 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002529 if (folder.isEditingName()) {
2530 folder.dismissEditingName();
2531 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002532 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002533
2534 // Dismiss the folder cling
2535 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002536 }
2537 }
2538
2539 void closeFolder(Folder folder) {
2540 folder.getInfo().opened = false;
2541
2542 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2543 if (parent != null) {
2544 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2545 shrinkAndFadeInFolderIcon(fi);
2546 }
2547 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002548
2549 // Notify the accessibility manager that this folder "window" has disappeard and no
2550 // longer occludeds the workspace items
2551 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552 }
2553
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002554 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002555 if (!isDraggingEnabled()) return false;
2556 if (isWorkspaceLocked()) return false;
2557 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002558
2559 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002560 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002561 }
2562
Michael Jurka0280c3b2010-09-17 15:00:07 -07002563 resetAddInfo();
2564 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002565 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002566 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002567 return true;
2568 }
2569
Winson Chung3d503fb2011-07-13 17:25:49 -07002570 // The hotseat touch handling does not go through Workspace, and we always allow long press
2571 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002572 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002573 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2574 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002575 if (itemUnderLongClick == null) {
Winson Chung0e6a7132013-08-23 12:55:10 -07002576 if (mWorkspace.hasNonCustomEmptyScreens()) {
2577 // User long pressed on empty space
2578 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2579 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2580 // Disabling reordering until we sort out some issues.
2581 if (mWorkspace.isInOverviewMode()) {
2582 mWorkspace.startReordering(v);
2583 } else {
2584 mWorkspace.enterOverviewMode();
2585 }
Adam Cohendedbd962013-07-11 14:21:49 -07002586 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002587 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002588 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002589 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002590 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 }
2592 }
2593 }
2594 return true;
2595 }
2596
Winson Chung3d503fb2011-07-13 17:25:49 -07002597 boolean isHotseatLayout(View layout) {
2598 return mHotseat != null && layout != null &&
2599 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2600 }
2601 Hotseat getHotseat() {
2602 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002603 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002604 View getOverviewPanel() {
2605 return mOverviewPanel;
2606 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002607 SearchDropTargetBar getSearchBar() {
2608 return mSearchDropTargetBar;
2609 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002610
Winson Chung3d503fb2011-07-13 17:25:49 -07002611 /**
2612 * Returns the CellLayout of the specified container at the specified screen.
2613 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002614 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002615 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2616 if (mHotseat != null) {
2617 return mHotseat.getLayout();
2618 } else {
2619 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002620 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002621 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002622 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002623 }
2624 }
2625
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002626 Workspace getWorkspace() {
2627 return mWorkspace;
2628 }
2629
Daniel Sandler843e8602010-06-07 14:59:01 -04002630 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002631 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002632 }
2633
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002634 /**
2635 * Helper method for the cameraZoomIn/cameraZoomOut animations
2636 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002637 * @param scaleFactor The scale factor used for the zoom
2638 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002639 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002640 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002641 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002642 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002643
Winson Chung18f41f82012-05-09 13:28:10 -07002644 void disableWallpaperIfInAllApps() {
2645 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002646 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002647 if (mAppsCustomizeTabHost != null &&
2648 !mAppsCustomizeTabHost.isTransitioning()) {
2649 updateWallpaperVisibility(false);
2650 }
2651 }
2652 }
2653
Craig Mautner360310b2012-10-26 15:13:08 -07002654 private void setWorkspaceBackground(boolean workspace) {
2655 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002656 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002657 }
2658
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002659 void updateWallpaperVisibility(boolean visible) {
2660 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2661 int curflags = getWindow().getAttributes().flags
2662 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2663 if (wpflags != curflags) {
2664 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2665 }
Craig Mautner360310b2012-10-26 15:13:08 -07002666 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002667 }
2668
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002669 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2670 if (v instanceof LauncherTransitionable) {
2671 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2672 }
2673 }
2674
Michael Jurkabed61d22012-02-14 22:51:29 -08002675 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2676 if (v instanceof LauncherTransitionable) {
2677 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2678 }
Winson Chung70442722012-02-10 15:43:22 -08002679
2680 // Update the workspace transition step as well
2681 dispatchOnLauncherTransitionStep(v, 0f);
2682 }
2683
2684 private void dispatchOnLauncherTransitionStep(View v, float t) {
2685 if (v instanceof LauncherTransitionable) {
2686 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2687 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002688 }
2689
2690 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2691 if (v instanceof LauncherTransitionable) {
2692 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2693 }
Winson Chung70442722012-02-10 15:43:22 -08002694
2695 // Update the workspace transition step as well
2696 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002697 }
2698
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002699 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002700 * Things to test when changing the following seven functions.
2701 * - Home from workspace
2702 * - from center screen
2703 * - from other screens
2704 * - Home from all apps
2705 * - from center screen
2706 * - from other screens
2707 * - Back from all apps
2708 * - from center screen
2709 * - from other screens
2710 * - Launch app from workspace and quit
2711 * - with back
2712 * - with home
2713 * - Launch app from all apps and quit
2714 * - with back
2715 * - with home
2716 * - Go to a screen that's not the default, then all
2717 * apps, and launch and app, and go back
2718 * - with back
2719 * -with home
2720 * - On workspace, long press power and go back
2721 * - with back
2722 * - with home
2723 * - On all apps, long press power and go back
2724 * - with back
2725 * - with home
2726 * - On workspace, power off
2727 * - On all apps, power off
2728 * - Launch an app and turn off the screen while in that app
2729 * - Go back with home key
2730 * - Go back with back key TODO: make this not go to workspace
2731 * - From all apps
2732 * - From workspace
2733 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2734 * - From all apps
2735 * - From the center workspace
2736 * - From another workspace
2737 */
2738
2739 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002740 * Zoom the camera out from the workspace to reveal 'toView'.
2741 * Assumes that the view to show is anchored at either the very top or very bottom
2742 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002743 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002744 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002745 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2746 showAppsCustomizeHelper(animated, springLoaded, contentType);
2747 }
2748 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2749 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002750 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002751 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002752 mStateAnimation.cancel();
2753 mStateAnimation = null;
2754 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002755 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002756
Winson Chungf0ea4d32011-06-06 14:27:16 -07002757 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2758 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2759 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002760 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002761 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002762 final int startDelay =
2763 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002764
Michael Jurkab3e22d92011-10-31 15:58:33 -07002765 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002766
Michael Jurkad74c9842011-07-10 12:44:21 -07002767 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002768 Animator workspaceAnim =
2769 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002770 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2771 // Set the content type for the all apps space
2772 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2773 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002774
2775 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002776 toView.setScaleX(scale);
2777 toView.setScaleY(scale);
2778 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2779 scaleAnim.
2780 scaleX(1f).scaleY(1f).
2781 setDuration(duration).
2782 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002783
Winson Chungf0ea4d32011-06-06 14:27:16 -07002784 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002785 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002786 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002787 .ofFloat(toView, "alpha", 0f, 1f)
2788 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002789 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002790 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2791 @Override
2792 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002793 if (animation == null) {
2794 throw new RuntimeException("animation is null");
2795 }
Winson Chung70442722012-02-10 15:43:22 -08002796 float t = (Float) animation.getAnimatedValue();
2797 dispatchOnLauncherTransitionStep(fromView, t);
2798 dispatchOnLauncherTransitionStep(toView, t);
2799 }
2800 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002801
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002802 // toView should appear right at the end of the workspace shrink
2803 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002804 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002805 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002806 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002807
2808 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002809 boolean animationCancelled = false;
2810
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002811 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002812 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002813 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002814 // Prepare the position
2815 toView.setTranslationX(0.0f);
2816 toView.setTranslationY(0.0f);
2817 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002818 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002819 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002820 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002821 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002822 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2823 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002824
Adam Cohenf4ddea32011-09-12 13:46:42 -07002825 if (!animationCancelled) {
2826 updateWallpaperVisibility(false);
2827 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002828
2829 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002830 if (mSearchDropTargetBar != null) {
2831 mSearchDropTargetBar.hideSearchBar(false);
2832 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002833 }
2834
Adam Cohencff6af82011-09-13 14:51:53 -07002835 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002836 public void onAnimationCancel(Animator animation) {
2837 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002838 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002839 });
2840
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002841 if (workspaceAnim != null) {
2842 mStateAnimation.play(workspaceAnim);
2843 }
Michael Jurka1899a362011-11-03 13:50:45 -07002844
2845 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002846
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002847 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2848 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002849
2850 // If any of the objects being animated haven't been measured/laid out
2851 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002852 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002853 (mWorkspace.getMeasuredWidth() == 0) ||
2854 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002855 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002856 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002857
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002858 final AnimatorSet stateAnimation = mStateAnimation;
2859 final Runnable startAnimRunnable = new Runnable() {
2860 public void run() {
2861 // Check that mStateAnimation hasn't changed while
2862 // we waited for a layout/draw pass
2863 if (mStateAnimation != stateAnimation)
2864 return;
2865 setPivotsForZoom(toView, scale);
2866 dispatchOnLauncherTransitionStart(fromView, animated, false);
2867 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002868 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002869 }
2870 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002871 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002872 final ViewTreeObserver observer = toView.getViewTreeObserver();
2873 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2874 public void onGlobalLayout() {
2875 startAnimRunnable.run();
2876 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2877 }
2878 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002879 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002880 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002881 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002882 } else {
2883 toView.setTranslationX(0.0f);
2884 toView.setTranslationY(0.0f);
2885 toView.setScaleX(1.0f);
2886 toView.setScaleY(1.0f);
2887 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002888 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002889
Daniel Sandlere4f98912013-06-25 15:13:26 -04002890 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002891 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002892 if (mSearchDropTargetBar != null) {
2893 mSearchDropTargetBar.hideSearchBar(false);
2894 }
Michael Jurkaabded662011-03-04 12:06:57 -08002895 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002896 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002897 dispatchOnLauncherTransitionStart(fromView, animated, false);
2898 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002899 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002900 dispatchOnLauncherTransitionStart(toView, animated, false);
2901 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002902 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002903 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002904 }
2905
2906 /**
2907 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002908 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002909 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002910 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002911 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2912 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002913
Michael Jurkab3e22d92011-10-31 15:58:33 -07002914 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002915 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002916 mStateAnimation.cancel();
2917 mStateAnimation = null;
2918 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002919 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002920
Winson Chungf0ea4d32011-06-06 14:27:16 -07002921 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002922 final int fadeOutDuration =
2923 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002924 final float scaleFactor = (float)
2925 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2926 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002927 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002928 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002929 if (toState == State.WORKSPACE) {
2930 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2931 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002932 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002933 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2934 workspaceAnim = mWorkspace.getChangeStateAnimation(
2935 Workspace.State.SPRING_LOADED, animated);
2936 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002937
Michael Jurkab3e22d92011-10-31 15:58:33 -07002938 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002939 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002940 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002941 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002942 final LauncherViewPropertyAnimator scaleAnim =
2943 new LauncherViewPropertyAnimator(fromView);
2944 scaleAnim.
2945 scaleX(scaleFactor).scaleY(scaleFactor).
2946 setDuration(duration).
2947 setInterpolator(new Workspace.ZoomInInterpolator());
2948
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002949 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002950 .ofFloat(fromView, "alpha", 1f, 0f)
2951 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002952 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002953 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2954 @Override
2955 public void onAnimationUpdate(ValueAnimator animation) {
2956 float t = 1f - (Float) animation.getAnimatedValue();
2957 dispatchOnLauncherTransitionStep(fromView, t);
2958 dispatchOnLauncherTransitionStep(toView, t);
2959 }
2960 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002961
Michael Jurka2ecf9952012-06-18 12:52:28 -07002962 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002963
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002964 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2965 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002966 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002967
2968 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002969 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002970 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002971 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002972 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002973 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2974 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002975 if (onCompleteRunnable != null) {
2976 onCompleteRunnable.run();
2977 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002978 mAppsCustomizeContent.updateCurrentPageScroll();
2979 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002980 }
2981 });
2982
Winson Chungf0ea4d32011-06-06 14:27:16 -07002983 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002984 if (workspaceAnim != null) {
2985 mStateAnimation.play(workspaceAnim);
2986 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002987 dispatchOnLauncherTransitionStart(fromView, animated, true);
2988 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002989 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002990 } else {
2991 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002992 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002993 dispatchOnLauncherTransitionStart(fromView, animated, true);
2994 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002995 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002996 dispatchOnLauncherTransitionStart(toView, animated, true);
2997 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002998 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002999 }
3000
Michael Jurkae326f182011-11-21 14:05:46 -08003001 @Override
3002 public void onTrimMemory(int level) {
3003 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003004 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003005 mAppsCustomizeTabHost.onTrimMemory();
3006 }
3007 }
3008
Winson Chung18f41f82012-05-09 13:28:10 -07003009 @Override
3010 public void onWindowFocusChanged(boolean hasFocus) {
3011 if (!hasFocus) {
3012 // When another window occludes launcher (like the notification shade, or recents),
3013 // ensure that we enable the wallpaper flag so that transitions are done correctly.
3014 updateWallpaperVisibility(true);
3015 } else {
3016 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07003017 mWorkspace.postDelayed(new Runnable() {
3018 @Override
3019 public void run() {
3020 disableWallpaperIfInAllApps();
3021 }
3022 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07003023 }
3024 }
3025
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003026 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003027 showWorkspace(animated, null);
3028 }
3029
3030 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003031 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003032 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003033 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003034 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003035
Winson Chungc7d2b602012-05-16 17:02:20 -07003036 // Show the search bar (only animate if we were showing the drop target bar in spring
3037 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003038 if (mSearchDropTargetBar != null) {
3039 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3040 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003041
Michael Jurkab3e22d92011-10-31 15:58:33 -07003042 // Set focus to the AppsCustomize button
3043 if (mAllAppsButton != null) {
3044 mAllAppsButton.requestFocus();
3045 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003046 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003047
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003048 // Change the state *after* we've called all the transition code
3049 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003050
Winson Chung5fb63472011-02-02 17:03:37 -08003051 // Resume the auto-advance of widgets
3052 mUserPresent = true;
3053 updateRunning();
3054
alanv1d4fde62012-10-17 13:15:47 -07003055 // Send an accessibility event to announce the context change
3056 getWindow().getDecorView()
3057 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003058
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003059 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003060 }
3061
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003062 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003063 }
3064
Winson Chungc58497e2013-09-03 17:48:37 -07003065 void showAllApps(boolean animated,
3066 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003067 if (mState != State.WORKSPACE) return;
3068
Winson Chungc58497e2013-09-03 17:48:37 -07003069 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003070 mAppsCustomizeTabHost.requestFocus();
3071
Michael Jurkab3e22d92011-10-31 15:58:33 -07003072 // Change the state *after* we've called all the transition code
3073 mState = State.APPS_CUSTOMIZE;
3074
3075 // Pause the auto-advance of widgets until we are out of AllApps
3076 mUserPresent = false;
3077 updateRunning();
3078 closeFolder();
3079
3080 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003081 getWindow().getDecorView()
3082 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003083 }
3084
Adam Cohen7777d962011-08-18 18:58:38 -07003085 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003086 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003087 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003088 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003089 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003090 }
Adam Cohen7777d962011-08-18 18:58:38 -07003091
Adam Cohened66b2b2012-01-23 17:28:51 -08003092 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3093 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003094 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3095
Winson Chunge7a03942011-08-05 15:05:12 -07003096 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003097 @Override
3098 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003099 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003100 // Before we show workspace, hide all apps again because
3101 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3102 // clean up our state transition functions
3103 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003104 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003105 } else {
3106 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003107 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003108 }
3109 }, (extendedDelay ?
3110 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3111 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3112 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003113
Michael Jurkad3ef3062010-11-23 16:23:58 -08003114 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003115 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003116 final boolean animated = true;
3117 final boolean springLoaded = true;
3118 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003119 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003120 }
3121 // Otherwise, we are not in spring loaded mode, so don't do anything.
3122 }
3123
Michael Jurkab3e22d92011-10-31 15:58:33 -07003124 void lockAllApps() {
3125 // TODO
3126 }
3127
3128 void unlockAllApps() {
3129 // TODO
3130 }
3131
Winson Chungf0ea4d32011-06-06 14:27:16 -07003132 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003133 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003134 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003135 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003136 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003137 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003138 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003139 int duration = 0;
3140 if (mSearchDropTargetBar != null) {
3141 duration = mSearchDropTargetBar.getTransitionInDuration();
3142 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003143 mHotseat.animate().alpha(1f).setDuration(duration);
3144 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003145 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003146 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003147 }
3148 }
3149 }
3150
3151 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003152 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003153 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003154 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003155 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003156 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003157 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003158 int duration = 0;
3159 if (mSearchDropTargetBar != null) {
3160 duration = mSearchDropTargetBar.getTransitionOutDuration();
3161 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003162 mHotseat.animate().alpha(0f).setDuration(duration);
3163 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003164 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003165 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003166 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003167 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003168 }
3169
Patrick Dubroy5f445422011-02-18 14:35:21 -08003170 /**
3171 * Add an item from all apps or customize onto the given workspace screen.
3172 * If layout is null, add to the current screen.
3173 */
3174 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003175 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003176 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003177 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003178 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003179
Winson Chungdff8ebb2011-09-08 17:25:31 -07003180 /** Maps the current orientation to an index for referencing orientation correct global icons */
3181 private int getCurrentOrientationIndexForGlobalIcons() {
3182 // default - 0, landscape - 1
3183 switch (getResources().getConfiguration().orientation) {
3184 case Configuration.ORIENTATION_LANDSCAPE:
3185 return 1;
3186 default:
3187 return 0;
3188 }
3189 }
3190
Michael Jurkaae65ee32012-04-30 11:45:54 -07003191 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003192 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003193 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003194 // Look for the toolbar icon specified in the activity meta-data
3195 Bundle metaData = packageManager.getActivityInfo(
3196 activityName, PackageManager.GET_META_DATA).metaData;
3197 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003198 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003199 if (iconResId != 0) {
3200 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003201 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003202 }
3203 }
3204 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003205 // This can happen if the activity defines an invalid drawable
3206 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3207 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003208 } catch (Resources.NotFoundException nfe) {
3209 // This can happen if the activity defines an invalid drawable
3210 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3211 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003212 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003213 return null;
3214 }
3215
3216 // if successful in getting icon, return it; otherwise, set button to use default drawable
3217 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003218 int buttonId, ComponentName activityName, int fallbackDrawableId,
3219 String toolbarResourceName) {
3220 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003221 Resources r = getResources();
3222 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3223 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003224
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003225 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003226 // If we were unable to find the icon via the meta-data, use a generic one
3227 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003228 toolbarIcon = r.getDrawable(fallbackDrawableId);
3229 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003230 if (button != null) {
3231 button.setCompoundDrawables(toolbarIcon, null, null, null);
3232 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003233 return null;
3234 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003235 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003236 if (button != null) {
3237 button.setCompoundDrawables(toolbarIcon, null, null, null);
3238 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003239 return toolbarIcon.getConstantState();
3240 }
3241 }
3242
3243 // if successful in getting icon, return it; otherwise, set button to use default drawable
3244 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003245 int buttonId, ComponentName activityName, int fallbackDrawableId,
3246 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003247 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003248 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003249
Michael Jurka19e0fc52011-07-22 18:00:21 -07003250 if (button != null) {
3251 // If we were unable to find the icon via the meta-data, use a
3252 // generic one
3253 if (toolbarIcon == null) {
3254 button.setImageResource(fallbackDrawableId);
3255 } else {
3256 button.setImageDrawable(toolbarIcon);
3257 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003258 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003259
3260 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3261
Michael Jurka0423dcf2010-10-05 14:56:18 -07003262 }
3263
Winson Chung1b884092012-06-08 17:13:02 -07003264 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003265 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003266 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003267 }
3268
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003269 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003270 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003271 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003272 }
3273
Winson Chungbb185bd2011-11-21 12:31:42 -08003274 private void invalidatePressedFocusedStates(View container, View button) {
3275 if (container instanceof HolographicLinearLayout) {
3276 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3277 layout.invalidatePressedFocusedStates();
3278 } else if (button instanceof HolographicImageView) {
3279 HolographicImageView view = (HolographicImageView) button;
3280 view.invalidatePressedFocusedStates();
3281 }
3282 }
3283
Cristina Stancu476493b2013-08-07 17:20:14 +01003284 public View getQsbBar() {
3285 if (mQsbBar == null) {
3286 mQsbBar = mInflater.inflate(R.layout.qsb_bar, mSearchDropTargetBar);
3287 }
3288 return mQsbBar;
3289 }
3290
3291 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003292 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003293 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003294 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003295 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003296
Winson Chung1cad91e2011-05-25 17:41:01 -07003297 final SearchManager searchManager =
3298 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3299 ComponentName activityName = searchManager.getGlobalSearchActivity();
3300 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003301 int coi = getCurrentOrientationIndexForGlobalIcons();
3302 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003303 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3304 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3305 if (sGlobalSearchIcon[coi] == null) {
3306 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3307 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3308 TOOLBAR_ICON_METADATA_NAME);
3309 }
3310
Winson Chungc51db6a2011-10-05 11:44:49 -07003311 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3312 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003313 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003314 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003315 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003316 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003317 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3318 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3319 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003320 voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003321 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003322 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003323 }
3324 }
3325
Cristina Stancu476493b2013-08-07 17:20:14 +01003326 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003327 final View searchButtonContainer = findViewById(R.id.search_button_container);
3328 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003329 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003330 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003331 }
3332
Cristina Stancu476493b2013-08-07 17:20:14 +01003333 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003334 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003335 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003336
Winson Chungc51db6a2011-10-05 11:44:49 -07003337 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003338 final SearchManager searchManager =
3339 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3340 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3341
3342 ComponentName activityName = null;
3343 if (globalSearchActivity != null) {
3344 // Check if the global search activity handles voice search
3345 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3346 intent.setPackage(globalSearchActivity.getPackageName());
3347 activityName = intent.resolveActivity(getPackageManager());
3348 }
3349
3350 if (activityName == null) {
3351 // Fallback: check if an activity other than the global search activity
3352 // resolves this
3353 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3354 activityName = intent.resolveActivity(getPackageManager());
3355 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003356 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003357 int coi = getCurrentOrientationIndexForGlobalIcons();
3358 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003359 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3360 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3361 if (sVoiceSearchIcon[coi] == null) {
3362 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3363 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3364 TOOLBAR_ICON_METADATA_NAME);
3365 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003366 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003367 voiceButton.setVisibility(View.VISIBLE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003368 setVoiceButtonProxyVisible(true);
Winson Chungbb185bd2011-11-21 12:31:42 -08003369 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003370 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003371 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003372 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003373 voiceButton.setVisibility(View.GONE);
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003374 setVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003375 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003376 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003377 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003378
Cristina Stancu476493b2013-08-07 17:20:14 +01003379 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003380 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3381 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003382 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003383 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003384 }
3385
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003386 public void setVoiceButtonProxyVisible(boolean visible) {
3387 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3388 if (voiceButtonProxy != null) {
3389 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
3390 }
3391 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003392 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003393 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003394 */
3395 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003396 final View marketButton = findViewById(R.id.market_button);
3397 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3398 // Find the app market activity by resolving an intent.
3399 // (If multiple app markets are installed, it will return the ResolverActivity.)
3400 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003401 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003402 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003403 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003404 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003405 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3406 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003407 marketButton.setVisibility(View.VISIBLE);
3408 } else {
3409 // We should hide and disable the view so that we don't try and restore the visibility
3410 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3411 marketButton.setVisibility(View.GONE);
3412 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003413 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003414 }
3415
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003416 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003417 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3418 Resources r = getResources();
3419 Drawable marketIconDrawable = d.newDrawable(r);
3420 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3421 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3422 marketIconDrawable.setBounds(0, 0, w, h);
3423
3424 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003425 }
3426
Michael Jurkad7c28052012-04-27 15:43:36 -07003427 @Override
3428 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003429 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003430 final List<CharSequence> text = event.getText();
3431 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003432 // Populate event with a fake title based on the current state.
3433 if (mState == State.APPS_CUSTOMIZE) {
3434 text.add(getString(R.string.all_apps_button_label));
3435 } else {
3436 text.add(getString(R.string.all_apps_home_button_label));
3437 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003438 return result;
3439 }
3440
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003441 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003442 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003443 */
3444 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3445 @Override
3446 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003447 closeSystemDialogs();
3448 }
3449 }
3450
3451 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003452 * Receives notifications whenever the appwidgets are reset.
3453 */
3454 private class AppWidgetResetObserver extends ContentObserver {
3455 public AppWidgetResetObserver() {
3456 super(new Handler());
3457 }
3458
3459 @Override
3460 public void onChange(boolean selfChange) {
3461 onAppWidgetReset();
3462 }
3463 }
3464
3465 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003466 * If the activity is currently paused, signal that we need to run the passed Runnable
3467 * in onResume.
3468 *
3469 * This needs to be called from incoming places where resources might have been loaded
3470 * while we are paused. That is becaues the Configuration might be wrong
3471 * when we're not running, and if it comes back to what it was when we
3472 * were paused, we are not restarted.
3473 *
3474 * Implementation of the method from LauncherModel.Callbacks.
3475 *
3476 * @return true if we are currently paused. The caller might be able to
3477 * skip some work in that case since we will come back again.
3478 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003479 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003480 if (mPaused) {
3481 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003482 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003483 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003484 }
3485 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003486 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003487 return true;
3488 } else {
3489 return false;
3490 }
3491 }
3492
Michael Jurkac402cd92013-05-20 15:49:32 +02003493 private boolean waitUntilResume(Runnable run) {
3494 return waitUntilResume(run, false);
3495 }
3496
Michael Jurka1e2f4652013-07-08 18:03:46 -07003497 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003498 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003499 }
3500
Michael Jurka7607c2f2013-04-03 14:33:19 -07003501 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003502 * If the activity is currently paused, signal that we need to re-run the loader
3503 * in onResume.
3504 *
3505 * This needs to be called from incoming places where resources might have been loaded
3506 * while we are paused. That is becaues the Configuration might be wrong
3507 * when we're not running, and if it comes back to what it was when we
3508 * were paused, we are not restarted.
3509 *
3510 * Implementation of the method from LauncherModel.Callbacks.
3511 *
3512 * @return true if we are currently paused. The caller might be able to
3513 * skip some work in that case since we will come back again.
3514 */
3515 public boolean setLoadOnResume() {
3516 if (mPaused) {
3517 Log.i(TAG, "setLoadOnResume");
3518 mOnResumeNeedsLoad = true;
3519 return true;
3520 } else {
3521 return false;
3522 }
3523 }
3524
3525 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003526 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003527 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003528 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003529 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003530 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003531 } else {
3532 return SCREEN_COUNT / 2;
3533 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003534 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003535
Joe Onorato9c1289c2009-08-17 11:03:03 -04003536 /**
3537 * Refreshes the shortcuts shown on the workspace.
3538 *
3539 * Implementation of the method from LauncherModel.Callbacks.
3540 */
3541 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003542 // If we're starting binding all over again, clear any bind calls we'd postponed in
3543 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3544 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003545 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003546
Winson Chungd64d1762013-08-20 14:37:16 -07003547 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003548 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003549 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003550
Michael Jurka05bf6442011-11-30 20:28:53 -08003551 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003552 if (mHotseat != null) {
3553 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003554 }
3555 }
3556
Adam Cohendcd297f2013-06-18 13:13:40 -07003557 @Override
3558 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003559 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003560
3561 // Create the new empty page
Winson Chung64359a52013-07-08 17:17:08 -07003562 mWorkspace.addExtraEmptyScreen();
Winson Chung0e6a7132013-08-23 12:55:10 -07003563
3564 // Create the custom content page (this call updates mDefaultScreen which calls
3565 // setCurrentPage() so ensure that all pages are added before calling this)
3566 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3567 mWorkspace.createCustomContentPage();
3568 }
Winson Chung64359a52013-07-08 17:17:08 -07003569 }
3570
3571 @Override
3572 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003573 int count = orderedScreenIds.size();
3574 for (int i = 0; i < count; i++) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003575 Launcher.addDumpLog(TAG, "10249126 - bindAddScreens(" + orderedScreenIds.get(i) + ")", true);
Adam Cohen89bddfa2013-08-20 11:57:13 -07003576 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003577 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003578 }
3579
Adam Cohen39a06042013-07-19 14:30:12 -07003580 private boolean shouldShowWeightWatcher() {
3581 String spKey = LauncherAppState.getSharedPreferencesKey();
3582 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003583 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003584
3585 return show;
3586 }
3587
Adam Cohen4caf2982013-08-20 18:54:31 -07003588 private boolean emailSent() {
3589 String spKey = LauncherAppState.getSharedPreferencesKey();
3590 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3591 boolean show = sp.getBoolean(CORRUPTION_EMAIL_SENT_KEY, false);
3592 return show;
3593 }
3594
3595 private void setEmailSent(boolean sent) {
3596 String spKey = LauncherAppState.getSharedPreferencesKey();
3597 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3598
3599 SharedPreferences.Editor editor = sp.edit();
3600 editor.putBoolean(CORRUPTION_EMAIL_SENT_KEY, sent);
3601 editor.commit();
3602 }
3603
Adam Cohen39a06042013-07-19 14:30:12 -07003604 private void toggleShowWeightWatcher() {
3605 String spKey = LauncherAppState.getSharedPreferencesKey();
3606 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3607 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3608
3609 show = !show;
3610
3611 SharedPreferences.Editor editor = sp.edit();
3612 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3613 editor.commit();
3614
3615 if (mWeightWatcher != null) {
3616 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3617 }
3618 }
3619
Winson Chungd64d1762013-08-20 14:37:16 -07003620 public void bindAppsAdded(final ArrayList<Long> newScreens,
3621 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003622 final ArrayList<ItemInfo> addAnimated,
3623 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003624 Runnable r = new Runnable() {
3625 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003626 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003627 }
3628 };
3629 if (waitUntilResume(r)) {
3630 return;
3631 }
3632
Adam Cohen4caf2982013-08-20 18:54:31 -07003633 Launcher.addDumpLog(TAG, "10249126 - bindAppsAdded(" + newScreens.size() + ")", true);
Winson Chungd64d1762013-08-20 14:37:16 -07003634
3635 // Add the new screens
3636 bindAddScreens(newScreens);
3637
3638 // We add the items without animation on non-visible pages, and with
3639 // animations on the new page (which we will try and snap to).
3640 if (!addNotAnimated.isEmpty()) {
3641 bindItems(addNotAnimated, 0,
3642 addNotAnimated.size(), false);
3643 }
3644 if (!addAnimated.isEmpty()) {
3645 bindItems(addAnimated, 0,
3646 addAnimated.size(), true);
3647 }
Winson Chungc58497e2013-09-03 17:48:37 -07003648
3649 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3650 addedApps != null && mAppsCustomizeContent != null) {
3651 mAppsCustomizeContent.addApps(addedApps);
3652 }
Winson Chungd64d1762013-08-20 14:37:16 -07003653 }
3654
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003655 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003656 * Bind the items start-end from the list.
3657 *
3658 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003659 */
Winson Chung64359a52013-07-08 17:17:08 -07003660 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3661 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003662 Runnable r = new Runnable() {
3663 public void run() {
3664 bindItems(shortcuts, start, end, forceAnimateIcons);
3665 }
3666 };
3667 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003668 return;
3669 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003670
Winson Chungf0c6ae02012-03-21 16:10:31 -07003671 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003672 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3673 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003674 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003675 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003676 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003677 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003678 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003679
3680 // Short circuit if we are loading dock items for a configuration which has no dock
3681 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3682 mHotseat == null) {
3683 continue;
3684 }
3685
Joe Onorato9c1289c2009-08-17 11:03:03 -04003686 switch (item.itemType) {
3687 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3688 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003689 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003690 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003691
Winson Chung64359a52013-07-08 17:17:08 -07003692 /*
3693 * TODO: FIX collision case
3694 */
Winson Chungce376632013-07-11 16:12:41 -07003695 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3696 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3697 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3698 throw new RuntimeException("OCCUPIED");
3699 }
Winson Chung64359a52013-07-08 17:17:08 -07003700 }
3701
Adam Cohendcd297f2013-06-18 13:13:40 -07003702 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3703 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003704 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003705 // Animate all the applications up now
3706 shortcut.setAlpha(0f);
3707 shortcut.setScaleX(0f);
3708 shortcut.setScaleY(0f);
3709 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003710 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003711 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003712 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003713 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003714 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003715 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003716 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003717 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3718 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003719 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003720 default:
3721 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003722 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003723 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003724
Winson Chung997a9232013-07-24 15:33:46 -07003725 if (animateIcons) {
3726 // Animate to the correct page
3727 if (newShortcutsScreenId > -1) {
3728 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
3729 int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
3730 if (newShortcutsScreenId != currentScreenId) {
3731 mWorkspace.snapToPage(newScreenIndex);
3732 }
3733 }
3734
Winson Chung64359a52013-07-08 17:17:08 -07003735 // We post the animation slightly delayed to prevent slowdowns when we are loading
3736 // right after we return to launcher.
3737 mWorkspace.postDelayed(new Runnable() {
3738 public void run() {
3739 anim.playTogether(bounceAnims);
3740 anim.start();
3741 }
3742 }, NEW_APPS_ANIMATION_DELAY);
3743 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003744 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003745 }
3746
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747 /**
3748 * Implementation of the method from LauncherModel.Callbacks.
3749 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003750 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003751 Runnable r = new Runnable() {
3752 public void run() {
3753 bindFolders(folders);
3754 }
3755 };
3756 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003757 return;
3758 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003759 sFolders.clear();
3760 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003761 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003762
3763 /**
3764 * Add the views for a widget to the workspace.
3765 *
3766 * Implementation of the method from LauncherModel.Callbacks.
3767 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003768 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003769 Runnable r = new Runnable() {
3770 public void run() {
3771 bindAppWidget(item);
3772 }
3773 };
3774 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003775 return;
3776 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003777
Daniel Sandler843e8602010-06-07 14:59:01 -04003778 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3779 if (DEBUG_WIDGETS) {
3780 Log.d(TAG, "bindAppWidget: " + item);
3781 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003782 final Workspace workspace = mWorkspace;
3783
3784 final int appWidgetId = item.appWidgetId;
3785 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003786 if (DEBUG_WIDGETS) {
3787 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3788 }
3789
Joe Onorato9c1289c2009-08-17 11:03:03 -04003790 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3791
Joe Onorato9c1289c2009-08-17 11:03:03 -04003792 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003793 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003794
Adam Cohendcd297f2013-06-18 13:13:40 -07003795 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003797 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3798
Joe Onorato9c1289c2009-08-17 11:03:03 -04003799 workspace.requestLayout();
3800
Daniel Sandler843e8602010-06-07 14:59:01 -04003801 if (DEBUG_WIDGETS) {
3802 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3803 + (SystemClock.uptimeMillis()-start) + "ms");
3804 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003805 }
3806
Adam Cohen1462de32012-07-24 22:34:36 -07003807 public void onPageBoundSynchronously(int page) {
3808 mSynchronouslyBoundPages.add(page);
3809 }
3810
Joe Onorato9c1289c2009-08-17 11:03:03 -04003811 /**
3812 * Callback saying that there aren't any more items to bind.
3813 *
3814 * Implementation of the method from LauncherModel.Callbacks.
3815 */
Adam Cohene25af792013-06-06 23:08:25 -07003816 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003817 Runnable r = new Runnable() {
3818 public void run() {
3819 finishBindingItems(upgradePath);
3820 }
3821 };
3822 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003823 return;
3824 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003825 if (mSavedState != null) {
3826 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003827 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003828 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003829 mSavedState = null;
3830 }
3831
Adam Cohen1462de32012-07-24 22:34:36 -07003832 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003833
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003834 // If we received the result of any pending adds while the loader was running (e.g. the
3835 // widget configuration forced an orientation change), process them now.
3836 for (int i = 0; i < sPendingAddList.size(); i++) {
3837 completeAdd(sPendingAddList.get(i));
3838 }
3839 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003840
Winson Chungc51db6a2011-10-05 11:44:49 -07003841 // Update the market app icon as necessary (the other icons will be managed in response to
3842 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003843 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003844
Winson Chungf0c6ae02012-03-21 16:10:31 -07003845 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003846 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003847 mWorkspace.getUniqueComponents(true, null);
3848 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003849 }
Adam Cohen99894d92013-06-14 11:22:59 -07003850
Adam Cohen66a01fd2013-06-11 12:48:00 -07003851 mWorkspace.post(new Runnable() {
3852 @Override
3853 public void run() {
3854 onFinishBindingItems();
3855 }
3856 });
Adam Cohen4caf2982013-08-20 18:54:31 -07003857
3858 // Write all the logs to disk
3859 Launcher.addDumpLog(TAG, "10249126 - finishBindingItems() - dumping logs to disk", true);
3860 dumpLogsToLocalData(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003861 }
3862
Winson Chunga2413752012-04-03 14:22:34 -07003863 private boolean canRunNewAppsAnimation() {
3864 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3865 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3866 }
3867
Winson Chungc9168342013-06-26 14:54:55 -07003868 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3869 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3870 PropertyValuesHolder.ofFloat("alpha", 1f),
3871 PropertyValuesHolder.ofFloat("scaleX", 1f),
3872 PropertyValuesHolder.ofFloat("scaleY", 1f));
3873 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3874 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3875 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3876 return bounceAnim;
3877 }
3878
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003879 @Override
3880 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003881 boolean searchVisible = updateGlobalSearchIcon();
3882 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003883 if (mSearchDropTargetBar != null) {
3884 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3885 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003886 }
3887
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003888 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003889 * Add the icons for all apps.
3890 *
3891 * Implementation of the method from LauncherModel.Callbacks.
3892 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003893 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003894 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3895 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3896 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3897 getHotseat().addAllAppsFolder(mIconCache, apps,
3898 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3899 }
3900 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003901 }
Winson Chungc58497e2013-09-03 17:48:37 -07003902 } else {
3903 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3904 mAppsCustomizeContent != null) {
3905 mAppsCustomizeContent.setApps(apps);
3906 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003907 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003908 }
3909
3910 /**
3911 * A package was updated.
3912 *
3913 * Implementation of the method from LauncherModel.Callbacks.
3914 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003915 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003916 Runnable r = new Runnable() {
3917 public void run() {
3918 bindAppsUpdated(apps);
3919 }
3920 };
3921 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003922 return;
3923 }
3924
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003925 if (mWorkspace != null) {
3926 mWorkspace.updateShortcuts(apps);
3927 }
Winson Chungc58497e2013-09-03 17:48:37 -07003928
3929 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3930 mAppsCustomizeContent != null) {
3931 mAppsCustomizeContent.updateApps(apps);
3932 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003933 }
3934
3935 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003936 * A package was uninstalled. We take both the super set of packageNames
3937 * in addition to specific applications to remove, the reason being that
3938 * this can be called when a package is updated as well. In that scenario,
3939 * we only remove specific components from the workspace, where as
3940 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003941 *
3942 * Implementation of the method from LauncherModel.Callbacks.
3943 */
Winson Chung83892cc2013-05-01 16:53:33 -07003944 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003945 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003946 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003947 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003948 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003949 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003950 }
Winson Chungd64d1762013-08-20 14:37:16 -07003951 };
3952 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003953 return;
3954 }
3955
Winson Chung64359a52013-07-08 17:17:08 -07003956 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003957 mWorkspace.removeItemsByPackageName(packageNames);
3958 } else {
3959 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003960 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003961
Winson Chunga1820962011-10-03 16:31:06 -07003962 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003963 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003964
3965 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3966 mAppsCustomizeContent != null) {
3967 mAppsCustomizeContent.removeApps(appInfos);
3968 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003969 }
Joe Onoratobe386092009-11-17 17:32:16 -08003970
3971 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003972 * A number of packages were updated.
3973 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003974 private ArrayList<Object> mWidgetsAndShortcuts;
3975 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003976 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003977 bindPackagesUpdated(mWidgetsAndShortcuts);
3978 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003979 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003980 };
3981
3982 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3983 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3984 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003985 return;
3986 }
3987
Winson Chung64359a52013-07-08 17:17:08 -07003988 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07003989 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3990 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003991 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003992 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003993 }
3994
Winson Chung400438b2011-01-16 17:53:48 -08003995 private int mapConfigurationOriActivityInfoOri(int configOri) {
3996 final Display d = getWindowManager().getDefaultDisplay();
3997 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3998 switch (d.getRotation()) {
3999 case Surface.ROTATION_0:
4000 case Surface.ROTATION_180:
4001 // We are currently in the same basic orientation as the natural orientation
4002 naturalOri = configOri;
4003 break;
4004 case Surface.ROTATION_90:
4005 case Surface.ROTATION_270:
4006 // We are currently in the other basic orientation to the natural orientation
4007 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4008 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4009 break;
4010 }
4011
4012 int[] oriMap = {
4013 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4014 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4015 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4016 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4017 };
4018 // Since the map starts at portrait, we need to offset if this device's natural orientation
4019 // is landscape.
4020 int indexOffset = 0;
4021 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4022 indexOffset = 1;
4023 }
4024 return oriMap[(d.getRotation() + indexOffset) % 4];
4025 }
Adam Cohen446e9402011-09-15 18:21:21 -07004026
Winson Chung4b919f82012-05-01 10:44:08 -07004027 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004028 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004029 getResources().getBoolean(R.bool.allow_rotation);
4030 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004031 }
Winson Chung4b919f82012-05-01 10:44:08 -07004032 public void lockScreenOrientation() {
4033 if (isRotationEnabled()) {
4034 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4035 .getConfiguration().orientation));
4036 }
4037 }
4038 public void unlockScreenOrientation(boolean immediate) {
4039 if (isRotationEnabled()) {
4040 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004041 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004042 } else {
4043 mHandler.postDelayed(new Runnable() {
4044 public void run() {
4045 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4046 }
4047 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004048 }
Winson Chung4b919f82012-05-01 10:44:08 -07004049 }
Winson Chung400438b2011-01-16 17:53:48 -08004050 }
4051
Winson Chung82f55532011-08-09 14:14:23 -07004052 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004053 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004054 if (DISABLE_CLINGS) {
4055 return false;
4056 }
4057
Brett Chabot2a9e2282011-08-23 15:03:13 -07004058 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004059 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004060
Michael Jurkae233a8b2013-03-19 13:49:20 +01004061 // Restricted secondary users (child mode) will potentially have very few apps
4062 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004063// boolean supportsLimitedUsers =
4064// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4065// Account[] accounts = AccountManager.get(this).getAccounts();
4066// if (supportsLimitedUsers && accounts.length == 0) {
4067// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4068// Bundle restrictions = um.getUserRestrictions();
4069// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4070// return false;
4071// }
4072// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004073 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004074 }
Michael Jurka22143132012-10-04 17:42:38 +02004075
Winson Chung7d7541e2011-09-16 20:14:36 -07004076 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02004077 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07004078 if (cling != null) {
4079 cling.init(this, positionData);
4080 cling.setVisibility(View.VISIBLE);
4081 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
4082 if (animate) {
4083 cling.buildLayer();
4084 cling.setAlpha(0f);
4085 cling.animate()
4086 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07004087 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07004088 .setDuration(SHOW_CLING_DURATION)
4089 .setStartDelay(delay)
4090 .start();
4091 } else {
4092 cling.setAlpha(1f);
4093 }
Michael Jurka22143132012-10-04 17:42:38 +02004094 cling.setFocusableInTouchMode(true);
4095 cling.post(new Runnable() {
4096 public void run() {
4097 cling.setFocusable(true);
4098 cling.requestFocus();
4099 }
4100 });
4101 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
4102 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004103 }
4104 return cling;
4105 }
Michael Jurka22143132012-10-04 17:42:38 +02004106
Winson Chung7d7541e2011-09-16 20:14:36 -07004107 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08004108 // To catch cases where siblings of top-level views are made invisible, just check whether
4109 // the cling is directly set to GONE before dismissing it.
4110 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07004111 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07004112 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07004113 anim.addListener(new AnimatorListenerAdapter() {
4114 public void onAnimationEnd(Animator animation) {
4115 cling.setVisibility(View.GONE);
4116 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004117 // We should update the shared preferences on a background thread
4118 new Thread("dismissClingThread") {
4119 public void run() {
4120 SharedPreferences.Editor editor = mSharedPrefs.edit();
4121 editor.putBoolean(flag, true);
4122 editor.commit();
4123 }
4124 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07004125 };
4126 });
4127 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02004128 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07004129 }
4130 }
Michael Jurka22143132012-10-04 17:42:38 +02004131
Winson Chung9d9d74f2011-09-19 11:49:12 -07004132 private void removeCling(int id) {
4133 final View cling = findViewById(id);
4134 if (cling != null) {
4135 final ViewGroup parent = (ViewGroup) cling.getParent();
4136 parent.post(new Runnable() {
4137 @Override
4138 public void run() {
4139 parent.removeView(cling);
4140 }
4141 });
Michael Jurka22143132012-10-04 17:42:38 +02004142 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004143 }
4144 }
Michael Jurka974c3862012-05-22 22:00:31 -07004145
4146 private boolean skipCustomClingIfNoAccounts() {
4147 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4148 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4149 if (customCling) {
4150 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004151 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004152 Account[] accounts = am.getAccountsByType("com.google");
4153 return accounts.length == 0;
4154 }
4155 return false;
4156 }
4157
Winson Chung7d7541e2011-09-16 20:14:36 -07004158 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004159 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004160 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07004161 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
4162 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004163 // If we're not using the default workspace layout, replace workspace cling
4164 // with a custom workspace cling (usually specified in an overlay)
4165 // For now, only do this on tablets
4166 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02004167 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02004168 // Use a custom cling
4169 View cling = findViewById(R.id.workspace_cling);
4170 ViewGroup clingParent = (ViewGroup) cling.getParent();
4171 int clingIndex = clingParent.indexOfChild(cling);
4172 clingParent.removeViewAt(clingIndex);
4173 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4174 clingParent.addView(customCling, clingIndex);
4175 customCling.setId(R.id.workspace_cling);
4176 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004177 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004178 } else {
4179 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004180 }
4181 }
4182 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004183 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004184 if (isClingsEnabled() &&
4185 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004186 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004187 } else {
4188 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004189 }
4190 }
4191 public Cling showFirstRunFoldersCling() {
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.FOLDER_CLING_DISMISSED_KEY, false)) {
4195 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004196 } else {
4197 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004198 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004199 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004200 }
Michael Jurka104c4562013-07-08 18:03:46 -07004201 protected SharedPreferences getSharedPrefs() {
4202 return mSharedPrefs;
4203 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004204 public boolean isFolderClingVisible() {
4205 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004206 if (cling != null) {
4207 return cling.getVisibility() == View.VISIBLE;
4208 }
4209 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004210 }
Winson Chung82f55532011-08-09 14:14:23 -07004211 public void dismissWorkspaceCling(View v) {
4212 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004213 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004214 }
4215 public void dismissAllAppsCling(View v) {
4216 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004217 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4218 }
4219 public void dismissFolderCling(View v) {
4220 Cling cling = (Cling) findViewById(R.id.folder_cling);
4221 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004222 }
4223
Winson Chung80baf5a2010-08-09 16:03:15 -07004224 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004225 * Prints out out state for debugging.
4226 */
4227 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004228 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004229 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004230 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4231 Log.d(TAG, "mRestoring=" + mRestoring);
4232 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4233 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004234 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004235 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004236
Winson Chung785d2eb2011-04-14 16:08:02 -07004237 if (mAppsCustomizeContent != null) {
4238 mAppsCustomizeContent.dumpState();
4239 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004240 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004241 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004242
4243 @Override
4244 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4245 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004246 synchronized (sDumpLogs) {
4247 writer.println(" ");
4248 writer.println("Debug logs: ");
4249 for (int i = 0; i < sDumpLogs.size(); i++) {
4250 writer.println(" " + sDumpLogs.get(i));
4251 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004252 }
4253 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004254
4255 public static void dumpDebugLogsToConsole() {
Adam Cohen4caf2982013-08-20 18:54:31 -07004256 synchronized (sDumpLogs) {
4257 Log.d(TAG, "");
4258 Log.d(TAG, "*********************");
4259 Log.d(TAG, "Launcher debug logs: ");
4260 for (int i = 0; i < sDumpLogs.size(); i++) {
4261 Log.d(TAG, " " + sDumpLogs.get(i));
4262 }
4263 Log.d(TAG, "*********************");
4264 Log.d(TAG, "");
Adam Cohen487f7dd2012-06-28 18:12:10 -07004265 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004266 }
4267
4268 public static void addDumpLog(String tag, String log, boolean debugLog) {
4269 if (debugLog) {
4270 Log.d(tag, log);
4271 }
4272 sDateStamp.setTime(System.currentTimeMillis());
4273 synchronized (sDumpLogs) {
4274 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
4275 }
4276 }
4277
4278 public void dumpLogsToLocalData(final boolean email) {
4279 new Thread("DumpLogsToLocalData") {
4280 @Override
4281 public void run() {
4282 boolean success = false;
4283 sDateStamp.setTime(sRunStart);
4284 String FILENAME = sDateStamp.getMonth() + "-"
4285 + sDateStamp.getDay() + "_"
4286 + sDateStamp.getHours() + "-"
4287 + sDateStamp.getMinutes() + "_"
4288 + sDateStamp.getSeconds() + ".txt";
4289
4290 FileOutputStream fos = null;
4291 File outFile = null;
4292 try {
4293 outFile = new File(getFilesDir(), FILENAME);
4294 outFile.createNewFile();
4295 fos = new FileOutputStream(outFile);
4296 } catch (Exception e) {
4297 e.printStackTrace();
4298 }
4299 if (fos != null) {
4300 PrintWriter writer = new PrintWriter(fos);
4301
4302 writer.println(" ");
4303 writer.println("Debug logs: ");
4304 synchronized (sDumpLogs) {
4305 for (int i = 0; i < sDumpLogs.size(); i++) {
4306 writer.println(" " + sDumpLogs.get(i));
4307 }
4308 }
4309 writer.close();
4310 }
4311 try {
4312 if (fos != null) {
4313 fos.close();
4314 success = true;
4315 }
4316 } catch (IOException e) {
4317 e.printStackTrace();
4318 }
4319
4320 if (success && email) {
4321 if (!emailSent()) {
4322 emailFile(outFile);
4323 }
4324 }
4325 }
4326 }.start();
4327 }
4328
4329 private void emailFile(File file) {
4330 File publicCopy = new File(Environment.getExternalStorageDirectory(), file.getName());
4331 try {
4332 copyFile(file, publicCopy);
4333 } catch (IOException e) {
4334 e.printStackTrace();
4335 return;
4336 }
4337
4338 Intent intent = new Intent(Intent.ACTION_SEND);
4339 intent.setType("text/plain");
4340 intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"adamcohen@google.com, winsonc@google.com," +
4341 "mikejurka@google"});
4342 intent.putExtra(Intent.EXTRA_SUBJECT, "Data corruption " + file.getName());
4343 intent.putExtra(Intent.EXTRA_TEXT, "Data corruption has occurred, logs attached");
4344
4345 if (!file.exists() || !file.canRead()) {
4346 Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
4347 finish();
4348 return;
4349 }
4350
4351 Toast.makeText(this, "Data corruption has occurred, please send e-mail", Toast.LENGTH_LONG);
4352 Uri uri = Uri.fromFile(publicCopy);
4353 intent.putExtra(Intent.EXTRA_STREAM, uri);
4354 startActivity(Intent.createChooser(intent, "Please send logs, consider clearing data"));
4355
4356 setEmailSent(true);
4357 }
4358
4359 public void copyFile(File src, File dst) throws IOException {
4360 InputStream in = new FileInputStream(src);
4361 OutputStream out = new FileOutputStream(dst);
4362
4363 // Transfer bytes from in to out
4364 byte[] buf = new byte[1024];
4365 int len;
4366 while ((len = in.read(buf)) > 0) {
4367 out.write(buf, 0, len);
4368 }
4369 in.close();
4370 out.close();
Adam Cohen487f7dd2012-06-28 18:12:10 -07004371 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004372}
Michael Jurka2763be32011-02-24 11:19:57 -08004373
Michael Jurkaabded662011-03-04 12:06:57 -08004374interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004375 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004376 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004377 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004378 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004379 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004380}