blob: 473a3d15828f7dc03c97f8972ee380f5deca882f [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
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
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;
Craig Mautner360310b2012-10-26 15:13:08 -070053import android.graphics.Color;
Adam Cohen268c4752012-06-06 17:47:33 -070054import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Craig Mautner360310b2012-10-26 15:13:08 -070056import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Michael Jurkae233a8b2013-03-19 13:49:20 +010066import android.os.UserManager;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070067import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080068import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080074import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080075import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
79import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070080import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080081import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080083import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070084import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080085import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080086import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070087import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080088import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070089import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070090import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080091import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070093import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070094import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070095import android.widget.TextView;
96import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070097
Adam Cohendf2cc412011-04-27 16:56:57 -070098import com.android.common.Search;
99import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -0700100import com.android.launcher2.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 Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.io.FileNotFoundException;
106import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700107import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700108import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700109import java.util.Collection;
110import java.util.Collections;
111import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700112import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700113import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700114import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700115import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117/**
118 * Default launcher application.
119 */
Michael Jurka946ad472010-07-09 18:05:18 -0700120public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700121 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700122 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800123 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700124 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
Joe Onorato9c1289c2009-08-17 11:03:03 -0400126 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400127 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700128 static final boolean DEBUG_STRICT_MODE = false;
Michael Jurka447bf842013-05-15 14:52:15 +0200129 static final boolean DEBUG_RESUME_TIME = true;
Romain Guy6fefcf12009-06-11 13:07:43 -0700130
Winson Chung70d72102011-08-12 11:24:35 -0700131 private static final int MENU_GROUP_WALLPAPER = 1;
132 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
133 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700134 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
135 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
137 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700138 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 private static final int REQUEST_PICK_APPLICATION = 6;
140 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700141 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700142 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
Michael Jurka8b805b12012-04-18 14:23:14 -0700144 private static final int REQUEST_BIND_APPWIDGET = 11;
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
147
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800148 static final int SCREEN_COUNT = 5;
149 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Romain Guy98d01652009-06-30 16:21:04 -0700151 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800152 // To turn on these properties, type
153 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
154 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
155 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
Winson Chung2672ff92012-05-04 16:22:30 -0700157 // The Intent extra that defines whether to ignore the launch animation
158 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
159 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
160
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 // Type: int
162 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700163 // Type: int
164 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700166 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
167 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
169 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700172 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 // Type: boolean
174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
175 // Type: long
176 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700177 // Type: int
178 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
179 // Type: int
180 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
181 // Type: parcelable
182 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700184 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700185 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
186 "com.android.launcher.toolbar_search_icon";
187 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
188 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700189
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700190 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700191 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700192 private State mState = State.WORKSPACE;
193 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800194 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700195
Joe Onorato9c1289c2009-08-17 11:03:03 -0400196 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700197 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
198 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700199 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700200 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800203 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
Winson Chunga2413752012-04-03 14:22:34 -0700205 // How long to wait before the new-shortcut animation automatically pans the workspace
206 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
207
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800208 private final BroadcastReceiver mCloseSystemDialogsReceiver
209 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800210 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private LayoutInflater mInflater;
213
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800215 private View mQsbDivider;
216 private View mDockDivider;
Craig Mautner360310b2012-10-26 15:13:08 -0700217 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800218 private DragLayer mDragLayer;
219 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700220
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700221 private AppWidgetManager mAppWidgetManager;
222 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700223
Michael Jurkac9d95c52011-08-29 14:03:34 -0700224 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700225 private AppWidgetProviderInfo mPendingAddWidgetInfo;
226
Michael Jurka0280c3b2010-09-17 15:00:07 -0700227 private int[] mTmpAddItemCellCoordinates = new int[2];
228
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 private FolderInfo mFolderInfo;
230
Winson Chung3d503fb2011-07-13 17:25:49 -0700231 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800232 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700233
Winson Chungc51db6a2011-10-05 11:44:49 -0700234 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700235 private AppsCustomizeTabHost mAppsCustomizeTabHost;
236 private AppsCustomizePagedView mAppsCustomizeContent;
237 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800239 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700240 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
241 // scroll issues (because the workspace may not have been measured yet) and extra work.
242 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
243 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244
245 private SpannableStringBuilder mDefaultKeySsb = null;
246
Joe Onorato9c1289c2009-08-17 11:03:03 -0400247 private boolean mWorkspaceLoading = true;
248
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800249 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 private boolean mRestoring;
251 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700252 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253
Michael Jurka7607c2f2013-04-03 14:33:19 -0700254 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
255
Winson Chung4a2afa32012-07-19 14:53:05 -0700256 // Keep track of whether the user has left launcher
257 private static boolean sPausedFromUserAction = false;
258
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 private Bundle mSavedInstanceState;
260
Joe Onorato9c1289c2009-08-17 11:03:03 -0400261 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800262 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800263 private boolean mUserPresent = true;
264 private boolean mVisible = false;
265 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400266
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700267 private static LocaleConfiguration sLocaleConfiguration = null;
268
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700269 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700270
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700271 private Intent mAppMarketIntent = null;
272
Adam Cohended9f8d2010-11-03 13:25:16 -0700273 // Related to the auto-advancing of widgets
274 private final int ADVANCE_MSG = 1;
275 private final int mAdvanceInterval = 20000;
276 private final int mAdvanceStagger = 250;
277 private long mAutoAdvanceSentTime;
278 private long mAutoAdvanceTimeLeft = -1;
279 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
280 new HashMap<View, AppWidgetProviderInfo>();
281
Winson Chung400438b2011-01-16 17:53:48 -0800282 // Determines how long to wait after a rotation before restoring the screen orientation to
283 // match the sensor state.
284 private final int mRestoreScreenOrientationDelay = 500;
285
Michael Jurka4ef207b2010-11-29 17:05:45 -0800286 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700287 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
288 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
289 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800290
Craig Mautner360310b2012-10-26 15:13:08 -0700291 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700292
Adam Cohen1462de32012-07-24 22:34:36 -0700293 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
294
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700295 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
296
Winson Chung46353de2012-02-16 14:05:10 -0800297 // We only want to get the SharedPreferences once since it does an FS stat each time we get
298 // it from the context.
299 private SharedPreferences mSharedPrefs;
300
Winson Chungf0c6ae02012-03-21 16:10:31 -0700301 // Holds the page that we need to animate to, and the icon views that we need to animate up
302 // when we scroll to that page on resume.
303 private int mNewShortcutAnimatePage = -1;
304 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700305 private ImageView mFolderIconImageView;
306 private Bitmap mFolderIconBitmap;
307 private Canvas mFolderIconCanvas;
308 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700309
Michael Jurkaddd62e92011-02-16 17:49:14 -0800310 private BubbleTextView mWaitingForResume;
311
Michael Jurka22143132012-10-04 17:42:38 +0200312 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
313 = new HideFromAccessibilityHelper();
314
Michael Jurkac1f5d262011-09-30 19:32:27 -0700315 private Runnable mBuildLayersRunnable = new Runnable() {
316 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700317 if (mWorkspace != null) {
318 mWorkspace.buildPageHardwareLayers();
319 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700320 }
321 };
322
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800323 private static ArrayList<PendingAddArguments> sPendingAddList
324 = new ArrayList<PendingAddArguments>();
325
Michael Jurka0a457bf2012-11-19 14:05:05 -0800326 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
327
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800328 private static class PendingAddArguments {
329 int requestCode;
330 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700331 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800332 int screen;
333 int cellX;
334 int cellY;
335 }
336
Michael Jurka0a457bf2012-11-19 14:05:05 -0800337 private static boolean isPropertyEnabled(String propertyName) {
338 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700339 }
340
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 @Override
342 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700343 if (DEBUG_STRICT_MODE) {
344 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
345 .detectDiskReads()
346 .detectDiskWrites()
347 .detectNetwork() // or .detectAll() for all detectable problems
348 .penaltyLog()
349 .build());
350 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
351 .detectLeakedSqlLiteObjects()
352 .detectLeakedClosableObjects()
353 .penaltyLog()
354 .penaltyDeath()
355 .build());
356 }
357
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800359 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700360 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
361 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800362 mModel = app.setLauncher(this);
363 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400364 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700366
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700367 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700368 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
369 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700370
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700371 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
372 // this also ensures that any synchronous binding below doesn't re-trigger another
373 // LauncherModel load.
374 mPaused = false;
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200377 android.os.Debug.startMethodTracing(
378 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 }
380
381 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 setContentView(R.layout.launcher);
383 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700384 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800386 registerContentObservers();
387
Joe Onorato7c312c12009-08-13 21:36:53 -0700388 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 mSavedState = savedInstanceState;
391 restoreState(mSavedState);
392
Winson Chunga12a2502010-12-20 14:41:35 -0800393 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700394 if (mAppsCustomizeContent != null) {
395 mAppsCustomizeContent.onPackagesUpdated();
396 }
Winson Chunga12a2502010-12-20 14:41:35 -0800397
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800398 if (PROFILE_STARTUP) {
399 android.os.Debug.stopMethodTracing();
400 }
401
402 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700403 if (sPausedFromUserAction) {
404 // If the user leaves launcher, then we should just load items asynchronously when
405 // they return.
406 mModel.startLoader(true, -1);
407 } else {
408 // We only load the page synchronously if the user rotates (or triggers a
409 // configuration change) while launcher is in the foreground
410 mModel.startLoader(true, mWorkspace.getCurrentPage());
411 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800412 }
413
Michael Jurkac57b7a82011-08-09 22:02:20 -0700414 if (!mModel.isAllAppsLoaded()) {
415 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
416 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
417 }
418
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 // For handling default keys
420 mDefaultKeySsb = new SpannableStringBuilder();
421 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800422
423 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
424 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800425
Adam Cohenf9426d52012-06-04 17:26:21 -0700426 updateGlobalIcons();
427
428 // On large interfaces, we want the screen to auto-rotate based on the current orientation
429 unlockScreenOrientation(true);
430 }
431
Winson Chung4a2afa32012-07-19 14:53:05 -0700432 protected void onUserLeaveHint() {
433 super.onUserLeaveHint();
434 sPausedFromUserAction = true;
435 }
436
Adam Cohenf9426d52012-06-04 17:26:21 -0700437 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700438 boolean searchVisible = false;
439 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800440 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700441 int coi = getCurrentOrientationIndexForGlobalIcons();
442 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
443 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700444 updateAppMarketIcon();
445 searchVisible = updateGlobalSearchIcon();
446 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700447 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700448 if (sGlobalSearchIcon[coi] != null) {
449 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700450 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700451 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700452 if (sVoiceSearchIcon[coi] != null) {
453 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700454 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700455 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700456 if (sAppMarketIcon[coi] != null) {
457 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800458 }
Winson Chungadf0c182012-08-23 14:59:07 -0700459 if (mSearchDropTargetBar != null) {
460 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
461 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 }
Romain Guycbb89e42009-06-08 15:52:54 -0700463
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700465 if (sLocaleConfiguration == null) {
466 new AsyncTask<Void, Void, LocaleConfiguration>() {
467 @Override
468 protected LocaleConfiguration doInBackground(Void... unused) {
469 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
470 readConfiguration(Launcher.this, localeConfiguration);
471 return localeConfiguration;
472 }
473
474 @Override
475 protected void onPostExecute(LocaleConfiguration result) {
476 sLocaleConfiguration = result;
477 checkForLocaleChange(); // recursive, but now with a locale configuration
478 }
479 }.execute();
480 return;
481 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700482
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800483 final Configuration configuration = getResources().getConfiguration();
484
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700485 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800486 final String locale = configuration.locale.toString();
487
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700488 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800489 final int mcc = configuration.mcc;
490
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700491 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800492 final int mnc = configuration.mnc;
493
Romain Guy84f296c2009-11-04 15:00:44 -0800494 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800495
Romain Guy84f296c2009-11-04 15:00:44 -0800496 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700497 sLocaleConfiguration.locale = locale;
498 sLocaleConfiguration.mcc = mcc;
499 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700500
Joe Onorato0589f0f2010-02-08 13:44:00 -0800501 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700502
503 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
504 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700505 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700506 public void run() {
507 writeConfiguration(Launcher.this, localeConfiguration);
508 }
509 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700510 }
511 }
512
513 private static class LocaleConfiguration {
514 public String locale;
515 public int mcc = -1;
516 public int mnc = -1;
517 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700518
Romain Guy98d01652009-06-30 16:21:04 -0700519 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
520 DataInputStream in = null;
521 try {
522 in = new DataInputStream(context.openFileInput(PREFERENCES));
523 configuration.locale = in.readUTF();
524 configuration.mcc = in.readInt();
525 configuration.mnc = in.readInt();
526 } catch (FileNotFoundException e) {
527 // Ignore
528 } catch (IOException e) {
529 // Ignore
530 } finally {
531 if (in != null) {
532 try {
533 in.close();
534 } catch (IOException e) {
535 // Ignore
536 }
537 }
538 }
539 }
540
541 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
542 DataOutputStream out = null;
543 try {
544 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
545 out.writeUTF(configuration.locale);
546 out.writeInt(configuration.mcc);
547 out.writeInt(configuration.mnc);
548 out.flush();
549 } catch (FileNotFoundException e) {
550 // Ignore
551 } catch (IOException e) {
552 //noinspection ResultOfMethodCallIgnored
553 context.getFileStreamPath(PREFERENCES).delete();
554 } finally {
555 if (out != null) {
556 try {
557 out.close();
558 } catch (IOException e) {
559 // Ignore
560 }
561 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800562 }
563 }
564
Adam Cohen716b51e2011-06-30 12:09:54 -0700565 public DragLayer getDragLayer() {
566 return mDragLayer;
567 }
568
Winson Chung36a62fe2012-05-06 18:04:42 -0700569 boolean isDraggingEnabled() {
570 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
571 // that is subsequently removed from the workspace in startBinding().
572 return !mModel.isLoadingWorkspace();
573 }
574
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 static int getScreen() {
576 synchronized (sLock) {
577 return sScreen;
578 }
579 }
580
581 static void setScreen(int screen) {
582 synchronized (sLock) {
583 sScreen = screen;
584 }
585 }
586
Winson Chung557d6ed2011-07-08 15:34:52 -0700587 /**
588 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
589 * a configuration step, this allows the proper animations to run after other transitions.
590 */
591 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700592 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800593 switch (args.requestCode) {
594 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700595 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
596 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800597 break;
598 case REQUEST_PICK_SHORTCUT:
599 processShortcut(args.intent);
600 break;
601 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700602 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
603 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700604 result = true;
605 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800606 case REQUEST_CREATE_APPWIDGET:
607 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800608 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700609 result = true;
610 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800611 case REQUEST_PICK_WALLPAPER:
612 // We just wanted the activity result here so we can clear mWaitingForResult
613 break;
614 }
Michael Jurka27614d22012-04-02 06:40:22 -0700615 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
616 // if you turned the screen off and then back while in All Apps, Launcher would not
617 // return to the workspace. Clearing mAddInfo.container here fixes this issue
618 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700619 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800620 }
621
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800622 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700623 protected void onActivityResult(
624 final int requestCode, final int resultCode, final Intent data) {
625 if (requestCode == REQUEST_BIND_APPWIDGET) {
626 int appWidgetId = data != null ?
627 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
628 if (resultCode == RESULT_CANCELED) {
629 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
630 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700631 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700632 }
633 return;
634 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700635 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800636 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
637 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700638 mWaitingForResult = false;
639
Adam Cohened66b2b2012-01-23 17:28:51 -0800640 // We have special handling for widgets
641 if (isWidgetDrop) {
642 int appWidgetId = data != null ?
643 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700644 if (appWidgetId < 0) {
645 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
646 "widget configuration activity.");
647 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
648 } else {
649 completeTwoStageWidgetDrop(resultCode, appWidgetId);
650 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800651 return;
652 }
653
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800654 // The pattern used here is that a user PICKs a specific application,
655 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700656
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
658 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700659 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800660 final PendingAddArguments args = new PendingAddArguments();
661 args.requestCode = requestCode;
662 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700663 args.container = mPendingAddInfo.container;
664 args.screen = mPendingAddInfo.screen;
665 args.cellX = mPendingAddInfo.cellX;
666 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800667 if (isWorkspaceLocked()) {
668 sPendingAddList.add(args);
669 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700670 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800673 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700674 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800675 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
676 null);
677 }
678
679 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700680 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700681 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800682 Runnable onCompleteRunnable = null;
683 int animationType = 0;
684
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700685 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800686 if (resultCode == RESULT_OK) {
687 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
688 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700689 mPendingAddWidgetInfo);
690 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800691 onCompleteRunnable = new Runnable() {
692 @Override
693 public void run() {
694 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
695 mPendingAddInfo.screen, layout, null);
696 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
697 null);
698 }
699 };
700 } else if (resultCode == RESULT_CANCELED) {
701 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
702 onCompleteRunnable = new Runnable() {
703 @Override
704 public void run() {
705 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
706 null);
707 }
708 };
709 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700710 if (mDragLayer.getAnimatedView() != null) {
711 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
712 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
713 animationType, boundWidget, true);
714 } else {
715 // The animated view may be null in the case of a rotation during widget configuration
716 onCompleteRunnable.run();
717 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800718 }
719
720 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700721 protected void onStop() {
722 super.onStop();
723 FirstFrameAnimatorHelper.setIsVisible(false);
724 }
725
726 @Override
727 protected void onStart() {
728 super.onStart();
729 FirstFrameAnimatorHelper.setIsVisible(true);
730 }
731
732 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800733 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200734 long startTime = 0;
735 if (DEBUG_RESUME_TIME) {
736 startTime = System.currentTimeMillis();
737 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800738 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700739
Winson Chung4a2afa32012-07-19 14:53:05 -0700740 // Restore the previous launcher state
741 if (mOnResumeState == State.WORKSPACE) {
742 showWorkspace(false);
743 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
744 showAllApps(false);
745 }
746 mOnResumeState = State.NONE;
747
Craig Mautner360310b2012-10-26 15:13:08 -0700748 // Background was set to gradient in onPause(), restore to black if in all apps.
749 setWorkspaceBackground(mState == State.WORKSPACE);
750
Winson Chungde0fb8f2012-05-08 14:37:08 -0700751 // Process any items that were added while Launcher was away
752 InstallShortcutReceiver.flushInstallQueue(this);
753
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800754 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700755 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700756 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400757 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700758 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400759 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700760 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800761 }
Michael Jurka7607c2f2013-04-03 14:33:19 -0700762 // We might have postponed some bind calls until onResume (see waitUntilResume) --
763 // execute them here
Michael Jurka447bf842013-05-15 14:52:15 +0200764 long startTimeCallbacks = 0;
765 if (DEBUG_RESUME_TIME) {
766 startTimeCallbacks = System.currentTimeMillis();
767 }
Michael Jurka7607c2f2013-04-03 14:33:19 -0700768 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
769 mOnResumeCallbacks.get(i).run();
770 }
771 mOnResumeCallbacks.clear();
Michael Jurka447bf842013-05-15 14:52:15 +0200772 if (DEBUG_RESUME_TIME) {
773 Log.d(TAG, "Time spent processing callbacks in onResume: " +
774 (System.currentTimeMillis() - startTimeCallbacks));
775 }
Winson Chunge4e50662012-01-23 14:45:13 -0800776
777 // Reset the pressed state of icons that were locked in the press state while activities
778 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800779 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800780 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800781 mWaitingForResume.setStayPressed(false);
782 }
Winson Chunge4e50662012-01-23 14:45:13 -0800783 if (mAppsCustomizeContent != null) {
784 // Resets the previous all apps icon press state
785 mAppsCustomizeContent.resetDrawableState();
786 }
Adam Cohen06dff352012-06-01 17:17:08 -0700787 // It is possible that widgets can receive updates while launcher is not in the foreground.
788 // Consequently, the widgets will be inflated in the orientation of the foreground activity
789 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
790 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700791 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700792
793 // Again, as with the above scenario, it's possible that one or more of the global icons
794 // were updated in the wrong orientation.
795 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200796 if (DEBUG_RESUME_TIME) {
797 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
798 }
Adam Cohen06dff352012-06-01 17:17:08 -0700799 }
800
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800801 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700802 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700803 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
804 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
805 // when Launcher resumes and we are still in AllApps.
806 updateWallpaperVisibility(true);
807
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700808 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700809 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800810 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700811 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700812 }
Romain Guycbb89e42009-06-08 15:52:54 -0700813
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700814 @Override
815 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400816 // Flag the loader to stop early before switching
817 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700818 if (mAppsCustomizeContent != null) {
819 mAppsCustomizeContent.surrender();
820 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800821 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700822 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700823
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800824 // We can't hide the IME if it was forced open. So don't bother
825 /*
826 @Override
827 public void onWindowFocusChanged(boolean hasFocus) {
828 super.onWindowFocusChanged(hasFocus);
829
830 if (hasFocus) {
831 final InputMethodManager inputManager = (InputMethodManager)
832 getSystemService(Context.INPUT_METHOD_SERVICE);
833 WindowManager.LayoutParams lp = getWindow().getAttributes();
834 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
835 android.os.Handler()) {
836 protected void onReceiveResult(int resultCode, Bundle resultData) {
837 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
838 }
839 });
840 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
841 }
842 }
843 */
844
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 private boolean acceptFilter() {
846 final InputMethodManager inputManager = (InputMethodManager)
847 getSystemService(Context.INPUT_METHOD_SERVICE);
848 return !inputManager.isFullscreenMode();
849 }
850
851 @Override
852 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700853 final int uniChar = event.getUnicodeChar();
854 final boolean handled = super.onKeyDown(keyCode, event);
855 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
856 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
858 keyCode, event);
859 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700860 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700861 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700862 // showSearchDialog()
863 // If there are multiple keystrokes before the search dialog takes focus,
864 // onSearchRequested() will be called for every keystroke,
865 // but it is idempotent, so it's fine.
866 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 }
868 }
869
Joe Onorato8a9625e2010-01-28 15:55:35 -0800870 // Eat the long press event so the keyboard doesn't come up.
871 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
872 return true;
873 }
874
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800875 return handled;
876 }
877
Karl Rosaen138a0412009-04-23 19:00:21 -0700878 private String getTypedText() {
879 return mDefaultKeySsb.toString();
880 }
881
882 private void clearTypedText() {
883 mDefaultKeySsb.clear();
884 mDefaultKeySsb.clearSpans();
885 Selection.setSelection(mDefaultKeySsb, 0);
886 }
887
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700889 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
890 * State
891 */
892 private static State intToState(int stateOrdinal) {
893 State state = State.WORKSPACE;
894 final State[] stateValues = State.values();
895 for (int i = 0; i < stateValues.length; i++) {
896 if (stateValues[i].ordinal() == stateOrdinal) {
897 state = stateValues[i];
898 break;
899 }
900 }
901 return state;
902 }
903
904 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905 * Restores the previous state, if it exists.
906 *
907 * @param savedState The previous state.
908 */
909 private void restoreState(Bundle savedState) {
910 if (savedState == null) {
911 return;
912 }
913
Michael Jurka883f55b2010-10-21 15:47:14 -0700914 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700915 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700916 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800917 }
918
Winson Chungf0c6ae02012-03-21 16:10:31 -0700919 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800920 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700921 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 }
923
Winson Chung3d503fb2011-07-13 17:25:49 -0700924 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
925 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700926
Winson Chung3d503fb2011-07-13 17:25:49 -0700927 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
928 mPendingAddInfo.container = pendingAddContainer;
929 mPendingAddInfo.screen = pendingAddScreen;
930 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
931 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700932 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
933 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
934 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700935 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800936 mRestoring = true;
937 }
938
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700939
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
941 if (renameFolder) {
942 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700943 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800944 mRestoring = true;
945 }
Winson Chunga12a2502010-12-20 14:41:35 -0800946
Winson Chung785d2eb2011-04-14 16:08:02 -0700947
948 // Restore the AppsCustomize tab
949 if (mAppsCustomizeTabHost != null) {
950 String curTab = savedState.getString("apps_customize_currentTab");
951 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -0700952 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -0700953 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -0700954 mAppsCustomizeContent.loadAssociatedPages(
955 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700956 }
957
Winson Chung5afbf7b2011-07-25 11:53:08 -0700958 int currentIndex = savedState.getInt("apps_customize_currentIndex");
959 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700960 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800961 }
962
963 /**
964 * Finds all the views we need and configure them properly.
965 */
966 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700967 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400968
Craig Mautner360310b2012-10-26 15:13:08 -0700969 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -0700970 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
971 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -0700972 mQsbDivider = findViewById(R.id.qsb_divider);
973 mDockDivider = findViewById(R.id.dock_divider);
974
975 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
976 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977
Winson Chung4c98d922011-05-31 16:50:48 -0700978 // Setup the drag layer
979 mDragLayer.setup(this, dragController);
980
Winson Chung3d503fb2011-07-13 17:25:49 -0700981 // Setup the hotseat
982 mHotseat = (Hotseat) findViewById(R.id.hotseat);
983 if (mHotseat != null) {
984 mHotseat.setup(this);
985 }
986
Winson Chung4c98d922011-05-31 16:50:48 -0700987 // Setup the workspace
988 mWorkspace.setHapticFeedbackEnabled(false);
989 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700990 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700991 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700992
Winson Chungf0ea4d32011-06-06 14:27:16 -0700993 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700994 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700995
Winson Chungf0ea4d32011-06-06 14:27:16 -0700996 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -0700997 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700998 mAppsCustomizeContent = (AppsCustomizePagedView)
999 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1000 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001001
Winson Chung3d503fb2011-07-13 17:25:49 -07001002 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001003 dragController.setDragScoller(mWorkspace);
1004 dragController.setScrollView(mDragLayer);
1005 dragController.setMoveTarget(mWorkspace);
1006 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001007 if (mSearchDropTargetBar != null) {
1008 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001009 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 }
1011
1012 /**
1013 * Creates a view representing a shortcut.
1014 *
1015 * @param info The data structure describing the shortcut.
1016 *
1017 * @return A View inflated from R.layout.application.
1018 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001019 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001021 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 }
1023
1024 /**
1025 * Creates a view representing a shortcut inflated from the specified resource.
1026 *
1027 * @param layoutResId The id of the XML layout used to create the shortcut.
1028 * @param parent The group the shortcut belongs to.
1029 * @param info The data structure describing the shortcut.
1030 *
1031 * @return A View inflated from layoutResId.
1032 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001033 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001034 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1035 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001036 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 return favorite;
1038 }
1039
1040 /**
1041 * Add an application shortcut to the workspace.
1042 *
1043 * @param data The intent describing the application.
1044 * @param cellInfo The position on screen where to create the shortcut.
1045 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001046 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001047 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -07001048 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001049
Adam Cohenfbba09b2011-07-18 21:43:05 -07001050 // First we check if we already know the exact location where we want to add this item.
1051 if (cellX >= 0 && cellY >= 0) {
1052 cellXY[0] = cellX;
1053 cellXY[1] = cellY;
1054 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001055 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001056 return;
1057 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001059 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001060
Romain Guy73b979d2009-06-09 12:57:21 -07001061 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001062 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001064 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -07001065 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001066 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001067 } else {
1068 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001069 }
1070 }
Romain Guycbb89e42009-06-08 15:52:54 -07001071
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001072 /**
1073 * Add a shortcut to the workspace.
1074 *
1075 * @param data The intent describing the shortcut.
1076 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001078 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1079 int cellY) {
1080 int[] cellXY = mTmpAddItemCellCoordinates;
1081 int[] touchXY = mPendingAddInfo.dropPos;
1082 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001083
Michael Jurkad3ef3062010-11-23 16:23:58 -08001084 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001085
Adam Cohen558baaf2011-08-15 15:22:57 -07001086 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001087 if (info == null) {
1088 return;
1089 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001090 final View view = createShortcut(info);
1091
Adam Cohenfbba09b2011-07-18 21:43:05 -07001092 // First we check if we already know the exact location where we want to add this item.
1093 if (cellX >= 0 && cellY >= 0) {
1094 cellXY[0] = cellX;
1095 cellXY[1] = cellY;
1096 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001097
1098 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001099 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001100 true, null,null)) {
1101 return;
1102 }
1103 DragObject dragObject = new DragObject();
1104 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001105 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1106 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001107 return;
1108 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001109 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001110 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001111 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001112 foundCellSpan = (result != null);
1113 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001114 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001115 }
1116
1117 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001118 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001119 return;
1120 }
1121
Adam Cohen558baaf2011-08-15 15:22:57 -07001122 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123
1124 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001125 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1126 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127 }
1128 }
1129
Adam Cohen2f093b62012-04-30 18:59:53 -07001130 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1131 int minHeight) {
1132 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001133 // We want to account for the extra amount of padding that we are adding to the widget
1134 // to ensure that it gets the full amount of space that it has requested
1135 int requiredWidth = minWidth + padding.left + padding.right;
1136 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001137 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001138 }
1139
Adam Cohen2f093b62012-04-30 18:59:53 -07001140 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1141 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001142 }
1143
Adam Cohen2f093b62012-04-30 18:59:53 -07001144 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1145 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001146 }
1147
Adam Cohen2f093b62012-04-30 18:59:53 -07001148 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1149 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001150 }
1151
Adam Cohen2f093b62012-04-30 18:59:53 -07001152 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1153 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001154 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001155 }
1156
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001157 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001158 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001160 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001161 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001163 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1164 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1165 if (appWidgetInfo == null) {
1166 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1167 }
Romain Guycbb89e42009-06-08 15:52:54 -07001168
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001169 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001170 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001171
Adam Cohen2f093b62012-04-30 18:59:53 -07001172 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1173 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001176 // We have saved the position to which the widget was dragged-- this really only matters
1177 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001178 int[] cellXY = mTmpAddItemCellCoordinates;
1179 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001180 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001181 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001182 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1183 cellXY[0] = mPendingAddInfo.cellX;
1184 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001185 spanXY[0] = mPendingAddInfo.spanX;
1186 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001187 foundCellSpan = true;
1188 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001189 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001190 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001191 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1192 spanXY[1], cellXY, finalSpan);
1193 spanXY[0] = finalSpan[0];
1194 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001195 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001196 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001197 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001198 }
1199
Michael Jurka0280c3b2010-09-17 15:00:07 -07001200 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001201 if (appWidgetId != -1) {
1202 // Deleting an app widget ID is a void call but writes to disk before returning
1203 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001204 new Thread("deleteAppWidgetId") {
1205 public void run() {
1206 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1207 }
1208 }.start();
1209 }
Winson Chung93eef082012-03-23 15:59:27 -07001210 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001211 return;
1212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001214 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001215 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1216 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001217 launcherInfo.spanX = spanXY[0];
1218 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001219 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1220 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001221
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001223 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224
1225 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001226 if (hostView == null) {
1227 // Perform actual inflation because we're live
1228 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1229 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1230 } else {
1231 // The AppWidgetHostView has already been inflated and instantiated
1232 launcherInfo.hostView = hostView;
1233 }
Romain Guycbb89e42009-06-08 15:52:54 -07001234
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001236 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001237 launcherInfo.notifyWidgetSizeChanged(this);
1238
Winson Chung3d503fb2011-07-13 17:25:49 -07001239 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001240 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001241
1242 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001244 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 }
Romain Guycbb89e42009-06-08 15:52:54 -07001246
Adam Cohended9f8d2010-11-03 13:25:16 -07001247 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1248 @Override
1249 public void onReceive(Context context, Intent intent) {
1250 final String action = intent.getAction();
1251 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1252 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001253 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001254 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001255
Winson Chungc100e8e2011-08-09 16:02:43 -07001256 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001257 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001258 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1259 mAppsCustomizeTabHost.reset();
1260 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001261 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001262 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1263 mUserPresent = true;
1264 updateRunning();
1265 }
1266 }
1267 };
1268
1269 @Override
1270 public void onAttachedToWindow() {
1271 super.onAttachedToWindow();
1272
1273 // Listen for broadcasts related to user-presence
1274 final IntentFilter filter = new IntentFilter();
1275 filter.addAction(Intent.ACTION_SCREEN_OFF);
1276 filter.addAction(Intent.ACTION_USER_PRESENT);
1277 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001278 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001279 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001280 mVisible = true;
1281 }
1282
1283 @Override
1284 public void onDetachedFromWindow() {
1285 super.onDetachedFromWindow();
1286 mVisible = false;
1287
Adam Cohend113e0c2010-11-11 10:48:05 -08001288 if (mAttached) {
1289 unregisterReceiver(mReceiver);
1290 mAttached = false;
1291 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001292 updateRunning();
1293 }
1294
1295 public void onWindowVisibilityChanged(int visibility) {
1296 mVisible = visibility == View.VISIBLE;
1297 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001298 // The following code used to be in onResume, but it turns out onResume is called when
1299 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1300 // is a more appropriate event to handle
1301 if (mVisible) {
1302 mAppsCustomizeTabHost.onWindowVisible();
1303 if (!mWorkspaceLoading) {
1304 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001305 // We want to let Launcher draw itself at least once before we force it to build
1306 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001307 // apps is nice and speedy.
1308 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001309 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001310 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001311 if (mStarted) return;
1312 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001313 // We delay the layer building a bit in order to give
1314 // other message processing a time to run. In particular
1315 // this avoids a delay in hiding the IME if it was
1316 // currently shown, because doing that may involve
1317 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001318 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001319 final ViewTreeObserver.OnDrawListener listener = this;
1320 mWorkspace.post(new Runnable() {
1321 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001322 if (mWorkspace != null &&
1323 mWorkspace.getViewTreeObserver() != null) {
1324 mWorkspace.getViewTreeObserver().
1325 removeOnDrawListener(listener);
1326 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001327 }
1328 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001329 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001330 }
1331 });
1332 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001333 // When Launcher comes back to foreground, a different Activity might be responsible for
1334 // the app market intent, so refresh the icon
1335 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001336 clearTypedText();
1337 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001338 }
1339
1340 private void sendAdvanceMessage(long delay) {
1341 mHandler.removeMessages(ADVANCE_MSG);
1342 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1343 mHandler.sendMessageDelayed(msg, delay);
1344 mAutoAdvanceSentTime = System.currentTimeMillis();
1345 }
1346
1347 private void updateRunning() {
1348 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1349 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1350 mAutoAdvanceRunning = autoAdvanceRunning;
1351 if (autoAdvanceRunning) {
1352 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1353 sendAdvanceMessage(delay);
1354 } else {
1355 if (!mWidgetsToAdvance.isEmpty()) {
1356 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1357 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1358 }
1359 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001360 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001361 }
1362 }
1363 }
1364
1365 private final Handler mHandler = new Handler() {
1366 @Override
1367 public void handleMessage(Message msg) {
1368 if (msg.what == ADVANCE_MSG) {
1369 int i = 0;
1370 for (View key: mWidgetsToAdvance.keySet()) {
1371 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1372 final int delay = mAdvanceStagger * i;
1373 if (v instanceof Advanceable) {
1374 postDelayed(new Runnable() {
1375 public void run() {
1376 ((Advanceable) v).advance();
1377 }
1378 }, delay);
1379 }
1380 i++;
1381 }
1382 sendAdvanceMessage(mAdvanceInterval);
1383 }
1384 }
1385 };
1386
1387 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001388 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001389 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1390 if (v instanceof Advanceable) {
1391 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001392 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001393 updateRunning();
1394 }
1395 }
1396
1397 void removeWidgetToAutoAdvance(View hostView) {
1398 if (mWidgetsToAdvance.containsKey(hostView)) {
1399 mWidgetsToAdvance.remove(hostView);
1400 updateRunning();
1401 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001402 }
1403
Joe Onorato9c1289c2009-08-17 11:03:03 -04001404 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001405 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001406 launcherInfo.hostView = null;
1407 }
1408
Winson Chung93eef082012-03-23 15:59:27 -07001409 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1410 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1411 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001412 }
1413
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001414 public LauncherAppWidgetHost getAppWidgetHost() {
1415 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
Romain Guycbb89e42009-06-08 15:52:54 -07001417
Winson Chunga9abd0e2010-10-27 17:18:37 -07001418 public LauncherModel getModel() {
1419 return mModel;
1420 }
1421
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001422 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001423 getWindow().closeAllPanels();
1424
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001425 // Whatever we were doing is hereby canceled.
1426 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001427 }
1428
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001429 @Override
1430 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001431 long startTime = 0;
1432 if (DEBUG_RESUME_TIME) {
1433 startTime = System.currentTimeMillis();
1434 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 super.onNewIntent(intent);
1436
1437 // Close the menu
1438 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001439 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001440 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001441
Jamie Genniscb222e82012-10-23 15:44:26 -07001442 final boolean alreadyOnHome =
1443 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001444 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001445
Jamie Genniscb222e82012-10-23 15:44:26 -07001446 Runnable processIntent = new Runnable() {
1447 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001448 if (mWorkspace == null) {
1449 // Can be cases where mWorkspace is null, this prevents a NPE
1450 return;
1451 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001452 Folder openFolder = mWorkspace.getOpenFolder();
1453 // In all these cases, only animate if we're already on home
1454 mWorkspace.exitWidgetResizeMode();
1455 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1456 openFolder == null) {
1457 mWorkspace.moveToDefaultScreen(true);
1458 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001459
Jamie Genniscb222e82012-10-23 15:44:26 -07001460 closeFolder();
1461 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001462
Jamie Genniscb222e82012-10-23 15:44:26 -07001463 // If we are already on home, then just animate back to the workspace,
1464 // otherwise, just wait until onResume to set the state back to Workspace
1465 if (alreadyOnHome) {
1466 showWorkspace(true);
1467 } else {
1468 mOnResumeState = State.WORKSPACE;
1469 }
1470
1471 final View v = getWindow().peekDecorView();
1472 if (v != null && v.getWindowToken() != null) {
1473 InputMethodManager imm = (InputMethodManager)getSystemService(
1474 INPUT_METHOD_SERVICE);
1475 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1476 }
1477
1478 // Reset AllApps to its initial state
1479 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1480 mAppsCustomizeTabHost.reset();
1481 }
1482 }
1483 };
1484
1485 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1486 // Delay processing of the intent to allow the status bar animation to finish
1487 // first in order to avoid janky animations.
1488 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001489 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001490 // Process the intent immediately.
1491 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001492 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001493
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001494 }
Michael Jurka447bf842013-05-15 14:52:15 +02001495 if (DEBUG_RESUME_TIME) {
1496 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1497 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 }
1499
1500 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001501 public void onRestoreInstanceState(Bundle state) {
1502 super.onRestoreInstanceState(state);
1503 for (int page: mSynchronouslyBoundPages) {
1504 mWorkspace.restoreInstanceStateForChild(page);
1505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 }
1507
1508 @Override
1509 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001510 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001511 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001512
Michael Jurka883f55b2010-10-21 15:47:14 -07001513 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001514 // We close any open folder since it will not be re-opened, and we need to make sure
1515 // this state is reflected.
1516 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517
Winson Chung3d503fb2011-07-13 17:25:49 -07001518 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1519 mWaitingForResult) {
1520 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1521 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1522 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1523 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001524 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1525 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1526 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527 }
1528
1529 if (mFolderInfo != null && mWaitingForResult) {
1530 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1531 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1532 }
Michael Jurka946ad472010-07-09 18:05:18 -07001533
Winson Chung785d2eb2011-04-14 16:08:02 -07001534 // Save the current AppsCustomize tab
1535 if (mAppsCustomizeTabHost != null) {
1536 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1537 if (currentTabTag != null) {
1538 outState.putString("apps_customize_currentTab", currentTabTag);
1539 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001540 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1541 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001542 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 }
1544
1545 @Override
1546 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001547 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001548
Winson Chunge7a03942011-08-05 15:05:12 -07001549 // Remove all pending runnables
1550 mHandler.removeMessages(ADVANCE_MSG);
1551 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001552 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001553
Winson Chungcd2b0142011-06-08 16:02:26 -07001554 // Stop callbacks from LauncherModel
1555 LauncherApplication app = ((LauncherApplication) getApplication());
1556 mModel.stopLoader();
1557 app.setLauncher(null);
1558
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001560 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001562 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001564 mAppWidgetHost = null;
1565
1566 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567
1568 TextKeyListener.getInstance().release();
1569
Winson Chung81b52252012-08-27 15:34:29 -07001570 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1571 // to prevent leaking Launcher activities on orientation change.
1572 if (mModel != null) {
1573 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1574 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001575
1576 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001577 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001578
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001579 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001580 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1581 mWorkspace.removeAllViews();
1582 mWorkspace = null;
1583 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001584
Michael Jurka2ecf9952012-06-18 12:52:28 -07001585 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 }
1587
Adam Cohena9cf38f2011-05-02 15:36:58 -07001588 public DragController getDragController() {
1589 return mDragController;
1590 }
1591
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 @Override
1593 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001594 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 super.startActivityForResult(intent, requestCode);
1596 }
1597
Winson Chung70d72102011-08-12 11:24:35 -07001598 /**
1599 * Indicates that we want global search for this activity by setting the globalSearch
1600 * argument for {@link #startSearch} to true.
1601 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001603 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001605
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001606 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001607
Karl Rosaen138a0412009-04-23 19:00:21 -07001608 if (initialQuery == null) {
1609 // Use any text typed in the launcher as the initial query
1610 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001611 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 if (appSearchData == null) {
1613 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001614 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001615 }
Winson Chungadf0c182012-08-23 14:59:07 -07001616 Rect sourceBounds = new Rect();
1617 if (mSearchDropTargetBar != null) {
1618 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1619 }
Romain Guycbb89e42009-06-08 15:52:54 -07001620
Michael Jurkaa33411c2012-06-14 16:18:21 -07001621 startGlobalSearch(initialQuery, selectInitialQuery,
1622 appSearchData, sourceBounds);
1623 }
1624
1625 /**
1626 * Starts the global search activity. This code is a copied from SearchManager
1627 */
1628 public void startGlobalSearch(String initialQuery,
1629 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001630 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001631 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1632 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1633 if (globalSearchActivity == null) {
1634 Log.w(TAG, "No global search activity found.");
1635 return;
1636 }
1637 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1638 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1639 intent.setComponent(globalSearchActivity);
1640 // Make sure that we have a Bundle to put source in
1641 if (appSearchData == null) {
1642 appSearchData = new Bundle();
1643 } else {
1644 appSearchData = new Bundle(appSearchData);
1645 }
1646 // Set source to package name of app that starts global search, if not set already.
1647 if (!appSearchData.containsKey("source")) {
1648 appSearchData.putString("source", getPackageName());
1649 }
1650 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1651 if (!TextUtils.isEmpty(initialQuery)) {
1652 intent.putExtra(SearchManager.QUERY, initialQuery);
1653 }
1654 if (selectInitialQuery) {
1655 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1656 }
1657 intent.setSourceBounds(sourceBounds);
1658 try {
1659 startActivity(intent);
1660 } catch (ActivityNotFoundException ex) {
1661 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1662 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001663 }
1664
Winson Chung70d72102011-08-12 11:24:35 -07001665 @Override
1666 public boolean onCreateOptionsMenu(Menu menu) {
1667 if (isWorkspaceLocked()) {
1668 return false;
1669 }
1670
1671 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001672
1673 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1674 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1675 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001676 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1677 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1678 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001679 String helpUrl = getString(R.string.help_url);
1680 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001681 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1682 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1683
Winson Chung70d72102011-08-12 11:24:35 -07001684 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1685 .setIcon(android.R.drawable.ic_menu_gallery)
1686 .setAlphabeticShortcut('W');
1687 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1688 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001689 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001690 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001691 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1692 .setIcon(android.R.drawable.ic_menu_preferences)
1693 .setIntent(settings)
1694 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001695 if (!helpUrl.isEmpty()) {
1696 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1697 .setIcon(android.R.drawable.ic_menu_help)
1698 .setIntent(help)
1699 .setAlphabeticShortcut('H');
1700 }
Winson Chung70d72102011-08-12 11:24:35 -07001701 return true;
1702 }
1703
1704 @Override
1705 public boolean onPrepareOptionsMenu(Menu menu) {
1706 super.onPrepareOptionsMenu(menu);
1707
1708 if (mAppsCustomizeTabHost.isTransitioning()) {
1709 return false;
1710 }
1711 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1712 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1713
1714 return true;
1715 }
1716
1717 @Override
1718 public boolean onOptionsItemSelected(MenuItem item) {
1719 switch (item.getItemId()) {
1720 case MENU_WALLPAPER_SETTINGS:
1721 startWallpaper();
1722 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001723 }
1724
1725 return super.onOptionsItemSelected(item);
1726 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001728 @Override
1729 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001730 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001731 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001732 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001733 }
1734
Joe Onorato9c1289c2009-08-17 11:03:03 -04001735 public boolean isWorkspaceLocked() {
1736 return mWorkspaceLoading || mWaitingForResult;
1737 }
1738
Michael Jurka0280c3b2010-09-17 15:00:07 -07001739 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001740 mPendingAddInfo.container = ItemInfo.NO_ID;
1741 mPendingAddInfo.screen = -1;
1742 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1743 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001744 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001745 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001746 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001747
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001748 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1749 AppWidgetProviderInfo appWidgetInfo) {
1750 if (appWidgetInfo.configure != null) {
1751 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001752
Bjorn Bringert7984c942009-12-09 15:38:25 +00001753 // Launch over to configure widget, if needed
1754 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001755 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001756 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001757 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001759 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001760 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1761 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001762 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001763 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 }
1765 }
Romain Guycbb89e42009-06-08 15:52:54 -07001766
Adam Cohenfbba09b2011-07-18 21:43:05 -07001767 /**
1768 * Process a shortcut drop.
1769 *
1770 * @param componentName The name of the component
1771 * @param screen The screen where it should be added
1772 * @param cell The cell it should be added to, optional
1773 * @param position The location on the screen where it was dropped, optional
1774 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001775 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1776 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001777 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001778 mPendingAddInfo.container = container;
1779 mPendingAddInfo.screen = screen;
1780 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001781
1782 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001783 mPendingAddInfo.cellX = cell[0];
1784 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001785 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001786
1787 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1788 createShortcutIntent.setComponent(componentName);
1789 processShortcut(createShortcutIntent);
1790 }
1791
Adam Cohenfbba09b2011-07-18 21:43:05 -07001792 /**
1793 * Process a widget drop.
1794 *
1795 * @param info The PendingAppWidgetInfo of the widget being added.
1796 * @param screen The screen where it should be added
1797 * @param cell The cell it should be added to, optional
1798 * @param position The location on the screen where it was dropped, optional
1799 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001800 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001801 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001802 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001803 mPendingAddInfo.container = info.container = container;
1804 mPendingAddInfo.screen = info.screen = screen;
1805 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001806 mPendingAddInfo.minSpanX = info.minSpanX;
1807 mPendingAddInfo.minSpanY = info.minSpanY;
1808
Adam Cohenfbba09b2011-07-18 21:43:05 -07001809 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001810 mPendingAddInfo.cellX = cell[0];
1811 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001812 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001813 if (span != null) {
1814 mPendingAddInfo.spanX = span[0];
1815 mPendingAddInfo.spanY = span[1];
1816 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001817
Adam Cohened66b2b2012-01-23 17:28:51 -08001818 AppWidgetHostView hostView = info.boundWidget;
1819 int appWidgetId;
1820 if (hostView != null) {
1821 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001822 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001823 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001824 // In this case, we either need to start an activity to get permission to bind
1825 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001826 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001827 Bundle options = info.bindOptions;
1828
1829 boolean success = false;
1830 if (options != null) {
1831 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1832 info.componentName, options);
1833 } else {
1834 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1835 info.componentName);
1836 }
1837 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001838 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001839 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001840 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001841 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1842 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1843 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001844 // TODO: we need to make sure that this accounts for the options bundle.
1845 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001846 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1847 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001848 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001849 }
1850
Joe Onoratodeb98af2010-02-19 14:59:39 -08001851 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001852 // Handle case where user selected "Applications"
1853 String applicationName = getResources().getString(R.string.group_applications);
1854 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001855
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001856 if (applicationName != null && applicationName.equals(shortcutName)) {
1857 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1858 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001859
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001860 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1861 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001862 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001863 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001864 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001865 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001866 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001867 }
1868
Winson Chung24ab2f12010-09-16 14:10:47 -07001869 void processWallpaper(Intent intent) {
1870 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1871 }
1872
Winson Chung3d503fb2011-07-13 17:25:49 -07001873 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1874 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001875 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001876 folderInfo.title = getText(R.string.folder_name);
1877
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001879 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1880 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001881 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882
1883 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001884 FolderIcon newFolder =
1885 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1886 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1887 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001888 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 }
Romain Guycbb89e42009-06-08 15:52:54 -07001890
Joe Onorato9c1289c2009-08-17 11:03:03 -04001891 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001892 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001893 }
1894
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001895 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001896 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001898 Intent chooser = Intent.createChooser(pickWallpaper,
1899 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001900 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1901 // Removed in Eclair MR1
1902// WallpaperManager wm = (WallpaperManager)
1903// getSystemService(Context.WALLPAPER_SERVICE);
1904// WallpaperInfo wi = wm.getWallpaperInfo();
1905// if (wi != null && wi.getSettingsActivity() != null) {
1906// LabeledIntent li = new LabeledIntent(getPackageName(),
1907// R.string.configure_wallpaper, 0);
1908// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1909// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1910// }
Mike Clerona0618e42009-10-22 13:55:21 -07001911 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001912 }
1913
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001914 /**
1915 * Registers various content observers. The current implementation registers
1916 * only a favorites observer to keep track of the favorites applications.
1917 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001918 private void registerContentObservers() {
1919 ContentResolver resolver = getContentResolver();
1920 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1921 true, mWidgetObserver);
1922 }
1923
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001924 @Override
1925 public boolean dispatchKeyEvent(KeyEvent event) {
1926 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1927 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001929 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001930 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08001931 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08001932 dumpState();
1933 return true;
1934 }
1935 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001936 }
1937 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1938 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001939 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 return true;
1941 }
1942 }
1943
1944 return super.dispatchKeyEvent(event);
1945 }
1946
Joe Onorato88ec0992009-11-19 13:16:06 -08001947 @Override
1948 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001949 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001950 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001951 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001952 Folder openFolder = mWorkspace.getOpenFolder();
1953 if (openFolder.isEditingName()) {
1954 openFolder.dismissEditingName();
1955 } else {
1956 closeFolder();
1957 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001958 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001959 mWorkspace.exitWidgetResizeMode();
1960
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001961 // Back button is a no-op here, but give at least some feedback for the button press
1962 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001963 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001964 }
1965
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001966 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001967 * Re-listen when widgets are reset.
1968 */
1969 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001970 if (mAppWidgetHost != null) {
1971 mAppWidgetHost.startListening();
1972 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001973 }
1974
1975 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 * Launches the intent referred by the clicked shortcut.
1977 *
1978 * @param v The view representing the clicked shortcut.
1979 */
1980 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001981 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1982 // view has detached (it's possible for this to happen if the view is removed mid touch).
1983 if (v.getWindowToken() == null) {
1984 return;
1985 }
1986
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001987 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001988 return;
1989 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001990
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001992 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001994 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001995 int[] pos = new int[2];
1996 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001997 intent.setSourceBounds(new Rect(pos[0], pos[1],
1998 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001999
2000 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002001
2002 if (success && v instanceof BubbleTextView) {
2003 mWaitingForResume = (BubbleTextView) v;
2004 mWaitingForResume.setStayPressed(true);
2005 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002007 if (v instanceof FolderIcon) {
2008 FolderIcon fi = (FolderIcon) v;
2009 handleFolderClick(fi);
2010 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002011 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002012 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002013 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002014 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002015 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002016 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 }
2018 }
2019
Michael Jurka0e260592010-06-30 17:07:39 -07002020 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07002021 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002022 // clicking anywhere on the workspace causes the customization drawer to slide down
2023 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07002024 return false;
2025 }
2026
Michael Jurkaaf442092010-06-10 17:01:57 -07002027 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002028 * Event handler for the search button
2029 *
2030 * @param v The view that was clicked.
2031 */
2032 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002033 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2034
Amith Yamasania135ba82011-08-09 17:42:01 -07002035 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002036 }
2037
2038 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002039 * Event handler for the voice button
2040 *
2041 * @param v The view that was clicked.
2042 */
2043 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002044 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002045
Michael Jurkaae65ee32012-04-30 11:45:54 -07002046 try {
2047 final SearchManager searchManager =
2048 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2049 ComponentName activityName = searchManager.getGlobalSearchActivity();
2050 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002051 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002052 if (activityName != null) {
2053 intent.setPackage(activityName.getPackageName());
2054 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002055 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002056 } catch (ActivityNotFoundException e) {
2057 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002058 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002059 startActivitySafely(null, intent, "onClickVoiceButton");
2060 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002061 }
2062
2063 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002064 * Event handler for the "grid" button that appears on the home screen, which
2065 * enters all apps mode.
2066 *
2067 * @param v The view that was clicked.
2068 */
2069 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07002070 showAllApps(true);
2071 }
2072
2073 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002074 // Provide the same haptic feedback that the system offers for virtual keys.
2075 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002076 }
2077
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002078 public void onClickAppMarketButton(View v) {
2079 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002080 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002081 } else {
2082 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002083 }
2084 }
2085
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002086 void startApplicationDetailsActivity(ComponentName componentName) {
2087 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002088 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2089 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002090 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002091 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002092 }
2093
Patrick Dubroy5539af72010-09-07 15:22:01 -07002094 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2095 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2096 // System applications cannot be installed. For now, show a toast explaining that.
2097 // We may give them the option of disabling apps this way.
2098 int messageId = R.string.uninstall_system_app_text;
2099 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2100 } else {
2101 String packageName = appInfo.componentName.getPackageName();
2102 String className = appInfo.componentName.getClassName();
2103 Intent intent = new Intent(
2104 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002105 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2106 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002107 startActivity(intent);
2108 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002109 }
2110
Michael Jurka86a720e2012-05-09 11:23:23 -07002111 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002113
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002114 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002115 // Only launch using the new animation if the shortcut has not opted out (this is a
2116 // private contract between launcher and may be ignored in the future).
2117 boolean useLaunchAnimation = (v != null) &&
2118 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2119 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002120 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2121 v.getMeasuredWidth(), v.getMeasuredHeight());
2122
2123 startActivity(intent, opts.toBundle());
2124 } else {
2125 startActivity(intent);
2126 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002127 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 } catch (SecurityException e) {
2129 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002130 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002132 "or use the exported attribute for this activity. "
2133 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002134 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002135 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002137
Michael Jurka86a720e2012-05-09 11:23:23 -07002138 boolean startActivitySafely(View v, Intent intent, Object tag) {
2139 boolean success = false;
2140 try {
2141 success = startActivity(v, intent, tag);
2142 } catch (ActivityNotFoundException e) {
2143 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2144 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2145 }
2146 return success;
2147 }
2148
Romain Guy8e633c52010-03-04 12:51:36 -08002149 void startActivityForResultSafely(Intent intent, int requestCode) {
2150 try {
2151 startActivityForResult(intent, requestCode);
2152 } catch (ActivityNotFoundException e) {
2153 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2154 } catch (SecurityException e) {
2155 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2156 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2157 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2158 "or use the exported attribute for this activity.", e);
2159 }
2160 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161
Adam Cohena9cf38f2011-05-02 15:36:58 -07002162 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002163 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002164 Folder openFolder = mWorkspace.getFolderForTag(info);
2165
2166 // If the folder info reports that the associated folder is open, then verify that
2167 // it is actually opened. There have been a few instances where this gets out of sync.
2168 if (info.opened && openFolder == null) {
2169 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2170 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2171 info.opened = false;
2172 }
2173
Adam Cohenfb91f302012-06-11 15:45:18 -07002174 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002175 // Close any open folder
2176 closeFolder();
2177 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002178 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002179 } else {
2180 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002181 int folderScreen;
2182 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002183 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002184 // .. and close it
2185 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002186 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187 // Close any folder open on the current screen
2188 closeFolder();
2189 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002190 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 }
2192 }
2193 }
2194 }
2195
Adam Cohen268c4752012-06-06 17:47:33 -07002196 /**
2197 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2198 * in the DragLayer in the exact absolute location of the original FolderIcon.
2199 */
2200 private void copyFolderIconToImage(FolderIcon fi) {
2201 final int width = fi.getMeasuredWidth();
2202 final int height = fi.getMeasuredHeight();
2203
2204 // Lazy load ImageView, Bitmap and Canvas
2205 if (mFolderIconImageView == null) {
2206 mFolderIconImageView = new ImageView(this);
2207 }
2208 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2209 mFolderIconBitmap.getHeight() != height) {
2210 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2211 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2212 }
2213
2214 DragLayer.LayoutParams lp;
2215 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2216 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2217 } else {
2218 lp = new DragLayer.LayoutParams(width, height);
2219 }
2220
Adam Cohen307fe232012-08-16 17:55:58 -07002221 // The layout from which the folder is being opened may be scaled, adjust the starting
2222 // view size by this scale factor.
2223 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002224 lp.customPosition = true;
2225 lp.x = mRectForFolderAnimation.left;
2226 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002227 lp.width = (int) (scale * width);
2228 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002229
2230 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2231 fi.draw(mFolderIconCanvas);
2232 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002233 if (fi.getFolder() != null) {
2234 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2235 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002236 }
Adam Cohen268c4752012-06-06 17:47:33 -07002237 // Just in case this image view is still in the drag layer from a previous animation,
2238 // we remove it and re-add it.
2239 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2240 mDragLayer.removeView(mFolderIconImageView);
2241 }
2242 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002243 if (fi.getFolder() != null) {
2244 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002245 }
Adam Cohen268c4752012-06-06 17:47:33 -07002246 }
2247
Adam Cohen2801caf2011-05-13 20:57:39 -07002248 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002249 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002250 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2251 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2252 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2253
Adam Cohenc51934b2011-07-26 21:07:43 -07002254 FolderInfo info = (FolderInfo) fi.getTag();
2255 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2256 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002257 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2258 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002259 }
2260
Adam Cohen268c4752012-06-06 17:47:33 -07002261 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2262 copyFolderIconToImage(fi);
2263 fi.setVisibility(View.INVISIBLE);
2264
Michael Jurka2ecf9952012-06-18 12:52:28 -07002265 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002266 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002267 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2268 oa.start();
2269 }
2270
Adam Cohen268c4752012-06-06 17:47:33 -07002271 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002272 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002273 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2274 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2275 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2276
Adam Cohen268c4752012-06-06 17:47:33 -07002277 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002278
Adam Cohen268c4752012-06-06 17:47:33 -07002279 // We remove and re-draw the FolderIcon in-case it has changed
2280 mDragLayer.removeView(mFolderIconImageView);
2281 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002282 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002283 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002284 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002285 oa.addListener(new AnimatorListenerAdapter() {
2286 @Override
2287 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002288 if (cl != null) {
2289 cl.clearFolderLeaveBehind();
2290 // Remove the ImageView copy of the FolderIcon and make the original visible.
2291 mDragLayer.removeView(mFolderIconImageView);
2292 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002293 }
2294 }
2295 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002296 oa.start();
2297 }
2298
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002299 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002300 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002301 * is animated relative to the specified View. If the View is null, no animation
2302 * is played.
2303 *
2304 * @param folderInfo The FolderInfo describing the folder to open.
2305 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002306 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002307 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002308 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002309
Adam Cohena9cf38f2011-05-02 15:36:58 -07002310 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311
Adam Cohen4554ee12011-08-03 16:13:21 -07002312 // Just verify that the folder hasn't already been added to the DragLayer.
2313 // There was a one-off crash where the folder had a parent already.
2314 if (folder.getParent() == null) {
2315 mDragLayer.addView(folder);
2316 mDragController.addDropTarget((DropTarget) folder);
2317 } else {
2318 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2319 folder.getParent() + ").");
2320 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002321 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002322 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002323
2324 // Notify the accessibility manager that this folder "window" has appeared and occluded
2325 // the workspace items
2326 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2327 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002328 }
2329
2330 public void closeFolder() {
2331 Folder folder = mWorkspace.getOpenFolder();
2332 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002333 if (folder.isEditingName()) {
2334 folder.dismissEditingName();
2335 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002336 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002337
2338 // Dismiss the folder cling
2339 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002340 }
2341 }
2342
2343 void closeFolder(Folder folder) {
2344 folder.getInfo().opened = false;
2345
2346 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2347 if (parent != null) {
2348 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2349 shrinkAndFadeInFolderIcon(fi);
2350 }
2351 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002352
2353 // Notify the accessibility manager that this folder "window" has disappeard and no
2354 // longer occludeds the workspace items
2355 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002356 }
2357
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002359 if (!isDraggingEnabled()) return false;
2360 if (isWorkspaceLocked()) return false;
2361 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362
2363 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002364 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002365 }
2366
Michael Jurka0280c3b2010-09-17 15:00:07 -07002367 resetAddInfo();
2368 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002369 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002370 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 return true;
2372 }
2373
Winson Chung3d503fb2011-07-13 17:25:49 -07002374 // The hotseat touch handling does not go through Workspace, and we always allow long press
2375 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002376 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002377 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2378 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002379 if (itemUnderLongClick == null) {
2380 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002381 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2382 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002383 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002384 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002385 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002387 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002388 }
2389 }
2390 }
2391 return true;
2392 }
2393
Winson Chung3d503fb2011-07-13 17:25:49 -07002394 boolean isHotseatLayout(View layout) {
2395 return mHotseat != null && layout != null &&
2396 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2397 }
2398 Hotseat getHotseat() {
2399 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002400 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002401 SearchDropTargetBar getSearchBar() {
2402 return mSearchDropTargetBar;
2403 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002404
Winson Chung3d503fb2011-07-13 17:25:49 -07002405 /**
2406 * Returns the CellLayout of the specified container at the specified screen.
2407 */
2408 CellLayout getCellLayout(long container, int screen) {
2409 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2410 if (mHotseat != null) {
2411 return mHotseat.getLayout();
2412 } else {
2413 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002414 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002415 } else {
2416 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002417 }
2418 }
2419
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002420 Workspace getWorkspace() {
2421 return mWorkspace;
2422 }
2423
Daniel Sandler843e8602010-06-07 14:59:01 -04002424 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
Craig Mautner360310b2012-10-26 15:13:08 -07002425 @Override
Daniel Sandler843e8602010-06-07 14:59:01 -04002426 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002427 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002428 }
2429
Craig Mautner360310b2012-10-26 15:13:08 -07002430 @Override
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002431 public boolean isAllAppsButtonRank(int rank) {
2432 return mHotseat.isAllAppsButtonRank(rank);
2433 }
2434
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002435 /**
2436 * Helper method for the cameraZoomIn/cameraZoomOut animations
2437 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002438 * @param scaleFactor The scale factor used for the zoom
2439 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002440 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002441 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002442 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002443 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002444
Winson Chung18f41f82012-05-09 13:28:10 -07002445 void disableWallpaperIfInAllApps() {
2446 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002447 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002448 if (mAppsCustomizeTabHost != null &&
2449 !mAppsCustomizeTabHost.isTransitioning()) {
2450 updateWallpaperVisibility(false);
2451 }
2452 }
2453 }
2454
Craig Mautner360310b2012-10-26 15:13:08 -07002455 private void setWorkspaceBackground(boolean workspace) {
2456 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002457 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002458 }
2459
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002460 void updateWallpaperVisibility(boolean visible) {
2461 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2462 int curflags = getWindow().getAttributes().flags
2463 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2464 if (wpflags != curflags) {
2465 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2466 }
Craig Mautner360310b2012-10-26 15:13:08 -07002467 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002468 }
2469
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002470 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2471 if (v instanceof LauncherTransitionable) {
2472 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2473 }
2474 }
2475
Michael Jurkabed61d22012-02-14 22:51:29 -08002476 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2477 if (v instanceof LauncherTransitionable) {
2478 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2479 }
Winson Chung70442722012-02-10 15:43:22 -08002480
2481 // Update the workspace transition step as well
2482 dispatchOnLauncherTransitionStep(v, 0f);
2483 }
2484
2485 private void dispatchOnLauncherTransitionStep(View v, float t) {
2486 if (v instanceof LauncherTransitionable) {
2487 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2488 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002489 }
2490
2491 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2492 if (v instanceof LauncherTransitionable) {
2493 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2494 }
Winson Chung70442722012-02-10 15:43:22 -08002495
2496 // Update the workspace transition step as well
2497 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002498 }
2499
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002500 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002501 * Things to test when changing the following seven functions.
2502 * - Home from workspace
2503 * - from center screen
2504 * - from other screens
2505 * - Home from all apps
2506 * - from center screen
2507 * - from other screens
2508 * - Back from all apps
2509 * - from center screen
2510 * - from other screens
2511 * - Launch app from workspace and quit
2512 * - with back
2513 * - with home
2514 * - Launch app from all apps and quit
2515 * - with back
2516 * - with home
2517 * - Go to a screen that's not the default, then all
2518 * apps, and launch and app, and go back
2519 * - with back
2520 * -with home
2521 * - On workspace, long press power and go back
2522 * - with back
2523 * - with home
2524 * - On all apps, long press power and go back
2525 * - with back
2526 * - with home
2527 * - On workspace, power off
2528 * - On all apps, power off
2529 * - Launch an app and turn off the screen while in that app
2530 * - Go back with home key
2531 * - Go back with back key TODO: make this not go to workspace
2532 * - From all apps
2533 * - From workspace
2534 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2535 * - From all apps
2536 * - From the center workspace
2537 * - From another workspace
2538 */
2539
2540 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002541 * Zoom the camera out from the workspace to reveal 'toView'.
2542 * Assumes that the view to show is anchored at either the very top or very bottom
2543 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002544 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002545 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002546 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002547 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002548 mStateAnimation.cancel();
2549 mStateAnimation = null;
2550 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002551 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002552
Winson Chungf0ea4d32011-06-06 14:27:16 -07002553 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2554 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2555 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002556 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002557 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002558 final int startDelay =
2559 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002560
Michael Jurkab3e22d92011-10-31 15:58:33 -07002561 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002562
Michael Jurkad74c9842011-07-10 12:44:21 -07002563 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002564 Animator workspaceAnim =
2565 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002566
2567 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002568 toView.setScaleX(scale);
2569 toView.setScaleY(scale);
2570 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2571 scaleAnim.
2572 scaleX(1f).scaleY(1f).
2573 setDuration(duration).
2574 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002575
Winson Chungf0ea4d32011-06-06 14:27:16 -07002576 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002577 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002578 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002579 .ofFloat(toView, "alpha", 0f, 1f)
2580 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002581 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002582 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2583 @Override
2584 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002585 if (animation == null) {
2586 throw new RuntimeException("animation is null");
2587 }
Winson Chung70442722012-02-10 15:43:22 -08002588 float t = (Float) animation.getAnimatedValue();
2589 dispatchOnLauncherTransitionStep(fromView, t);
2590 dispatchOnLauncherTransitionStep(toView, t);
2591 }
2592 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002593
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002594 // toView should appear right at the end of the workspace shrink
2595 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002596 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002597 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002598 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002599
2600 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002601 boolean animationCancelled = false;
2602
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002603 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002604 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002605 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002606 // Prepare the position
2607 toView.setTranslationX(0.0f);
2608 toView.setTranslationY(0.0f);
2609 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002610 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002611 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002612 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002613 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002614 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2615 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002616
Michael Jurkafa7969f2012-09-21 16:39:14 -07002617 if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chung32174c82011-07-19 15:47:55 -07002618 // Hide the workspace scrollbar
2619 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002620 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002621 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002622 if (!animationCancelled) {
2623 updateWallpaperVisibility(false);
2624 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002625
2626 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002627 if (mSearchDropTargetBar != null) {
2628 mSearchDropTargetBar.hideSearchBar(false);
2629 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002630 }
2631
Adam Cohencff6af82011-09-13 14:51:53 -07002632 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002633 public void onAnimationCancel(Animator animation) {
2634 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002635 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002636 });
2637
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002638 if (workspaceAnim != null) {
2639 mStateAnimation.play(workspaceAnim);
2640 }
Michael Jurka1899a362011-11-03 13:50:45 -07002641
2642 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002643
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002644 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2645 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002646
2647 // If any of the objects being animated haven't been measured/laid out
2648 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002649 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002650 (mWorkspace.getMeasuredWidth() == 0) ||
2651 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002652 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002653 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002654
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002655 final AnimatorSet stateAnimation = mStateAnimation;
2656 final Runnable startAnimRunnable = new Runnable() {
2657 public void run() {
2658 // Check that mStateAnimation hasn't changed while
2659 // we waited for a layout/draw pass
2660 if (mStateAnimation != stateAnimation)
2661 return;
2662 setPivotsForZoom(toView, scale);
2663 dispatchOnLauncherTransitionStart(fromView, animated, false);
2664 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002665 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002666 }
2667 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002668 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002669 final ViewTreeObserver observer = toView.getViewTreeObserver();
2670 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2671 public void onGlobalLayout() {
2672 startAnimRunnable.run();
2673 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2674 }
2675 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002676 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002677 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002678 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002679 } else {
2680 toView.setTranslationX(0.0f);
2681 toView.setTranslationY(0.0f);
2682 toView.setScaleX(1.0f);
2683 toView.setScaleY(1.0f);
2684 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002685 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002686
Michael Jurkabed61d22012-02-14 22:51:29 -08002687 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2688 // Hide the workspace scrollbar
2689 mWorkspace.hideScrollingIndicator(true);
2690 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002691
2692 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002693 if (mSearchDropTargetBar != null) {
2694 mSearchDropTargetBar.hideSearchBar(false);
2695 }
Michael Jurkaabded662011-03-04 12:06:57 -08002696 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002697 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002698 dispatchOnLauncherTransitionStart(fromView, animated, false);
2699 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002700 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002701 dispatchOnLauncherTransitionStart(toView, animated, false);
2702 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002703 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002704 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002705 }
2706
2707 /**
2708 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002709 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002710 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002711 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002712 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2713 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002714
Michael Jurkab3e22d92011-10-31 15:58:33 -07002715 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002716 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002717 mStateAnimation.cancel();
2718 mStateAnimation = null;
2719 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002720 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002721
Winson Chungf0ea4d32011-06-06 14:27:16 -07002722 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002723 final int fadeOutDuration =
2724 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002725 final float scaleFactor = (float)
2726 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2727 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002728 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002729 Animator workspaceAnim = null;
2730
2731 if (toState == State.WORKSPACE) {
2732 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2733 workspaceAnim = mWorkspace.getChangeStateAnimation(
2734 Workspace.State.NORMAL, animated, stagger);
2735 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2736 workspaceAnim = mWorkspace.getChangeStateAnimation(
2737 Workspace.State.SPRING_LOADED, animated);
2738 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002739
Michael Jurkab3e22d92011-10-31 15:58:33 -07002740 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002741 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002742 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002743 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002744 final LauncherViewPropertyAnimator scaleAnim =
2745 new LauncherViewPropertyAnimator(fromView);
2746 scaleAnim.
2747 scaleX(scaleFactor).scaleY(scaleFactor).
2748 setDuration(duration).
2749 setInterpolator(new Workspace.ZoomInInterpolator());
2750
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002751 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002752 .ofFloat(fromView, "alpha", 1f, 0f)
2753 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002754 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002755 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2756 @Override
2757 public void onAnimationUpdate(ValueAnimator animation) {
2758 float t = 1f - (Float) animation.getAnimatedValue();
2759 dispatchOnLauncherTransitionStep(fromView, t);
2760 dispatchOnLauncherTransitionStep(toView, t);
2761 }
2762 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002763
Michael Jurka2ecf9952012-06-18 12:52:28 -07002764 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002765
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002766 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2767 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002768 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002769
2770 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002771 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002772 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002773 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002774 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002775 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2776 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002777 if (mWorkspace != null) {
2778 mWorkspace.hideScrollingIndicator(false);
2779 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002780 if (onCompleteRunnable != null) {
2781 onCompleteRunnable.run();
2782 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002783 mAppsCustomizeContent.updateCurrentPageScroll();
2784 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002785 }
2786 });
2787
Winson Chungf0ea4d32011-06-06 14:27:16 -07002788 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002789 if (workspaceAnim != null) {
2790 mStateAnimation.play(workspaceAnim);
2791 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002792 dispatchOnLauncherTransitionStart(fromView, animated, true);
2793 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002794 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002795 } else {
2796 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002797 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002798 dispatchOnLauncherTransitionStart(fromView, animated, true);
2799 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002800 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002801 dispatchOnLauncherTransitionStart(toView, animated, true);
2802 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002803 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002804 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002805 }
2806
Michael Jurkae326f182011-11-21 14:05:46 -08002807 @Override
2808 public void onTrimMemory(int level) {
2809 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002810 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002811 mAppsCustomizeTabHost.onTrimMemory();
2812 }
2813 }
2814
Winson Chung18f41f82012-05-09 13:28:10 -07002815 @Override
2816 public void onWindowFocusChanged(boolean hasFocus) {
2817 if (!hasFocus) {
2818 // When another window occludes launcher (like the notification shade, or recents),
2819 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2820 updateWallpaperVisibility(true);
2821 } else {
2822 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002823 mWorkspace.postDelayed(new Runnable() {
2824 @Override
2825 public void run() {
2826 disableWallpaperIfInAllApps();
2827 }
2828 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002829 }
2830 }
2831
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002832 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002833 showWorkspace(animated, null);
2834 }
2835
2836 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002837 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002838 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002839 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002840 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002841
Winson Chungc7d2b602012-05-16 17:02:20 -07002842 // Show the search bar (only animate if we were showing the drop target bar in spring
2843 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07002844 if (mSearchDropTargetBar != null) {
2845 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2846 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002847
Michael Jurkab737ee62011-11-15 15:57:22 -08002848 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002849 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002850
2851 // Set focus to the AppsCustomize button
2852 if (mAllAppsButton != null) {
2853 mAllAppsButton.requestFocus();
2854 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002855 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002856
Michael Jurkab737ee62011-11-15 15:57:22 -08002857 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002858
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002859 // Change the state *after* we've called all the transition code
2860 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002861
Winson Chung5fb63472011-02-02 17:03:37 -08002862 // Resume the auto-advance of widgets
2863 mUserPresent = true;
2864 updateRunning();
2865
alanv1d4fde62012-10-17 13:15:47 -07002866 // Send an accessibility event to announce the context change
2867 getWindow().getDecorView()
2868 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Joe Onorato00acb122009-08-04 16:04:30 -04002869 }
2870
Michael Jurkab3e22d92011-10-31 15:58:33 -07002871 void showAllApps(boolean animated) {
2872 if (mState != State.WORKSPACE) return;
2873
2874 showAppsCustomizeHelper(animated, false);
2875 mAppsCustomizeTabHost.requestFocus();
2876
Michael Jurkab3e22d92011-10-31 15:58:33 -07002877 // Change the state *after* we've called all the transition code
2878 mState = State.APPS_CUSTOMIZE;
2879
2880 // Pause the auto-advance of widgets until we are out of AllApps
2881 mUserPresent = false;
2882 updateRunning();
2883 closeFolder();
2884
2885 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07002886 getWindow().getDecorView()
2887 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002888 }
2889
Adam Cohen7777d962011-08-18 18:58:38 -07002890 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002891 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002892 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002893 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002894 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002895 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002896 }
Adam Cohen7777d962011-08-18 18:58:38 -07002897
Adam Cohened66b2b2012-01-23 17:28:51 -08002898 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2899 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002900 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2901
Winson Chunge7a03942011-08-05 15:05:12 -07002902 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002903 @Override
2904 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002905 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002906 // Before we show workspace, hide all apps again because
2907 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2908 // clean up our state transition functions
2909 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002910 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002911 } else {
2912 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002913 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002914 }
2915 }, (extendedDelay ?
2916 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2917 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2918 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002919
Michael Jurkad3ef3062010-11-23 16:23:58 -08002920 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002921 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002922 final boolean animated = true;
2923 final boolean springLoaded = true;
2924 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002925 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002926 }
2927 // Otherwise, we are not in spring loaded mode, so don't do anything.
2928 }
2929
Michael Jurkab737ee62011-11-15 15:57:22 -08002930 void hideDockDivider() {
2931 if (mQsbDivider != null && mDockDivider != null) {
2932 mQsbDivider.setVisibility(View.INVISIBLE);
2933 mDockDivider.setVisibility(View.INVISIBLE);
2934 }
2935 }
2936
2937 void showDockDivider(boolean animated) {
2938 if (mQsbDivider != null && mDockDivider != null) {
2939 mQsbDivider.setVisibility(View.VISIBLE);
2940 mDockDivider.setVisibility(View.VISIBLE);
2941 if (mDividerAnimator != null) {
2942 mDividerAnimator.cancel();
2943 mQsbDivider.setAlpha(1f);
2944 mDockDivider.setAlpha(1f);
2945 mDividerAnimator = null;
2946 }
2947 if (animated) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07002948 mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
2949 mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f),
2950 LauncherAnimUtils.ofFloat(mDockDivider, "alpha", 1f));
Winson Chungadf0c182012-08-23 14:59:07 -07002951 int duration = 0;
2952 if (mSearchDropTargetBar != null) {
2953 duration = mSearchDropTargetBar.getTransitionInDuration();
2954 }
2955 mDividerAnimator.setDuration(duration);
Michael Jurkab737ee62011-11-15 15:57:22 -08002956 mDividerAnimator.start();
2957 }
2958 }
2959 }
2960
Michael Jurkab3e22d92011-10-31 15:58:33 -07002961 void lockAllApps() {
2962 // TODO
2963 }
2964
2965 void unlockAllApps() {
2966 // TODO
2967 }
2968
Winson Chungf0ea4d32011-06-06 14:27:16 -07002969 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002970 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002971 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002972 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002973 if (!LauncherApplication.isScreenLarge()) {
2974 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002975 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002976 int duration = 0;
2977 if (mSearchDropTargetBar != null) {
2978 duration = mSearchDropTargetBar.getTransitionInDuration();
2979 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002980 mHotseat.animate().alpha(1f).setDuration(duration);
2981 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002982 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002983 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002984 }
2985 }
2986 }
2987
2988 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002989 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002990 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002991 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002992 if (!LauncherApplication.isScreenLarge()) {
2993 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002994 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002995 int duration = 0;
2996 if (mSearchDropTargetBar != null) {
2997 duration = mSearchDropTargetBar.getTransitionOutDuration();
2998 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002999 mHotseat.animate().alpha(0f).setDuration(duration);
3000 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003001 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003002 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003003 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003004 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003005 }
3006
Patrick Dubroy5f445422011-02-18 14:35:21 -08003007 /**
3008 * Add an item from all apps or customize onto the given workspace screen.
3009 * If layout is null, add to the current screen.
3010 */
3011 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003012 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003013 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003014 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003015 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003016
Winson Chungdff8ebb2011-09-08 17:25:31 -07003017 /** Maps the current orientation to an index for referencing orientation correct global icons */
3018 private int getCurrentOrientationIndexForGlobalIcons() {
3019 // default - 0, landscape - 1
3020 switch (getResources().getConfiguration().orientation) {
3021 case Configuration.ORIENTATION_LANDSCAPE:
3022 return 1;
3023 default:
3024 return 0;
3025 }
3026 }
3027
Michael Jurkaae65ee32012-04-30 11:45:54 -07003028 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003029 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003030 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003031 // Look for the toolbar icon specified in the activity meta-data
3032 Bundle metaData = packageManager.getActivityInfo(
3033 activityName, PackageManager.GET_META_DATA).metaData;
3034 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003035 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003036 if (iconResId != 0) {
3037 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003038 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003039 }
3040 }
3041 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003042 // This can happen if the activity defines an invalid drawable
3043 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3044 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003045 } catch (Resources.NotFoundException nfe) {
3046 // This can happen if the activity defines an invalid drawable
3047 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3048 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003049 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003050 return null;
3051 }
3052
3053 // if successful in getting icon, return it; otherwise, set button to use default drawable
3054 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003055 int buttonId, ComponentName activityName, int fallbackDrawableId,
3056 String toolbarResourceName) {
3057 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003058 Resources r = getResources();
3059 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3060 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003061
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003062 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003063 // If we were unable to find the icon via the meta-data, use a generic one
3064 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003065 toolbarIcon = r.getDrawable(fallbackDrawableId);
3066 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003067 if (button != null) {
3068 button.setCompoundDrawables(toolbarIcon, null, null, null);
3069 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003070 return null;
3071 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003072 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003073 if (button != null) {
3074 button.setCompoundDrawables(toolbarIcon, null, null, null);
3075 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003076 return toolbarIcon.getConstantState();
3077 }
3078 }
3079
3080 // if successful in getting icon, return it; otherwise, set button to use default drawable
3081 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003082 int buttonId, ComponentName activityName, int fallbackDrawableId,
3083 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003084 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003085 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003086
Michael Jurka19e0fc52011-07-22 18:00:21 -07003087 if (button != null) {
3088 // If we were unable to find the icon via the meta-data, use a
3089 // generic one
3090 if (toolbarIcon == null) {
3091 button.setImageResource(fallbackDrawableId);
3092 } else {
3093 button.setImageDrawable(toolbarIcon);
3094 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003095 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003096
3097 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3098
Michael Jurka0423dcf2010-10-05 14:56:18 -07003099 }
3100
Winson Chung1b884092012-06-08 17:13:02 -07003101 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003102 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003103 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003104 }
3105
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003106 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003107 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003108 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003109 }
3110
Winson Chungbb185bd2011-11-21 12:31:42 -08003111 private void invalidatePressedFocusedStates(View container, View button) {
3112 if (container instanceof HolographicLinearLayout) {
3113 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3114 layout.invalidatePressedFocusedStates();
3115 } else if (button instanceof HolographicImageView) {
3116 HolographicImageView view = (HolographicImageView) button;
3117 view.invalidatePressedFocusedStates();
3118 }
3119 }
3120
Winson Chungc51db6a2011-10-05 11:44:49 -07003121 private boolean updateGlobalSearchIcon() {
3122 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003123 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003124 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003125 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003126 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003127
Winson Chung1cad91e2011-05-25 17:41:01 -07003128 final SearchManager searchManager =
3129 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3130 ComponentName activityName = searchManager.getGlobalSearchActivity();
3131 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003132 int coi = getCurrentOrientationIndexForGlobalIcons();
3133 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003134 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3135 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3136 if (sGlobalSearchIcon[coi] == null) {
3137 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3138 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3139 TOOLBAR_ICON_METADATA_NAME);
3140 }
3141
Winson Chungc51db6a2011-10-05 11:44:49 -07003142 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3143 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003144 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003145 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003146 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003147 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003148 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3149 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3150 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003151 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07003152 if (voiceButtonProxy != null) {
3153 voiceButtonProxy.setVisibility(View.GONE);
3154 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003155 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003156 }
3157 }
3158
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003159 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003160 final View searchButtonContainer = findViewById(R.id.search_button_container);
3161 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003162 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003163 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003164 }
3165
Winson Chungc51db6a2011-10-05 11:44:49 -07003166 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003167 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003168 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003169 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003170
Winson Chungc51db6a2011-10-05 11:44:49 -07003171 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003172 final SearchManager searchManager =
3173 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3174 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3175
3176 ComponentName activityName = null;
3177 if (globalSearchActivity != null) {
3178 // Check if the global search activity handles voice search
3179 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3180 intent.setPackage(globalSearchActivity.getPackageName());
3181 activityName = intent.resolveActivity(getPackageManager());
3182 }
3183
3184 if (activityName == null) {
3185 // Fallback: check if an activity other than the global search activity
3186 // resolves this
3187 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3188 activityName = intent.resolveActivity(getPackageManager());
3189 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003190 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003191 int coi = getCurrentOrientationIndexForGlobalIcons();
3192 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003193 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3194 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3195 if (sVoiceSearchIcon[coi] == null) {
3196 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3197 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3198 TOOLBAR_ICON_METADATA_NAME);
3199 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003200 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003201 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003202 if (voiceButtonProxy != null) {
3203 voiceButtonProxy.setVisibility(View.VISIBLE);
3204 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003205 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003206 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003207 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003208 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003209 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003210 if (voiceButtonProxy != null) {
3211 voiceButtonProxy.setVisibility(View.GONE);
3212 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003213 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003214 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003215 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003216
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003217 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003218 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3219 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003220 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003221 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003222 }
3223
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003224 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003225 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003226 */
3227 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003228 final View marketButton = findViewById(R.id.market_button);
3229 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3230 // Find the app market activity by resolving an intent.
3231 // (If multiple app markets are installed, it will return the ResolverActivity.)
3232 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003233 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003234 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003235 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003236 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003237 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3238 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003239 marketButton.setVisibility(View.VISIBLE);
3240 } else {
3241 // We should hide and disable the view so that we don't try and restore the visibility
3242 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3243 marketButton.setVisibility(View.GONE);
3244 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003245 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003246 }
3247
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003248 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003249 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3250 Resources r = getResources();
3251 Drawable marketIconDrawable = d.newDrawable(r);
3252 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3253 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3254 marketIconDrawable.setBounds(0, 0, w, h);
3255
3256 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003257 }
3258
Michael Jurkad7c28052012-04-27 15:43:36 -07003259 @Override
3260 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003261 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003262 final List<CharSequence> text = event.getText();
3263 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003264 // Populate event with a fake title based on the current state.
3265 if (mState == State.APPS_CUSTOMIZE) {
3266 text.add(getString(R.string.all_apps_button_label));
3267 } else {
3268 text.add(getString(R.string.all_apps_home_button_label));
3269 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003270 return result;
3271 }
3272
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003273 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003274 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003275 */
3276 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3277 @Override
3278 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003279 closeSystemDialogs();
3280 }
3281 }
3282
3283 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003284 * Receives notifications whenever the appwidgets are reset.
3285 */
3286 private class AppWidgetResetObserver extends ContentObserver {
3287 public AppWidgetResetObserver() {
3288 super(new Handler());
3289 }
3290
3291 @Override
3292 public void onChange(boolean selfChange) {
3293 onAppWidgetReset();
3294 }
3295 }
3296
3297 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003298 * If the activity is currently paused, signal that we need to run the passed Runnable
3299 * in onResume.
3300 *
3301 * This needs to be called from incoming places where resources might have been loaded
3302 * while we are paused. That is becaues the Configuration might be wrong
3303 * when we're not running, and if it comes back to what it was when we
3304 * were paused, we are not restarted.
3305 *
3306 * Implementation of the method from LauncherModel.Callbacks.
3307 *
3308 * @return true if we are currently paused. The caller might be able to
3309 * skip some work in that case since we will come back again.
3310 */
3311 private boolean waitUntilResume(Runnable run) {
3312 if (mPaused) {
3313 Log.i(TAG, "Deferring update until onResume");
3314 mOnResumeCallbacks.add(run);
3315 return true;
3316 } else {
3317 return false;
3318 }
3319 }
3320
3321 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003322 * If the activity is currently paused, signal that we need to re-run the loader
3323 * in onResume.
3324 *
3325 * This needs to be called from incoming places where resources might have been loaded
3326 * while we are paused. That is becaues the Configuration might be wrong
3327 * when we're not running, and if it comes back to what it was when we
3328 * were paused, we are not restarted.
3329 *
3330 * Implementation of the method from LauncherModel.Callbacks.
3331 *
3332 * @return true if we are currently paused. The caller might be able to
3333 * skip some work in that case since we will come back again.
3334 */
3335 public boolean setLoadOnResume() {
3336 if (mPaused) {
3337 Log.i(TAG, "setLoadOnResume");
3338 mOnResumeNeedsLoad = true;
3339 return true;
3340 } else {
3341 return false;
3342 }
3343 }
3344
3345 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003346 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003347 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003348 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003349 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003350 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003351 } else {
3352 return SCREEN_COUNT / 2;
3353 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003354 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003355
Joe Onorato9c1289c2009-08-17 11:03:03 -04003356 /**
3357 * Refreshes the shortcuts shown on the workspace.
3358 *
3359 * Implementation of the method from LauncherModel.Callbacks.
3360 */
3361 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003362 // If we're starting binding all over again, clear any bind calls we'd postponed in
3363 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3364 // from scratch again
3365 mOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003366
Michael Jurka7607c2f2013-04-03 14:33:19 -07003367 final Workspace workspace = mWorkspace;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003368 mNewShortcutAnimatePage = -1;
3369 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003370 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003371 int count = workspace.getChildCount();
3372 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003373 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003374 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3375 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003376 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003377 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003378 if (mHotseat != null) {
3379 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003380 }
3381 }
3382
3383 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003384 * Bind the items start-end from the list.
3385 *
3386 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003387 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003388 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end) {
3389 if (waitUntilResume(new Runnable() {
3390 public void run() {
3391 bindItems(shortcuts, start, end);
3392 }
3393 })) {
3394 return;
3395 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003396
Winson Chungf0c6ae02012-03-21 16:10:31 -07003397 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3398 Set<String> newApps = new HashSet<String>();
3399 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3400
3401 Workspace workspace = mWorkspace;
3402 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003403 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003404
3405 // Short circuit if we are loading dock items for a configuration which has no dock
3406 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3407 mHotseat == null) {
3408 continue;
3409 }
3410
Joe Onorato9c1289c2009-08-17 11:03:03 -04003411 switch (item.itemType) {
3412 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3413 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003414 ShortcutInfo info = (ShortcutInfo) item;
3415 String uri = info.intent.toUri(0).toString();
3416 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003417 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3418 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003419 boolean animateIconUp = false;
3420 synchronized (newApps) {
3421 if (newApps.contains(uri)) {
3422 animateIconUp = newApps.remove(uri);
3423 }
3424 }
3425 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003426 // Prepare the view to be animated up
3427 shortcut.setAlpha(0f);
3428 shortcut.setScaleX(0f);
3429 shortcut.setScaleY(0f);
3430 mNewShortcutAnimatePage = item.screen;
3431 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3432 mNewShortcutAnimateViews.add(shortcut);
3433 }
3434 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003435 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003436 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003437 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003438 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003439 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003440 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3441 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003442 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003443 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003444 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003445
Joe Onorato9c1289c2009-08-17 11:03:03 -04003446 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003447 }
3448
Joe Onorato9c1289c2009-08-17 11:03:03 -04003449 /**
3450 * Implementation of the method from LauncherModel.Callbacks.
3451 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003452 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
3453 if (waitUntilResume(new Runnable() {
3454 public void run() {
3455 bindFolders(folders);
3456 }
3457 })) {
3458 return;
3459 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003460 sFolders.clear();
3461 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003462 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003463
3464 /**
3465 * Add the views for a widget to the workspace.
3466 *
3467 * Implementation of the method from LauncherModel.Callbacks.
3468 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003469 public void bindAppWidget(final LauncherAppWidgetInfo item) {
3470 if (waitUntilResume(new Runnable() {
3471 public void run() {
3472 bindAppWidget(item);
3473 }
3474 })) {
3475 return;
3476 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003477
Daniel Sandler843e8602010-06-07 14:59:01 -04003478 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3479 if (DEBUG_WIDGETS) {
3480 Log.d(TAG, "bindAppWidget: " + item);
3481 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003482 final Workspace workspace = mWorkspace;
3483
3484 final int appWidgetId = item.appWidgetId;
3485 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003486 if (DEBUG_WIDGETS) {
3487 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3488 }
3489
Joe Onorato9c1289c2009-08-17 11:03:03 -04003490 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3491
Joe Onorato9c1289c2009-08-17 11:03:03 -04003492 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003493 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003494
Winson Chung3d503fb2011-07-13 17:25:49 -07003495 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003496 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003497 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3498
Joe Onorato9c1289c2009-08-17 11:03:03 -04003499 workspace.requestLayout();
3500
Daniel Sandler843e8602010-06-07 14:59:01 -04003501 if (DEBUG_WIDGETS) {
3502 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3503 + (SystemClock.uptimeMillis()-start) + "ms");
3504 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003505 }
3506
Adam Cohen1462de32012-07-24 22:34:36 -07003507 public void onPageBoundSynchronously(int page) {
3508 mSynchronouslyBoundPages.add(page);
3509 }
3510
Joe Onorato9c1289c2009-08-17 11:03:03 -04003511 /**
3512 * Callback saying that there aren't any more items to bind.
3513 *
3514 * Implementation of the method from LauncherModel.Callbacks.
3515 */
3516 public void finishBindingItems() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003517 if (waitUntilResume(new Runnable() {
3518 public void run() {
3519 finishBindingItems();
3520 }
3521 })) {
3522 return;
3523 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003524 if (mSavedState != null) {
3525 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003526 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003527 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003528 mSavedState = null;
3529 }
3530
Adam Cohen1462de32012-07-24 22:34:36 -07003531 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003532
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003533 // If we received the result of any pending adds while the loader was running (e.g. the
3534 // widget configuration forced an orientation change), process them now.
3535 for (int i = 0; i < sPendingAddList.size(); i++) {
3536 completeAdd(sPendingAddList.get(i));
3537 }
3538 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003539
Winson Chungc51db6a2011-10-05 11:44:49 -07003540 // Update the market app icon as necessary (the other icons will be managed in response to
3541 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003542 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003543
Winson Chungf0c6ae02012-03-21 16:10:31 -07003544 // Animate up any icons as necessary
3545 if (mVisible || mWorkspaceLoading) {
3546 Runnable newAppsRunnable = new Runnable() {
3547 @Override
3548 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003549 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003550 }
3551 };
Winson Chunga2413752012-04-03 14:22:34 -07003552
3553 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3554 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3555 if (canRunNewAppsAnimation()) {
3556 // If the user has not interacted recently, then either snap to the new page to show
3557 // the new-apps animation or just run them if they are to appear on the current page
3558 if (willSnapPage) {
3559 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3560 } else {
3561 runNewAppsAnimation(false);
3562 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003563 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003564 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003565 // are on another page (or just normally if they are added to the current page)
3566 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003567 }
3568 }
3569
3570 mWorkspaceLoading = false;
3571 }
3572
Winson Chunga2413752012-04-03 14:22:34 -07003573 private boolean canRunNewAppsAnimation() {
3574 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3575 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3576 }
3577
Winson Chungf0c6ae02012-03-21 16:10:31 -07003578 /**
3579 * Runs a new animation that scales up icons that were added while Launcher was in the
3580 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003581 *
3582 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003583 */
Winson Chunga2413752012-04-03 14:22:34 -07003584 private void runNewAppsAnimation(boolean immediate) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003585 AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003586 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003587
3588 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003589 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3590 @Override
3591 public int compare(View a, View b) {
3592 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3593 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3594 int cellCountX = LauncherModel.getCellCountX();
3595 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3596 }
3597 });
Winson Chunga2413752012-04-03 14:22:34 -07003598
3599 // Animate each of the views in place (or show them immediately if requested)
3600 if (immediate) {
3601 for (View v : mNewShortcutAnimateViews) {
3602 v.setAlpha(1f);
3603 v.setScaleX(1f);
3604 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003605 }
Winson Chunga2413752012-04-03 14:22:34 -07003606 } else {
3607 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3608 View v = mNewShortcutAnimateViews.get(i);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003609 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
Winson Chunga2413752012-04-03 14:22:34 -07003610 PropertyValuesHolder.ofFloat("alpha", 1f),
3611 PropertyValuesHolder.ofFloat("scaleX", 1f),
3612 PropertyValuesHolder.ofFloat("scaleY", 1f));
3613 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3614 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3615 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3616 bounceAnims.add(bounceAnim);
3617 }
3618 anim.playTogether(bounceAnims);
3619 anim.addListener(new AnimatorListenerAdapter() {
3620 @Override
3621 public void onAnimationEnd(Animator animation) {
Michael Jurkad6dd7c82012-10-19 17:15:16 +02003622 if (mWorkspace != null) {
3623 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3624 }
Winson Chunga2413752012-04-03 14:22:34 -07003625 }
3626 });
3627 anim.start();
3628 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003629
3630 // Clean up
3631 mNewShortcutAnimatePage = -1;
3632 mNewShortcutAnimateViews.clear();
3633 new Thread("clearNewAppsThread") {
3634 public void run() {
3635 mSharedPrefs.edit()
3636 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3637 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3638 .commit();
3639 }
3640 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003641 }
3642
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003643 @Override
3644 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003645 boolean searchVisible = updateGlobalSearchIcon();
3646 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003647 if (mSearchDropTargetBar != null) {
3648 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3649 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003650 }
3651
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003652 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003653 * Add the icons for all apps.
3654 *
3655 * Implementation of the method from LauncherModel.Callbacks.
3656 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003657 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003658 Runnable setAllAppsRunnable = new Runnable() {
3659 public void run() {
3660 if (mAppsCustomizeContent != null) {
3661 mAppsCustomizeContent.setApps(apps);
3662 }
3663 }
3664 };
3665
Michael Jurkac57b7a82011-08-09 22:02:20 -07003666 // Remove the progress bar entirely; we could also make it GONE
3667 // but better to remove it since we know it's not going to be used
3668 View progressBar = mAppsCustomizeTabHost.
3669 findViewById(R.id.apps_customize_progress_bar);
3670 if (progressBar != null) {
3671 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chungc93e5ae2012-07-23 20:48:26 -07003672
3673 // We just post the call to setApps so the user sees the progress bar
3674 // disappear-- otherwise, it just looks like the progress bar froze
3675 // which doesn't look great
3676 mAppsCustomizeTabHost.post(setAllAppsRunnable);
3677 } else {
3678 // If we did not initialize the spinner in onCreate, then we can directly set the
3679 // list of applications without waiting for any progress bars views to be hidden.
3680 setAllAppsRunnable.run();
Winson Chung785d2eb2011-04-14 16:08:02 -07003681 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003682 }
3683
3684 /**
3685 * A package was installed.
3686 *
3687 * Implementation of the method from LauncherModel.Callbacks.
3688 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003689 public void bindAppsAdded(final ArrayList<ApplicationInfo> apps) {
3690 if (waitUntilResume(new Runnable() {
3691 public void run() {
3692 bindAppsAdded(apps);
3693 }
3694 })) {
3695 return;
3696 }
3697
Winson Chungf0ea4d32011-06-06 14:27:16 -07003698
Winson Chung785d2eb2011-04-14 16:08:02 -07003699 if (mAppsCustomizeContent != null) {
3700 mAppsCustomizeContent.addApps(apps);
3701 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003702 }
3703
3704 /**
3705 * A package was updated.
3706 *
3707 * Implementation of the method from LauncherModel.Callbacks.
3708 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003709 public void bindAppsUpdated(final ArrayList<ApplicationInfo> apps) {
3710 if (waitUntilResume(new Runnable() {
3711 public void run() {
3712 bindAppsUpdated(apps);
3713 }
3714 })) {
3715 return;
3716 }
3717
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003718 if (mWorkspace != null) {
3719 mWorkspace.updateShortcuts(apps);
3720 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003721
Winson Chung785d2eb2011-04-14 16:08:02 -07003722 if (mAppsCustomizeContent != null) {
3723 mAppsCustomizeContent.updateApps(apps);
3724 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003725 }
3726
3727 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003728 * A package was uninstalled. We take both the super set of packageNames
3729 * in addition to specific applications to remove, the reason being that
3730 * this can be called when a package is updated as well. In that scenario,
3731 * we only remove specific components from the workspace, where as
3732 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003733 *
3734 * Implementation of the method from LauncherModel.Callbacks.
3735 */
Winson Chung83892cc2013-05-01 16:53:33 -07003736 public void bindComponentsRemoved(final ArrayList<String> packageNames,
3737 final ArrayList<ApplicationInfo> appInfos,
3738 final boolean matchPackageNamesOnly) {
3739 if (waitUntilResume(new Runnable() {
3740 public void run() {
3741 bindComponentsRemoved(packageNames, appInfos, matchPackageNamesOnly);
3742 }
3743 })) {
3744 return;
3745 }
3746
3747 if (matchPackageNamesOnly) {
3748 mWorkspace.removeItemsByPackageName(packageNames);
3749 } else {
3750 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003751 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003752
Winson Chung785d2eb2011-04-14 16:08:02 -07003753 if (mAppsCustomizeContent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -07003754 mAppsCustomizeContent.removeApps(appInfos);
Winson Chung785d2eb2011-04-14 16:08:02 -07003755 }
Winson Chunga1820962011-10-03 16:31:06 -07003756
3757 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003758 mDragController.onAppsRemoved(appInfos, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003759 }
Joe Onoratobe386092009-11-17 17:32:16 -08003760
3761 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003762 * A number of packages were updated.
3763 */
3764 public void bindPackagesUpdated() {
Winson Chung83892cc2013-05-01 16:53:33 -07003765 if (waitUntilResume(new Runnable() {
3766 public void run() {
3767 bindPackagesUpdated();
3768 }
3769 })) {
3770 return;
3771 }
3772
Winson Chung785d2eb2011-04-14 16:08:02 -07003773 if (mAppsCustomizeContent != null) {
3774 mAppsCustomizeContent.onPackagesUpdated();
3775 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003776 }
3777
Winson Chung400438b2011-01-16 17:53:48 -08003778 private int mapConfigurationOriActivityInfoOri(int configOri) {
3779 final Display d = getWindowManager().getDefaultDisplay();
3780 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3781 switch (d.getRotation()) {
3782 case Surface.ROTATION_0:
3783 case Surface.ROTATION_180:
3784 // We are currently in the same basic orientation as the natural orientation
3785 naturalOri = configOri;
3786 break;
3787 case Surface.ROTATION_90:
3788 case Surface.ROTATION_270:
3789 // We are currently in the other basic orientation to the natural orientation
3790 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3791 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3792 break;
3793 }
3794
3795 int[] oriMap = {
3796 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3797 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3798 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3799 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3800 };
3801 // Since the map starts at portrait, we need to offset if this device's natural orientation
3802 // is landscape.
3803 int indexOffset = 0;
3804 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3805 indexOffset = 1;
3806 }
3807 return oriMap[(d.getRotation() + indexOffset) % 4];
3808 }
Adam Cohen446e9402011-09-15 18:21:21 -07003809
Winson Chung4b919f82012-05-01 10:44:08 -07003810 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08003811 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07003812 getResources().getBoolean(R.bool.allow_rotation);
3813 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003814 }
Winson Chung4b919f82012-05-01 10:44:08 -07003815 public void lockScreenOrientation() {
3816 if (isRotationEnabled()) {
3817 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3818 .getConfiguration().orientation));
3819 }
3820 }
3821 public void unlockScreenOrientation(boolean immediate) {
3822 if (isRotationEnabled()) {
3823 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003824 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003825 } else {
3826 mHandler.postDelayed(new Runnable() {
3827 public void run() {
3828 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3829 }
3830 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003831 }
Winson Chung4b919f82012-05-01 10:44:08 -07003832 }
Winson Chung400438b2011-01-16 17:53:48 -08003833 }
3834
Winson Chung82f55532011-08-09 14:14:23 -07003835 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003836 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003837 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003838 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003839
Michael Jurkae233a8b2013-03-19 13:49:20 +01003840 // Restricted secondary users (child mode) will potentially have very few apps
3841 // seeded when they start up for the first time. Clings won't work well with that
Amith Yamasani9178ed82013-04-12 15:16:23 -07003842 boolean supportsLimitedUsers =
Michael Jurkae233a8b2013-03-19 13:49:20 +01003843 android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
Amith Yamasanid59b0642013-04-25 15:18:12 -07003844 Account[] accounts = AccountManager.get(this).getAccounts();
3845 if (supportsLimitedUsers && accounts.length == 0) {
3846 UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
3847 Bundle restrictions = um.getUserRestrictions();
3848 if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
3849 return false;
3850 }
Michael Jurkae233a8b2013-03-19 13:49:20 +01003851 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003852 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003853 }
Michael Jurka22143132012-10-04 17:42:38 +02003854
Winson Chung7d7541e2011-09-16 20:14:36 -07003855 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02003856 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07003857 if (cling != null) {
3858 cling.init(this, positionData);
3859 cling.setVisibility(View.VISIBLE);
3860 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3861 if (animate) {
3862 cling.buildLayer();
3863 cling.setAlpha(0f);
3864 cling.animate()
3865 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003866 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003867 .setDuration(SHOW_CLING_DURATION)
3868 .setStartDelay(delay)
3869 .start();
3870 } else {
3871 cling.setAlpha(1f);
3872 }
Michael Jurka22143132012-10-04 17:42:38 +02003873 cling.setFocusableInTouchMode(true);
3874 cling.post(new Runnable() {
3875 public void run() {
3876 cling.setFocusable(true);
3877 cling.requestFocus();
3878 }
3879 });
3880 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
3881 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003882 }
3883 return cling;
3884 }
Michael Jurka22143132012-10-04 17:42:38 +02003885
Winson Chung7d7541e2011-09-16 20:14:36 -07003886 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08003887 // To catch cases where siblings of top-level views are made invisible, just check whether
3888 // the cling is directly set to GONE before dismissing it.
3889 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003890 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003891 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003892 anim.addListener(new AnimatorListenerAdapter() {
3893 public void onAnimationEnd(Animator animation) {
3894 cling.setVisibility(View.GONE);
3895 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003896 // We should update the shared preferences on a background thread
3897 new Thread("dismissClingThread") {
3898 public void run() {
3899 SharedPreferences.Editor editor = mSharedPrefs.edit();
3900 editor.putBoolean(flag, true);
3901 editor.commit();
3902 }
3903 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003904 };
3905 });
3906 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02003907 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07003908 }
3909 }
Michael Jurka22143132012-10-04 17:42:38 +02003910
Winson Chung9d9d74f2011-09-19 11:49:12 -07003911 private void removeCling(int id) {
3912 final View cling = findViewById(id);
3913 if (cling != null) {
3914 final ViewGroup parent = (ViewGroup) cling.getParent();
3915 parent.post(new Runnable() {
3916 @Override
3917 public void run() {
3918 parent.removeView(cling);
3919 }
3920 });
Michael Jurka22143132012-10-04 17:42:38 +02003921 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003922 }
3923 }
Michael Jurka974c3862012-05-22 22:00:31 -07003924
3925 private boolean skipCustomClingIfNoAccounts() {
3926 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3927 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3928 if (customCling) {
3929 AccountManager am = AccountManager.get(this);
3930 Account[] accounts = am.getAccountsByType("com.google");
3931 return accounts.length == 0;
3932 }
3933 return false;
3934 }
3935
Winson Chung7d7541e2011-09-16 20:14:36 -07003936 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003937 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003938 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003939 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3940 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02003941 // If we're not using the default workspace layout, replace workspace cling
3942 // with a custom workspace cling (usually specified in an overlay)
3943 // For now, only do this on tablets
3944 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02003945 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02003946 // Use a custom cling
3947 View cling = findViewById(R.id.workspace_cling);
3948 ViewGroup clingParent = (ViewGroup) cling.getParent();
3949 int clingIndex = clingParent.indexOfChild(cling);
3950 clingParent.removeViewAt(clingIndex);
3951 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
3952 clingParent.addView(customCling, clingIndex);
3953 customCling.setId(R.id.workspace_cling);
3954 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003955 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003956 } else {
3957 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003958 }
3959 }
3960 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003961 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003962 if (isClingsEnabled() &&
3963 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003964 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003965 } else {
3966 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003967 }
3968 }
3969 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003970 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003971 if (isClingsEnabled() &&
3972 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3973 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003974 } else {
3975 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003976 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003977 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003978 }
3979 public boolean isFolderClingVisible() {
3980 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003981 if (cling != null) {
3982 return cling.getVisibility() == View.VISIBLE;
3983 }
3984 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003985 }
Winson Chung82f55532011-08-09 14:14:23 -07003986 public void dismissWorkspaceCling(View v) {
3987 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003988 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003989 }
3990 public void dismissAllAppsCling(View v) {
3991 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003992 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3993 }
3994 public void dismissFolderCling(View v) {
3995 Cling cling = (Cling) findViewById(R.id.folder_cling);
3996 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003997 }
3998
Winson Chung80baf5a2010-08-09 16:03:15 -07003999 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004000 * Prints out out state for debugging.
4001 */
4002 public void dumpState() {
4003 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004004 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004005 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4006 Log.d(TAG, "mRestoring=" + mRestoring);
4007 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4008 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004009 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004010 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004011
Winson Chung785d2eb2011-04-14 16:08:02 -07004012 if (mAppsCustomizeContent != null) {
4013 mAppsCustomizeContent.dumpState();
4014 }
Joe Onoratobe386092009-11-17 17:32:16 -08004015 Log.d(TAG, "END launcher2 dump state");
4016 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004017
4018 @Override
4019 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4020 super.dump(prefix, fd, writer, args);
4021 writer.println(" ");
4022 writer.println("Debug logs: ");
4023 for (int i = 0; i < sDumpLogs.size(); i++) {
4024 writer.println(" " + sDumpLogs.get(i));
4025 }
4026 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004027
4028 public static void dumpDebugLogsToConsole() {
4029 Log.d(TAG, "");
4030 Log.d(TAG, "*********************");
4031 Log.d(TAG, "Launcher debug logs: ");
4032 for (int i = 0; i < sDumpLogs.size(); i++) {
4033 Log.d(TAG, " " + sDumpLogs.get(i));
4034 }
4035 Log.d(TAG, "*********************");
4036 Log.d(TAG, "");
4037 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004038}
Michael Jurka2763be32011-02-24 11:19:57 -08004039
Michael Jurkaabded662011-03-04 12:06:57 -08004040interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004041 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004042 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004043 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004044 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004045 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004046}