blob: 94a0bca268129f3994be335da3a8197a727dcabc [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 Jurkac402cd92013-05-20 15:49:32 +0200129 static final boolean DEBUG_RESUME_TIME = false;
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) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200395 mAppsCustomizeContent.onPackagesUpdated(
396 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700397 }
Winson Chunga12a2502010-12-20 14:41:35 -0800398
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 if (PROFILE_STARTUP) {
400 android.os.Debug.stopMethodTracing();
401 }
402
403 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700404 if (sPausedFromUserAction) {
405 // If the user leaves launcher, then we should just load items asynchronously when
406 // they return.
407 mModel.startLoader(true, -1);
408 } else {
409 // We only load the page synchronously if the user rotates (or triggers a
410 // configuration change) while launcher is in the foreground
411 mModel.startLoader(true, mWorkspace.getCurrentPage());
412 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 }
414
Michael Jurkac57b7a82011-08-09 22:02:20 -0700415 if (!mModel.isAllAppsLoaded()) {
416 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
417 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
418 }
419
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 // For handling default keys
421 mDefaultKeySsb = new SpannableStringBuilder();
422 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800423
424 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
425 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800426
Adam Cohenf9426d52012-06-04 17:26:21 -0700427 updateGlobalIcons();
428
429 // On large interfaces, we want the screen to auto-rotate based on the current orientation
430 unlockScreenOrientation(true);
431 }
432
Winson Chung4a2afa32012-07-19 14:53:05 -0700433 protected void onUserLeaveHint() {
434 super.onUserLeaveHint();
435 sPausedFromUserAction = true;
436 }
437
Adam Cohenf9426d52012-06-04 17:26:21 -0700438 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700439 boolean searchVisible = false;
440 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800441 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700442 int coi = getCurrentOrientationIndexForGlobalIcons();
443 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
444 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700445 updateAppMarketIcon();
446 searchVisible = updateGlobalSearchIcon();
447 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700448 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700449 if (sGlobalSearchIcon[coi] != null) {
450 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700451 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700452 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700453 if (sVoiceSearchIcon[coi] != null) {
454 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700455 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700456 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700457 if (sAppMarketIcon[coi] != null) {
458 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800459 }
Winson Chungadf0c182012-08-23 14:59:07 -0700460 if (mSearchDropTargetBar != null) {
461 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
462 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463 }
Romain Guycbb89e42009-06-08 15:52:54 -0700464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700466 if (sLocaleConfiguration == null) {
467 new AsyncTask<Void, Void, LocaleConfiguration>() {
468 @Override
469 protected LocaleConfiguration doInBackground(Void... unused) {
470 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
471 readConfiguration(Launcher.this, localeConfiguration);
472 return localeConfiguration;
473 }
474
475 @Override
476 protected void onPostExecute(LocaleConfiguration result) {
477 sLocaleConfiguration = result;
478 checkForLocaleChange(); // recursive, but now with a locale configuration
479 }
480 }.execute();
481 return;
482 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700483
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800484 final Configuration configuration = getResources().getConfiguration();
485
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700486 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800487 final String locale = configuration.locale.toString();
488
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700489 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800490 final int mcc = configuration.mcc;
491
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700492 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800493 final int mnc = configuration.mnc;
494
Romain Guy84f296c2009-11-04 15:00:44 -0800495 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800496
Romain Guy84f296c2009-11-04 15:00:44 -0800497 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700498 sLocaleConfiguration.locale = locale;
499 sLocaleConfiguration.mcc = mcc;
500 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700501
Joe Onorato0589f0f2010-02-08 13:44:00 -0800502 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700503
504 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
505 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700506 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700507 public void run() {
508 writeConfiguration(Launcher.this, localeConfiguration);
509 }
510 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700511 }
512 }
513
514 private static class LocaleConfiguration {
515 public String locale;
516 public int mcc = -1;
517 public int mnc = -1;
518 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700519
Romain Guy98d01652009-06-30 16:21:04 -0700520 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
521 DataInputStream in = null;
522 try {
523 in = new DataInputStream(context.openFileInput(PREFERENCES));
524 configuration.locale = in.readUTF();
525 configuration.mcc = in.readInt();
526 configuration.mnc = in.readInt();
527 } catch (FileNotFoundException e) {
528 // Ignore
529 } catch (IOException e) {
530 // Ignore
531 } finally {
532 if (in != null) {
533 try {
534 in.close();
535 } catch (IOException e) {
536 // Ignore
537 }
538 }
539 }
540 }
541
542 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
543 DataOutputStream out = null;
544 try {
545 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
546 out.writeUTF(configuration.locale);
547 out.writeInt(configuration.mcc);
548 out.writeInt(configuration.mnc);
549 out.flush();
550 } catch (FileNotFoundException e) {
551 // Ignore
552 } catch (IOException e) {
553 //noinspection ResultOfMethodCallIgnored
554 context.getFileStreamPath(PREFERENCES).delete();
555 } finally {
556 if (out != null) {
557 try {
558 out.close();
559 } catch (IOException e) {
560 // Ignore
561 }
562 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 }
564 }
565
Adam Cohen716b51e2011-06-30 12:09:54 -0700566 public DragLayer getDragLayer() {
567 return mDragLayer;
568 }
569
Winson Chung36a62fe2012-05-06 18:04:42 -0700570 boolean isDraggingEnabled() {
571 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
572 // that is subsequently removed from the workspace in startBinding().
573 return !mModel.isLoadingWorkspace();
574 }
575
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576 static int getScreen() {
577 synchronized (sLock) {
578 return sScreen;
579 }
580 }
581
582 static void setScreen(int screen) {
583 synchronized (sLock) {
584 sScreen = screen;
585 }
586 }
587
Winson Chung557d6ed2011-07-08 15:34:52 -0700588 /**
589 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
590 * a configuration step, this allows the proper animations to run after other transitions.
591 */
592 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700593 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800594 switch (args.requestCode) {
595 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700596 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
597 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800598 break;
599 case REQUEST_PICK_SHORTCUT:
600 processShortcut(args.intent);
601 break;
602 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700603 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
604 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700605 result = true;
606 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800607 case REQUEST_CREATE_APPWIDGET:
608 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800609 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700610 result = true;
611 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800612 case REQUEST_PICK_WALLPAPER:
613 // We just wanted the activity result here so we can clear mWaitingForResult
614 break;
615 }
Michael Jurka27614d22012-04-02 06:40:22 -0700616 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
617 // if you turned the screen off and then back while in All Apps, Launcher would not
618 // return to the workspace. Clearing mAddInfo.container here fixes this issue
619 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700620 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800621 }
622
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800623 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700624 protected void onActivityResult(
625 final int requestCode, final int resultCode, final Intent data) {
626 if (requestCode == REQUEST_BIND_APPWIDGET) {
627 int appWidgetId = data != null ?
628 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
629 if (resultCode == RESULT_CANCELED) {
630 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
631 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700632 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700633 }
634 return;
635 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700636 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800637 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
638 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700639 mWaitingForResult = false;
640
Adam Cohened66b2b2012-01-23 17:28:51 -0800641 // We have special handling for widgets
642 if (isWidgetDrop) {
643 int appWidgetId = data != null ?
644 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700645 if (appWidgetId < 0) {
646 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
647 "widget configuration activity.");
648 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
649 } else {
650 completeTwoStageWidgetDrop(resultCode, appWidgetId);
651 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800652 return;
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 // The pattern used here is that a user PICKs a specific application,
656 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700657
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
659 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700660 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800661 final PendingAddArguments args = new PendingAddArguments();
662 args.requestCode = requestCode;
663 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700664 args.container = mPendingAddInfo.container;
665 args.screen = mPendingAddInfo.screen;
666 args.cellX = mPendingAddInfo.cellX;
667 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800668 if (isWorkspaceLocked()) {
669 sPendingAddList.add(args);
670 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700671 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800674 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700675 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800676 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
677 null);
678 }
679
680 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700681 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700682 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800683 Runnable onCompleteRunnable = null;
684 int animationType = 0;
685
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700686 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800687 if (resultCode == RESULT_OK) {
688 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
689 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700690 mPendingAddWidgetInfo);
691 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800692 onCompleteRunnable = new Runnable() {
693 @Override
694 public void run() {
695 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
696 mPendingAddInfo.screen, layout, null);
697 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
698 null);
699 }
700 };
701 } else if (resultCode == RESULT_CANCELED) {
702 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
703 onCompleteRunnable = new Runnable() {
704 @Override
705 public void run() {
706 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
707 null);
708 }
709 };
710 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700711 if (mDragLayer.getAnimatedView() != null) {
712 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
713 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
714 animationType, boundWidget, true);
715 } else {
716 // The animated view may be null in the case of a rotation during widget configuration
717 onCompleteRunnable.run();
718 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800719 }
720
721 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700722 protected void onStop() {
723 super.onStop();
724 FirstFrameAnimatorHelper.setIsVisible(false);
725 }
726
727 @Override
728 protected void onStart() {
729 super.onStart();
730 FirstFrameAnimatorHelper.setIsVisible(true);
731 }
732
733 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200735 long startTime = 0;
736 if (DEBUG_RESUME_TIME) {
737 startTime = System.currentTimeMillis();
738 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700740
Winson Chung4a2afa32012-07-19 14:53:05 -0700741 // Restore the previous launcher state
742 if (mOnResumeState == State.WORKSPACE) {
743 showWorkspace(false);
744 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
745 showAllApps(false);
746 }
747 mOnResumeState = State.NONE;
748
Craig Mautner360310b2012-10-26 15:13:08 -0700749 // Background was set to gradient in onPause(), restore to black if in all apps.
750 setWorkspaceBackground(mState == State.WORKSPACE);
751
Winson Chungde0fb8f2012-05-08 14:37:08 -0700752 // Process any items that were added while Launcher was away
753 InstallShortcutReceiver.flushInstallQueue(this);
754
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800755 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700756 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700757 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400758 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700759 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400760 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700761 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 }
Michael Jurkac402cd92013-05-20 15:49:32 +0200763 if (mOnResumeCallbacks.size() > 0) {
764 // We might have postponed some bind calls until onResume (see waitUntilResume) --
765 // execute them here
766 long startTimeCallbacks = 0;
767 if (DEBUG_RESUME_TIME) {
768 startTimeCallbacks = System.currentTimeMillis();
769 }
770
771 if (mAppsCustomizeContent != null) {
772 mAppsCustomizeContent.setBulkBind(true);
773 }
774 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
775 mOnResumeCallbacks.get(i).run();
776 }
777 if (mAppsCustomizeContent != null) {
778 mAppsCustomizeContent.setBulkBind(false);
779 }
780 mOnResumeCallbacks.clear();
781 if (DEBUG_RESUME_TIME) {
782 Log.d(TAG, "Time spent processing callbacks in onResume: " +
783 (System.currentTimeMillis() - startTimeCallbacks));
784 }
Michael Jurka447bf842013-05-15 14:52:15 +0200785 }
Winson Chunge4e50662012-01-23 14:45:13 -0800786
787 // Reset the pressed state of icons that were locked in the press state while activities
788 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800789 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800790 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800791 mWaitingForResume.setStayPressed(false);
792 }
Winson Chunge4e50662012-01-23 14:45:13 -0800793 if (mAppsCustomizeContent != null) {
794 // Resets the previous all apps icon press state
795 mAppsCustomizeContent.resetDrawableState();
796 }
Adam Cohen06dff352012-06-01 17:17:08 -0700797 // It is possible that widgets can receive updates while launcher is not in the foreground.
798 // Consequently, the widgets will be inflated in the orientation of the foreground activity
799 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
800 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700801 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700802
803 // Again, as with the above scenario, it's possible that one or more of the global icons
804 // were updated in the wrong orientation.
805 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200806 if (DEBUG_RESUME_TIME) {
807 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
808 }
Adam Cohen06dff352012-06-01 17:17:08 -0700809 }
810
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700812 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700813 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
814 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
815 // when Launcher resumes and we are still in AllApps.
816 updateWallpaperVisibility(true);
817
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700818 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700819 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800820 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700821 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700822 }
Romain Guycbb89e42009-06-08 15:52:54 -0700823
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700824 @Override
825 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400826 // Flag the loader to stop early before switching
827 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700828 if (mAppsCustomizeContent != null) {
829 mAppsCustomizeContent.surrender();
830 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800831 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700832 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700833
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800834 // We can't hide the IME if it was forced open. So don't bother
835 /*
836 @Override
837 public void onWindowFocusChanged(boolean hasFocus) {
838 super.onWindowFocusChanged(hasFocus);
839
840 if (hasFocus) {
841 final InputMethodManager inputManager = (InputMethodManager)
842 getSystemService(Context.INPUT_METHOD_SERVICE);
843 WindowManager.LayoutParams lp = getWindow().getAttributes();
844 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
845 android.os.Handler()) {
846 protected void onReceiveResult(int resultCode, Bundle resultData) {
847 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
848 }
849 });
850 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
851 }
852 }
853 */
854
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 private boolean acceptFilter() {
856 final InputMethodManager inputManager = (InputMethodManager)
857 getSystemService(Context.INPUT_METHOD_SERVICE);
858 return !inputManager.isFullscreenMode();
859 }
860
861 @Override
862 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700863 final int uniChar = event.getUnicodeChar();
864 final boolean handled = super.onKeyDown(keyCode, event);
865 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
866 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
868 keyCode, event);
869 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700870 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700871 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700872 // showSearchDialog()
873 // If there are multiple keystrokes before the search dialog takes focus,
874 // onSearchRequested() will be called for every keystroke,
875 // but it is idempotent, so it's fine.
876 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 }
878 }
879
Joe Onorato8a9625e2010-01-28 15:55:35 -0800880 // Eat the long press event so the keyboard doesn't come up.
881 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
882 return true;
883 }
884
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885 return handled;
886 }
887
Karl Rosaen138a0412009-04-23 19:00:21 -0700888 private String getTypedText() {
889 return mDefaultKeySsb.toString();
890 }
891
892 private void clearTypedText() {
893 mDefaultKeySsb.clear();
894 mDefaultKeySsb.clearSpans();
895 Selection.setSelection(mDefaultKeySsb, 0);
896 }
897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700899 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
900 * State
901 */
902 private static State intToState(int stateOrdinal) {
903 State state = State.WORKSPACE;
904 final State[] stateValues = State.values();
905 for (int i = 0; i < stateValues.length; i++) {
906 if (stateValues[i].ordinal() == stateOrdinal) {
907 state = stateValues[i];
908 break;
909 }
910 }
911 return state;
912 }
913
914 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800915 * Restores the previous state, if it exists.
916 *
917 * @param savedState The previous state.
918 */
919 private void restoreState(Bundle savedState) {
920 if (savedState == null) {
921 return;
922 }
923
Michael Jurka883f55b2010-10-21 15:47:14 -0700924 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700925 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700926 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800927 }
928
Winson Chungf0c6ae02012-03-21 16:10:31 -0700929 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700931 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800932 }
933
Winson Chung3d503fb2011-07-13 17:25:49 -0700934 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
935 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700936
Winson Chung3d503fb2011-07-13 17:25:49 -0700937 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
938 mPendingAddInfo.container = pendingAddContainer;
939 mPendingAddInfo.screen = pendingAddScreen;
940 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
941 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700942 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
943 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
944 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700945 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946 mRestoring = true;
947 }
948
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700949
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
951 if (renameFolder) {
952 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700953 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 mRestoring = true;
955 }
Winson Chunga12a2502010-12-20 14:41:35 -0800956
Winson Chung785d2eb2011-04-14 16:08:02 -0700957
958 // Restore the AppsCustomize tab
959 if (mAppsCustomizeTabHost != null) {
960 String curTab = savedState.getString("apps_customize_currentTab");
961 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -0700962 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -0700963 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -0700964 mAppsCustomizeContent.loadAssociatedPages(
965 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700966 }
967
Winson Chung5afbf7b2011-07-25 11:53:08 -0700968 int currentIndex = savedState.getInt("apps_customize_currentIndex");
969 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700970 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800971 }
972
973 /**
974 * Finds all the views we need and configure them properly.
975 */
976 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700977 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400978
Craig Mautner360310b2012-10-26 15:13:08 -0700979 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -0700980 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
981 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -0700982 mQsbDivider = findViewById(R.id.qsb_divider);
983 mDockDivider = findViewById(R.id.dock_divider);
984
985 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
986 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987
Winson Chung4c98d922011-05-31 16:50:48 -0700988 // Setup the drag layer
989 mDragLayer.setup(this, dragController);
990
Winson Chung3d503fb2011-07-13 17:25:49 -0700991 // Setup the hotseat
992 mHotseat = (Hotseat) findViewById(R.id.hotseat);
993 if (mHotseat != null) {
994 mHotseat.setup(this);
995 }
996
Winson Chung4c98d922011-05-31 16:50:48 -0700997 // Setup the workspace
998 mWorkspace.setHapticFeedbackEnabled(false);
999 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001000 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001001 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001002
Winson Chungf0ea4d32011-06-06 14:27:16 -07001003 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001004 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001005
Winson Chungf0ea4d32011-06-06 14:27:16 -07001006 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001007 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001008 mAppsCustomizeContent = (AppsCustomizePagedView)
1009 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1010 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001011
Winson Chung3d503fb2011-07-13 17:25:49 -07001012 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001013 dragController.setDragScoller(mWorkspace);
1014 dragController.setScrollView(mDragLayer);
1015 dragController.setMoveTarget(mWorkspace);
1016 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001017 if (mSearchDropTargetBar != null) {
1018 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001019 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020 }
1021
1022 /**
1023 * Creates a view representing a shortcut.
1024 *
1025 * @param info The data structure describing the shortcut.
1026 *
1027 * @return A View inflated from R.layout.application.
1028 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001029 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001031 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 }
1033
1034 /**
1035 * Creates a view representing a shortcut inflated from the specified resource.
1036 *
1037 * @param layoutResId The id of the XML layout used to create the shortcut.
1038 * @param parent The group the shortcut belongs to.
1039 * @param info The data structure describing the shortcut.
1040 *
1041 * @return A View inflated from layoutResId.
1042 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001043 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001044 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1045 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 return favorite;
1048 }
1049
1050 /**
1051 * Add an application shortcut to the workspace.
1052 *
1053 * @param data The intent describing the application.
1054 * @param cellInfo The position on screen where to create the shortcut.
1055 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001056 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001057 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -07001058 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001059
Adam Cohenfbba09b2011-07-18 21:43:05 -07001060 // First we check if we already know the exact location where we want to add this item.
1061 if (cellX >= 0 && cellY >= 0) {
1062 cellXY[0] = cellX;
1063 cellXY[1] = cellY;
1064 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001065 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001066 return;
1067 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001068
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001069 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001070
Romain Guy73b979d2009-06-09 12:57:21 -07001071 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001072 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001073 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001074 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -07001075 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001076 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001077 } else {
1078 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001079 }
1080 }
Romain Guycbb89e42009-06-08 15:52:54 -07001081
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 /**
1083 * Add a shortcut to the workspace.
1084 *
1085 * @param data The intent describing the shortcut.
1086 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001088 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1089 int cellY) {
1090 int[] cellXY = mTmpAddItemCellCoordinates;
1091 int[] touchXY = mPendingAddInfo.dropPos;
1092 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001093
Michael Jurkad3ef3062010-11-23 16:23:58 -08001094 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001095
Adam Cohen558baaf2011-08-15 15:22:57 -07001096 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001097 if (info == null) {
1098 return;
1099 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001100 final View view = createShortcut(info);
1101
Adam Cohenfbba09b2011-07-18 21:43:05 -07001102 // First we check if we already know the exact location where we want to add this item.
1103 if (cellX >= 0 && cellY >= 0) {
1104 cellXY[0] = cellX;
1105 cellXY[1] = cellY;
1106 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001107
1108 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001109 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001110 true, null,null)) {
1111 return;
1112 }
1113 DragObject dragObject = new DragObject();
1114 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001115 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1116 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001117 return;
1118 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001119 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001120 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001121 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001122 foundCellSpan = (result != null);
1123 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001124 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001125 }
1126
1127 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001128 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 return;
1130 }
1131
Adam Cohen558baaf2011-08-15 15:22:57 -07001132 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133
1134 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001135 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1136 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001137 }
1138 }
1139
Adam Cohen2f093b62012-04-30 18:59:53 -07001140 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1141 int minHeight) {
1142 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001143 // We want to account for the extra amount of padding that we are adding to the widget
1144 // to ensure that it gets the full amount of space that it has requested
1145 int requiredWidth = minWidth + padding.left + padding.right;
1146 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001147 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001148 }
1149
Adam Cohen2f093b62012-04-30 18:59:53 -07001150 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1151 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001152 }
1153
Adam Cohen2f093b62012-04-30 18:59:53 -07001154 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1155 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001156 }
1157
Adam Cohen2f093b62012-04-30 18:59:53 -07001158 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1159 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001160 }
1161
Adam Cohen2f093b62012-04-30 18:59:53 -07001162 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1163 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001164 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001165 }
1166
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001168 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001169 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001170 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001171 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001172 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001173 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1174 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1175 if (appWidgetInfo == null) {
1176 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1177 }
Romain Guycbb89e42009-06-08 15:52:54 -07001178
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001179 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001180 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001181
Adam Cohen2f093b62012-04-30 18:59:53 -07001182 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1183 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001184
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001186 // We have saved the position to which the widget was dragged-- this really only matters
1187 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001188 int[] cellXY = mTmpAddItemCellCoordinates;
1189 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001190 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001191 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001192 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1193 cellXY[0] = mPendingAddInfo.cellX;
1194 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001195 spanXY[0] = mPendingAddInfo.spanX;
1196 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001197 foundCellSpan = true;
1198 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001199 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001200 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001201 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1202 spanXY[1], cellXY, finalSpan);
1203 spanXY[0] = finalSpan[0];
1204 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001205 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001206 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001207 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001208 }
1209
Michael Jurka0280c3b2010-09-17 15:00:07 -07001210 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001211 if (appWidgetId != -1) {
1212 // Deleting an app widget ID is a void call but writes to disk before returning
1213 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001214 new Thread("deleteAppWidgetId") {
1215 public void run() {
1216 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1217 }
1218 }.start();
1219 }
Winson Chung93eef082012-03-23 15:59:27 -07001220 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001221 return;
1222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001224 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001225 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1226 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001227 launcherInfo.spanX = spanXY[0];
1228 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001229 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1230 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001231
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001233 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
1235 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001236 if (hostView == null) {
1237 // Perform actual inflation because we're live
1238 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1239 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1240 } else {
1241 // The AppWidgetHostView has already been inflated and instantiated
1242 launcherInfo.hostView = hostView;
1243 }
Romain Guycbb89e42009-06-08 15:52:54 -07001244
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001246 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001247 launcherInfo.notifyWidgetSizeChanged(this);
1248
Winson Chung3d503fb2011-07-13 17:25:49 -07001249 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001250 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001251
1252 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001254 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 }
Romain Guycbb89e42009-06-08 15:52:54 -07001256
Adam Cohended9f8d2010-11-03 13:25:16 -07001257 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1258 @Override
1259 public void onReceive(Context context, Intent intent) {
1260 final String action = intent.getAction();
1261 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1262 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001263 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001264 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001265
Winson Chungc100e8e2011-08-09 16:02:43 -07001266 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001267 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001268 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1269 mAppsCustomizeTabHost.reset();
1270 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001271 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001272 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1273 mUserPresent = true;
1274 updateRunning();
1275 }
1276 }
1277 };
1278
1279 @Override
1280 public void onAttachedToWindow() {
1281 super.onAttachedToWindow();
1282
1283 // Listen for broadcasts related to user-presence
1284 final IntentFilter filter = new IntentFilter();
1285 filter.addAction(Intent.ACTION_SCREEN_OFF);
1286 filter.addAction(Intent.ACTION_USER_PRESENT);
1287 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001288 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001289 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001290 mVisible = true;
1291 }
1292
1293 @Override
1294 public void onDetachedFromWindow() {
1295 super.onDetachedFromWindow();
1296 mVisible = false;
1297
Adam Cohend113e0c2010-11-11 10:48:05 -08001298 if (mAttached) {
1299 unregisterReceiver(mReceiver);
1300 mAttached = false;
1301 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001302 updateRunning();
1303 }
1304
1305 public void onWindowVisibilityChanged(int visibility) {
1306 mVisible = visibility == View.VISIBLE;
1307 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001308 // The following code used to be in onResume, but it turns out onResume is called when
1309 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1310 // is a more appropriate event to handle
1311 if (mVisible) {
1312 mAppsCustomizeTabHost.onWindowVisible();
1313 if (!mWorkspaceLoading) {
1314 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001315 // We want to let Launcher draw itself at least once before we force it to build
1316 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001317 // apps is nice and speedy.
1318 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001319 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001320 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001321 if (mStarted) return;
1322 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001323 // We delay the layer building a bit in order to give
1324 // other message processing a time to run. In particular
1325 // this avoids a delay in hiding the IME if it was
1326 // currently shown, because doing that may involve
1327 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001328 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001329 final ViewTreeObserver.OnDrawListener listener = this;
1330 mWorkspace.post(new Runnable() {
1331 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001332 if (mWorkspace != null &&
1333 mWorkspace.getViewTreeObserver() != null) {
1334 mWorkspace.getViewTreeObserver().
1335 removeOnDrawListener(listener);
1336 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001337 }
1338 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001339 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001340 }
1341 });
1342 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001343 // When Launcher comes back to foreground, a different Activity might be responsible for
1344 // the app market intent, so refresh the icon
1345 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001346 clearTypedText();
1347 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001348 }
1349
1350 private void sendAdvanceMessage(long delay) {
1351 mHandler.removeMessages(ADVANCE_MSG);
1352 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1353 mHandler.sendMessageDelayed(msg, delay);
1354 mAutoAdvanceSentTime = System.currentTimeMillis();
1355 }
1356
1357 private void updateRunning() {
1358 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1359 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1360 mAutoAdvanceRunning = autoAdvanceRunning;
1361 if (autoAdvanceRunning) {
1362 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1363 sendAdvanceMessage(delay);
1364 } else {
1365 if (!mWidgetsToAdvance.isEmpty()) {
1366 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1367 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1368 }
1369 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001370 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001371 }
1372 }
1373 }
1374
1375 private final Handler mHandler = new Handler() {
1376 @Override
1377 public void handleMessage(Message msg) {
1378 if (msg.what == ADVANCE_MSG) {
1379 int i = 0;
1380 for (View key: mWidgetsToAdvance.keySet()) {
1381 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1382 final int delay = mAdvanceStagger * i;
1383 if (v instanceof Advanceable) {
1384 postDelayed(new Runnable() {
1385 public void run() {
1386 ((Advanceable) v).advance();
1387 }
1388 }, delay);
1389 }
1390 i++;
1391 }
1392 sendAdvanceMessage(mAdvanceInterval);
1393 }
1394 }
1395 };
1396
1397 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001398 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001399 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1400 if (v instanceof Advanceable) {
1401 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001402 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001403 updateRunning();
1404 }
1405 }
1406
1407 void removeWidgetToAutoAdvance(View hostView) {
1408 if (mWidgetsToAdvance.containsKey(hostView)) {
1409 mWidgetsToAdvance.remove(hostView);
1410 updateRunning();
1411 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 }
1413
Joe Onorato9c1289c2009-08-17 11:03:03 -04001414 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001415 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001416 launcherInfo.hostView = null;
1417 }
1418
Winson Chung93eef082012-03-23 15:59:27 -07001419 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1420 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1421 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001422 }
1423
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001424 public LauncherAppWidgetHost getAppWidgetHost() {
1425 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001426 }
Romain Guycbb89e42009-06-08 15:52:54 -07001427
Winson Chunga9abd0e2010-10-27 17:18:37 -07001428 public LauncherModel getModel() {
1429 return mModel;
1430 }
1431
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001432 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001433 getWindow().closeAllPanels();
1434
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001435 // Whatever we were doing is hereby canceled.
1436 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001437 }
1438
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 @Override
1440 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001441 long startTime = 0;
1442 if (DEBUG_RESUME_TIME) {
1443 startTime = System.currentTimeMillis();
1444 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445 super.onNewIntent(intent);
1446
1447 // Close the menu
1448 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001449 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001450 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001451
Jamie Genniscb222e82012-10-23 15:44:26 -07001452 final boolean alreadyOnHome =
1453 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001454 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001455
Jamie Genniscb222e82012-10-23 15:44:26 -07001456 Runnable processIntent = new Runnable() {
1457 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001458 if (mWorkspace == null) {
1459 // Can be cases where mWorkspace is null, this prevents a NPE
1460 return;
1461 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001462 Folder openFolder = mWorkspace.getOpenFolder();
1463 // In all these cases, only animate if we're already on home
1464 mWorkspace.exitWidgetResizeMode();
1465 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1466 openFolder == null) {
1467 mWorkspace.moveToDefaultScreen(true);
1468 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001469
Jamie Genniscb222e82012-10-23 15:44:26 -07001470 closeFolder();
1471 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001472
Jamie Genniscb222e82012-10-23 15:44:26 -07001473 // If we are already on home, then just animate back to the workspace,
1474 // otherwise, just wait until onResume to set the state back to Workspace
1475 if (alreadyOnHome) {
1476 showWorkspace(true);
1477 } else {
1478 mOnResumeState = State.WORKSPACE;
1479 }
1480
1481 final View v = getWindow().peekDecorView();
1482 if (v != null && v.getWindowToken() != null) {
1483 InputMethodManager imm = (InputMethodManager)getSystemService(
1484 INPUT_METHOD_SERVICE);
1485 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1486 }
1487
1488 // Reset AllApps to its initial state
1489 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1490 mAppsCustomizeTabHost.reset();
1491 }
1492 }
1493 };
1494
1495 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1496 // Delay processing of the intent to allow the status bar animation to finish
1497 // first in order to avoid janky animations.
1498 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001499 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001500 // Process the intent immediately.
1501 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001502 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001503
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 }
Michael Jurka447bf842013-05-15 14:52:15 +02001505 if (DEBUG_RESUME_TIME) {
1506 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1507 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 }
1509
1510 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001511 public void onRestoreInstanceState(Bundle state) {
1512 super.onRestoreInstanceState(state);
1513 for (int page: mSynchronouslyBoundPages) {
1514 mWorkspace.restoreInstanceStateForChild(page);
1515 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 }
1517
1518 @Override
1519 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001520 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001521 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522
Michael Jurka883f55b2010-10-21 15:47:14 -07001523 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001524 // We close any open folder since it will not be re-opened, and we need to make sure
1525 // this state is reflected.
1526 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527
Winson Chung3d503fb2011-07-13 17:25:49 -07001528 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1529 mWaitingForResult) {
1530 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1531 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1532 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1533 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001534 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1535 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1536 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 }
1538
1539 if (mFolderInfo != null && mWaitingForResult) {
1540 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1541 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1542 }
Michael Jurka946ad472010-07-09 18:05:18 -07001543
Winson Chung785d2eb2011-04-14 16:08:02 -07001544 // Save the current AppsCustomize tab
1545 if (mAppsCustomizeTabHost != null) {
1546 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1547 if (currentTabTag != null) {
1548 outState.putString("apps_customize_currentTab", currentTabTag);
1549 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001550 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1551 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001552 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 }
1554
1555 @Override
1556 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001558
Winson Chunge7a03942011-08-05 15:05:12 -07001559 // Remove all pending runnables
1560 mHandler.removeMessages(ADVANCE_MSG);
1561 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001562 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001563
Winson Chungcd2b0142011-06-08 16:02:26 -07001564 // Stop callbacks from LauncherModel
1565 LauncherApplication app = ((LauncherApplication) getApplication());
1566 mModel.stopLoader();
1567 app.setLauncher(null);
1568
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001570 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001572 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001574 mAppWidgetHost = null;
1575
1576 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577
1578 TextKeyListener.getInstance().release();
1579
Winson Chung81b52252012-08-27 15:34:29 -07001580 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1581 // to prevent leaking Launcher activities on orientation change.
1582 if (mModel != null) {
1583 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1584 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001585
1586 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001587 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001588
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001589 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001590 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1591 mWorkspace.removeAllViews();
1592 mWorkspace = null;
1593 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001594
Michael Jurka2ecf9952012-06-18 12:52:28 -07001595 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 }
1597
Adam Cohena9cf38f2011-05-02 15:36:58 -07001598 public DragController getDragController() {
1599 return mDragController;
1600 }
1601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 @Override
1603 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001604 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605 super.startActivityForResult(intent, requestCode);
1606 }
1607
Winson Chung70d72102011-08-12 11:24:35 -07001608 /**
1609 * Indicates that we want global search for this activity by setting the globalSearch
1610 * argument for {@link #startSearch} to true.
1611 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001613 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001615
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001616 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001617
Karl Rosaen138a0412009-04-23 19:00:21 -07001618 if (initialQuery == null) {
1619 // Use any text typed in the launcher as the initial query
1620 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001621 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001622 if (appSearchData == null) {
1623 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001624 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625 }
Winson Chungadf0c182012-08-23 14:59:07 -07001626 Rect sourceBounds = new Rect();
1627 if (mSearchDropTargetBar != null) {
1628 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1629 }
Romain Guycbb89e42009-06-08 15:52:54 -07001630
Michael Jurkaa33411c2012-06-14 16:18:21 -07001631 startGlobalSearch(initialQuery, selectInitialQuery,
1632 appSearchData, sourceBounds);
1633 }
1634
1635 /**
1636 * Starts the global search activity. This code is a copied from SearchManager
1637 */
1638 public void startGlobalSearch(String initialQuery,
1639 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001640 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001641 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1642 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1643 if (globalSearchActivity == null) {
1644 Log.w(TAG, "No global search activity found.");
1645 return;
1646 }
1647 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1648 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1649 intent.setComponent(globalSearchActivity);
1650 // Make sure that we have a Bundle to put source in
1651 if (appSearchData == null) {
1652 appSearchData = new Bundle();
1653 } else {
1654 appSearchData = new Bundle(appSearchData);
1655 }
1656 // Set source to package name of app that starts global search, if not set already.
1657 if (!appSearchData.containsKey("source")) {
1658 appSearchData.putString("source", getPackageName());
1659 }
1660 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1661 if (!TextUtils.isEmpty(initialQuery)) {
1662 intent.putExtra(SearchManager.QUERY, initialQuery);
1663 }
1664 if (selectInitialQuery) {
1665 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1666 }
1667 intent.setSourceBounds(sourceBounds);
1668 try {
1669 startActivity(intent);
1670 } catch (ActivityNotFoundException ex) {
1671 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001673 }
1674
Winson Chung70d72102011-08-12 11:24:35 -07001675 @Override
1676 public boolean onCreateOptionsMenu(Menu menu) {
1677 if (isWorkspaceLocked()) {
1678 return false;
1679 }
1680
1681 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001682
1683 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1684 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1685 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001686 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1687 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1688 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001689 String helpUrl = getString(R.string.help_url);
1690 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001691 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1692 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1693
Winson Chung70d72102011-08-12 11:24:35 -07001694 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1695 .setIcon(android.R.drawable.ic_menu_gallery)
1696 .setAlphabeticShortcut('W');
1697 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1698 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001699 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001700 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001701 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1702 .setIcon(android.R.drawable.ic_menu_preferences)
1703 .setIntent(settings)
1704 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001705 if (!helpUrl.isEmpty()) {
1706 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1707 .setIcon(android.R.drawable.ic_menu_help)
1708 .setIntent(help)
1709 .setAlphabeticShortcut('H');
1710 }
Winson Chung70d72102011-08-12 11:24:35 -07001711 return true;
1712 }
1713
1714 @Override
1715 public boolean onPrepareOptionsMenu(Menu menu) {
1716 super.onPrepareOptionsMenu(menu);
1717
1718 if (mAppsCustomizeTabHost.isTransitioning()) {
1719 return false;
1720 }
1721 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1722 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1723
1724 return true;
1725 }
1726
1727 @Override
1728 public boolean onOptionsItemSelected(MenuItem item) {
1729 switch (item.getItemId()) {
1730 case MENU_WALLPAPER_SETTINGS:
1731 startWallpaper();
1732 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001733 }
1734
1735 return super.onOptionsItemSelected(item);
1736 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001738 @Override
1739 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001740 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001741 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001742 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001743 }
1744
Joe Onorato9c1289c2009-08-17 11:03:03 -04001745 public boolean isWorkspaceLocked() {
1746 return mWorkspaceLoading || mWaitingForResult;
1747 }
1748
Michael Jurka0280c3b2010-09-17 15:00:07 -07001749 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001750 mPendingAddInfo.container = ItemInfo.NO_ID;
1751 mPendingAddInfo.screen = -1;
1752 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1753 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001754 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001755 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001756 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001757
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001758 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1759 AppWidgetProviderInfo appWidgetInfo) {
1760 if (appWidgetInfo.configure != null) {
1761 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001762
Bjorn Bringert7984c942009-12-09 15:38:25 +00001763 // Launch over to configure widget, if needed
1764 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001765 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001766 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001767 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001769 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001770 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1771 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001772 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001773 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 }
1775 }
Romain Guycbb89e42009-06-08 15:52:54 -07001776
Adam Cohenfbba09b2011-07-18 21:43:05 -07001777 /**
1778 * Process a shortcut drop.
1779 *
1780 * @param componentName The name of the component
1781 * @param screen The screen where it should be added
1782 * @param cell The cell it should be added to, optional
1783 * @param position The location on the screen where it was dropped, optional
1784 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001785 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1786 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001787 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001788 mPendingAddInfo.container = container;
1789 mPendingAddInfo.screen = screen;
1790 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001791
1792 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001793 mPendingAddInfo.cellX = cell[0];
1794 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001795 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001796
1797 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1798 createShortcutIntent.setComponent(componentName);
1799 processShortcut(createShortcutIntent);
1800 }
1801
Adam Cohenfbba09b2011-07-18 21:43:05 -07001802 /**
1803 * Process a widget drop.
1804 *
1805 * @param info The PendingAppWidgetInfo of the widget being added.
1806 * @param screen The screen where it should be added
1807 * @param cell The cell it should be added to, optional
1808 * @param position The location on the screen where it was dropped, optional
1809 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001810 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001811 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001812 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001813 mPendingAddInfo.container = info.container = container;
1814 mPendingAddInfo.screen = info.screen = screen;
1815 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001816 mPendingAddInfo.minSpanX = info.minSpanX;
1817 mPendingAddInfo.minSpanY = info.minSpanY;
1818
Adam Cohenfbba09b2011-07-18 21:43:05 -07001819 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001820 mPendingAddInfo.cellX = cell[0];
1821 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001822 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001823 if (span != null) {
1824 mPendingAddInfo.spanX = span[0];
1825 mPendingAddInfo.spanY = span[1];
1826 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001827
Adam Cohened66b2b2012-01-23 17:28:51 -08001828 AppWidgetHostView hostView = info.boundWidget;
1829 int appWidgetId;
1830 if (hostView != null) {
1831 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001832 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001833 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001834 // In this case, we either need to start an activity to get permission to bind
1835 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001836 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001837 Bundle options = info.bindOptions;
1838
1839 boolean success = false;
1840 if (options != null) {
1841 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1842 info.componentName, options);
1843 } else {
1844 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1845 info.componentName);
1846 }
1847 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001848 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001849 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001850 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001851 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1852 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1853 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001854 // TODO: we need to make sure that this accounts for the options bundle.
1855 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001856 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1857 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001858 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001859 }
1860
Joe Onoratodeb98af2010-02-19 14:59:39 -08001861 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001862 // Handle case where user selected "Applications"
1863 String applicationName = getResources().getString(R.string.group_applications);
1864 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001865
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001866 if (applicationName != null && applicationName.equals(shortcutName)) {
1867 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1868 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001869
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001870 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1871 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001872 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001873 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001874 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001875 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 }
1878
Winson Chung24ab2f12010-09-16 14:10:47 -07001879 void processWallpaper(Intent intent) {
1880 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1881 }
1882
Winson Chung3d503fb2011-07-13 17:25:49 -07001883 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1884 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001885 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 folderInfo.title = getText(R.string.folder_name);
1887
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001889 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1890 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001891 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892
1893 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001894 FolderIcon newFolder =
1895 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1896 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1897 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001898 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 }
Romain Guycbb89e42009-06-08 15:52:54 -07001900
Joe Onorato9c1289c2009-08-17 11:03:03 -04001901 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001902 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001903 }
1904
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001906 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001907 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001908 Intent chooser = Intent.createChooser(pickWallpaper,
1909 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001910 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1911 // Removed in Eclair MR1
1912// WallpaperManager wm = (WallpaperManager)
1913// getSystemService(Context.WALLPAPER_SERVICE);
1914// WallpaperInfo wi = wm.getWallpaperInfo();
1915// if (wi != null && wi.getSettingsActivity() != null) {
1916// LabeledIntent li = new LabeledIntent(getPackageName(),
1917// R.string.configure_wallpaper, 0);
1918// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1919// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1920// }
Mike Clerona0618e42009-10-22 13:55:21 -07001921 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 }
1923
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001924 /**
1925 * Registers various content observers. The current implementation registers
1926 * only a favorites observer to keep track of the favorites applications.
1927 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001928 private void registerContentObservers() {
1929 ContentResolver resolver = getContentResolver();
1930 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1931 true, mWidgetObserver);
1932 }
1933
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001934 @Override
1935 public boolean dispatchKeyEvent(KeyEvent event) {
1936 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1937 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001938 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001939 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001940 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08001941 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08001942 dumpState();
1943 return true;
1944 }
1945 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001946 }
1947 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1948 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001949 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 return true;
1951 }
1952 }
1953
1954 return super.dispatchKeyEvent(event);
1955 }
1956
Joe Onorato88ec0992009-11-19 13:16:06 -08001957 @Override
1958 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001959 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001960 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001961 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001962 Folder openFolder = mWorkspace.getOpenFolder();
1963 if (openFolder.isEditingName()) {
1964 openFolder.dismissEditingName();
1965 } else {
1966 closeFolder();
1967 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001968 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001969 mWorkspace.exitWidgetResizeMode();
1970
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001971 // Back button is a no-op here, but give at least some feedback for the button press
1972 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001973 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001974 }
1975
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001977 * Re-listen when widgets are reset.
1978 */
1979 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001980 if (mAppWidgetHost != null) {
1981 mAppWidgetHost.startListening();
1982 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001983 }
1984
1985 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 * Launches the intent referred by the clicked shortcut.
1987 *
1988 * @param v The view representing the clicked shortcut.
1989 */
1990 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001991 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1992 // view has detached (it's possible for this to happen if the view is removed mid touch).
1993 if (v.getWindowToken() == null) {
1994 return;
1995 }
1996
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001997 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001998 return;
1999 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002002 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08002004 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08002005 int[] pos = new int[2];
2006 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002007 intent.setSourceBounds(new Rect(pos[0], pos[1],
2008 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002009
2010 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002011
2012 if (success && v instanceof BubbleTextView) {
2013 mWaitingForResume = (BubbleTextView) v;
2014 mWaitingForResume.setStayPressed(true);
2015 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002016 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002017 if (v instanceof FolderIcon) {
2018 FolderIcon fi = (FolderIcon) v;
2019 handleFolderClick(fi);
2020 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002021 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002022 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002023 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002024 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002025 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002026 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028 }
2029
Michael Jurka0e260592010-06-30 17:07:39 -07002030 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07002031 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002032 // clicking anywhere on the workspace causes the customization drawer to slide down
2033 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07002034 return false;
2035 }
2036
Michael Jurkaaf442092010-06-10 17:01:57 -07002037 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002038 * Event handler for the search button
2039 *
2040 * @param v The view that was clicked.
2041 */
2042 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002043 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2044
Amith Yamasania135ba82011-08-09 17:42:01 -07002045 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002046 }
2047
2048 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002049 * Event handler for the voice button
2050 *
2051 * @param v The view that was clicked.
2052 */
2053 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002054 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002055
Michael Jurkaae65ee32012-04-30 11:45:54 -07002056 try {
2057 final SearchManager searchManager =
2058 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2059 ComponentName activityName = searchManager.getGlobalSearchActivity();
2060 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002061 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002062 if (activityName != null) {
2063 intent.setPackage(activityName.getPackageName());
2064 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002065 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002066 } catch (ActivityNotFoundException e) {
2067 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002068 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002069 startActivitySafely(null, intent, "onClickVoiceButton");
2070 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002071 }
2072
2073 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002074 * Event handler for the "grid" button that appears on the home screen, which
2075 * enters all apps mode.
2076 *
2077 * @param v The view that was clicked.
2078 */
2079 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07002080 showAllApps(true);
2081 }
2082
2083 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002084 // Provide the same haptic feedback that the system offers for virtual keys.
2085 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002086 }
2087
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002088 public void onClickAppMarketButton(View v) {
2089 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002090 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002091 } else {
2092 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002093 }
2094 }
2095
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002096 void startApplicationDetailsActivity(ComponentName componentName) {
2097 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002098 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2099 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002100 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002101 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002102 }
2103
Patrick Dubroy5539af72010-09-07 15:22:01 -07002104 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2105 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2106 // System applications cannot be installed. For now, show a toast explaining that.
2107 // We may give them the option of disabling apps this way.
2108 int messageId = R.string.uninstall_system_app_text;
2109 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2110 } else {
2111 String packageName = appInfo.componentName.getPackageName();
2112 String className = appInfo.componentName.getClassName();
2113 Intent intent = new Intent(
2114 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002115 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2116 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002117 startActivity(intent);
2118 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002119 }
2120
Michael Jurka86a720e2012-05-09 11:23:23 -07002121 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002122 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002123
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002125 // Only launch using the new animation if the shortcut has not opted out (this is a
2126 // private contract between launcher and may be ignored in the future).
2127 boolean useLaunchAnimation = (v != null) &&
2128 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2129 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002130 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2131 v.getMeasuredWidth(), v.getMeasuredHeight());
2132
2133 startActivity(intent, opts.toBundle());
2134 } else {
2135 startActivity(intent);
2136 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002137 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138 } catch (SecurityException e) {
2139 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002140 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002141 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002142 "or use the exported attribute for this activity. "
2143 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002145 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002147
Michael Jurka86a720e2012-05-09 11:23:23 -07002148 boolean startActivitySafely(View v, Intent intent, Object tag) {
2149 boolean success = false;
2150 try {
2151 success = startActivity(v, intent, tag);
2152 } catch (ActivityNotFoundException e) {
2153 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2154 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2155 }
2156 return success;
2157 }
2158
Romain Guy8e633c52010-03-04 12:51:36 -08002159 void startActivityForResultSafely(Intent intent, int requestCode) {
2160 try {
2161 startActivityForResult(intent, requestCode);
2162 } catch (ActivityNotFoundException e) {
2163 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2164 } catch (SecurityException e) {
2165 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2166 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2167 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2168 "or use the exported attribute for this activity.", e);
2169 }
2170 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002171
Adam Cohena9cf38f2011-05-02 15:36:58 -07002172 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002173 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002174 Folder openFolder = mWorkspace.getFolderForTag(info);
2175
2176 // If the folder info reports that the associated folder is open, then verify that
2177 // it is actually opened. There have been a few instances where this gets out of sync.
2178 if (info.opened && openFolder == null) {
2179 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2180 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2181 info.opened = false;
2182 }
2183
Adam Cohenfb91f302012-06-11 15:45:18 -07002184 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002185 // Close any open folder
2186 closeFolder();
2187 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002188 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 } else {
2190 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 int folderScreen;
2192 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002193 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002194 // .. and close it
2195 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002196 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 // Close any folder open on the current screen
2198 closeFolder();
2199 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002200 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 }
2202 }
2203 }
2204 }
2205
Adam Cohen268c4752012-06-06 17:47:33 -07002206 /**
2207 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2208 * in the DragLayer in the exact absolute location of the original FolderIcon.
2209 */
2210 private void copyFolderIconToImage(FolderIcon fi) {
2211 final int width = fi.getMeasuredWidth();
2212 final int height = fi.getMeasuredHeight();
2213
2214 // Lazy load ImageView, Bitmap and Canvas
2215 if (mFolderIconImageView == null) {
2216 mFolderIconImageView = new ImageView(this);
2217 }
2218 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2219 mFolderIconBitmap.getHeight() != height) {
2220 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2221 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2222 }
2223
2224 DragLayer.LayoutParams lp;
2225 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2226 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2227 } else {
2228 lp = new DragLayer.LayoutParams(width, height);
2229 }
2230
Adam Cohen307fe232012-08-16 17:55:58 -07002231 // The layout from which the folder is being opened may be scaled, adjust the starting
2232 // view size by this scale factor.
2233 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002234 lp.customPosition = true;
2235 lp.x = mRectForFolderAnimation.left;
2236 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002237 lp.width = (int) (scale * width);
2238 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002239
2240 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2241 fi.draw(mFolderIconCanvas);
2242 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002243 if (fi.getFolder() != null) {
2244 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2245 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002246 }
Adam Cohen268c4752012-06-06 17:47:33 -07002247 // Just in case this image view is still in the drag layer from a previous animation,
2248 // we remove it and re-add it.
2249 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2250 mDragLayer.removeView(mFolderIconImageView);
2251 }
2252 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002253 if (fi.getFolder() != null) {
2254 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002255 }
Adam Cohen268c4752012-06-06 17:47:33 -07002256 }
2257
Adam Cohen2801caf2011-05-13 20:57:39 -07002258 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002259 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002260 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2261 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2262 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2263
Adam Cohenc51934b2011-07-26 21:07:43 -07002264 FolderInfo info = (FolderInfo) fi.getTag();
2265 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2266 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002267 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2268 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002269 }
2270
Adam Cohen268c4752012-06-06 17:47:33 -07002271 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2272 copyFolderIconToImage(fi);
2273 fi.setVisibility(View.INVISIBLE);
2274
Michael Jurka2ecf9952012-06-18 12:52:28 -07002275 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002276 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002277 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2278 oa.start();
2279 }
2280
Adam Cohen268c4752012-06-06 17:47:33 -07002281 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002282 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002283 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2284 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2285 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2286
Adam Cohen268c4752012-06-06 17:47:33 -07002287 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002288
Adam Cohen268c4752012-06-06 17:47:33 -07002289 // We remove and re-draw the FolderIcon in-case it has changed
2290 mDragLayer.removeView(mFolderIconImageView);
2291 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002292 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002293 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002294 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002295 oa.addListener(new AnimatorListenerAdapter() {
2296 @Override
2297 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002298 if (cl != null) {
2299 cl.clearFolderLeaveBehind();
2300 // Remove the ImageView copy of the FolderIcon and make the original visible.
2301 mDragLayer.removeView(mFolderIconImageView);
2302 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002303 }
2304 }
2305 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002306 oa.start();
2307 }
2308
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002309 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002310 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311 * is animated relative to the specified View. If the View is null, no animation
2312 * is played.
2313 *
2314 * @param folderInfo The FolderInfo describing the folder to open.
2315 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002316 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002317 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002318 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319
Adam Cohena9cf38f2011-05-02 15:36:58 -07002320 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002321
Adam Cohen4554ee12011-08-03 16:13:21 -07002322 // Just verify that the folder hasn't already been added to the DragLayer.
2323 // There was a one-off crash where the folder had a parent already.
2324 if (folder.getParent() == null) {
2325 mDragLayer.addView(folder);
2326 mDragController.addDropTarget((DropTarget) folder);
2327 } else {
2328 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2329 folder.getParent() + ").");
2330 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002331 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002332 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002333
2334 // Notify the accessibility manager that this folder "window" has appeared and occluded
2335 // the workspace items
2336 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2337 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002338 }
2339
2340 public void closeFolder() {
2341 Folder folder = mWorkspace.getOpenFolder();
2342 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002343 if (folder.isEditingName()) {
2344 folder.dismissEditingName();
2345 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002346 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002347
2348 // Dismiss the folder cling
2349 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002350 }
2351 }
2352
2353 void closeFolder(Folder folder) {
2354 folder.getInfo().opened = false;
2355
2356 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2357 if (parent != null) {
2358 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2359 shrinkAndFadeInFolderIcon(fi);
2360 }
2361 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002362
2363 // Notify the accessibility manager that this folder "window" has disappeard and no
2364 // longer occludeds the workspace items
2365 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002366 }
2367
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002368 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002369 if (!isDraggingEnabled()) return false;
2370 if (isWorkspaceLocked()) return false;
2371 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002372
2373 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002374 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 }
2376
Michael Jurka0280c3b2010-09-17 15:00:07 -07002377 resetAddInfo();
2378 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002380 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002381 return true;
2382 }
2383
Winson Chung3d503fb2011-07-13 17:25:49 -07002384 // The hotseat touch handling does not go through Workspace, and we always allow long press
2385 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002386 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002387 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2388 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002389 if (itemUnderLongClick == null) {
2390 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002391 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2392 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002393 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002394 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002395 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002396 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002397 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002398 }
2399 }
2400 }
2401 return true;
2402 }
2403
Winson Chung3d503fb2011-07-13 17:25:49 -07002404 boolean isHotseatLayout(View layout) {
2405 return mHotseat != null && layout != null &&
2406 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2407 }
2408 Hotseat getHotseat() {
2409 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002410 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002411 SearchDropTargetBar getSearchBar() {
2412 return mSearchDropTargetBar;
2413 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002414
Winson Chung3d503fb2011-07-13 17:25:49 -07002415 /**
2416 * Returns the CellLayout of the specified container at the specified screen.
2417 */
2418 CellLayout getCellLayout(long container, int screen) {
2419 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2420 if (mHotseat != null) {
2421 return mHotseat.getLayout();
2422 } else {
2423 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002424 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002425 } else {
2426 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002427 }
2428 }
2429
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430 Workspace getWorkspace() {
2431 return mWorkspace;
2432 }
2433
Daniel Sandler843e8602010-06-07 14:59:01 -04002434 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
Craig Mautner360310b2012-10-26 15:13:08 -07002435 @Override
Daniel Sandler843e8602010-06-07 14:59:01 -04002436 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002437 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002438 }
2439
Craig Mautner360310b2012-10-26 15:13:08 -07002440 @Override
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002441 public boolean isAllAppsButtonRank(int rank) {
2442 return mHotseat.isAllAppsButtonRank(rank);
2443 }
2444
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002445 /**
2446 * Helper method for the cameraZoomIn/cameraZoomOut animations
2447 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002448 * @param scaleFactor The scale factor used for the zoom
2449 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002450 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002451 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002452 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002453 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002454
Winson Chung18f41f82012-05-09 13:28:10 -07002455 void disableWallpaperIfInAllApps() {
2456 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002457 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002458 if (mAppsCustomizeTabHost != null &&
2459 !mAppsCustomizeTabHost.isTransitioning()) {
2460 updateWallpaperVisibility(false);
2461 }
2462 }
2463 }
2464
Craig Mautner360310b2012-10-26 15:13:08 -07002465 private void setWorkspaceBackground(boolean workspace) {
2466 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002467 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002468 }
2469
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002470 void updateWallpaperVisibility(boolean visible) {
2471 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2472 int curflags = getWindow().getAttributes().flags
2473 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2474 if (wpflags != curflags) {
2475 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2476 }
Craig Mautner360310b2012-10-26 15:13:08 -07002477 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002478 }
2479
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002480 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2481 if (v instanceof LauncherTransitionable) {
2482 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2483 }
2484 }
2485
Michael Jurkabed61d22012-02-14 22:51:29 -08002486 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2487 if (v instanceof LauncherTransitionable) {
2488 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2489 }
Winson Chung70442722012-02-10 15:43:22 -08002490
2491 // Update the workspace transition step as well
2492 dispatchOnLauncherTransitionStep(v, 0f);
2493 }
2494
2495 private void dispatchOnLauncherTransitionStep(View v, float t) {
2496 if (v instanceof LauncherTransitionable) {
2497 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2498 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002499 }
2500
2501 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2502 if (v instanceof LauncherTransitionable) {
2503 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2504 }
Winson Chung70442722012-02-10 15:43:22 -08002505
2506 // Update the workspace transition step as well
2507 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002508 }
2509
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002510 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002511 * Things to test when changing the following seven functions.
2512 * - Home from workspace
2513 * - from center screen
2514 * - from other screens
2515 * - Home from all apps
2516 * - from center screen
2517 * - from other screens
2518 * - Back from all apps
2519 * - from center screen
2520 * - from other screens
2521 * - Launch app from workspace and quit
2522 * - with back
2523 * - with home
2524 * - Launch app from all apps and quit
2525 * - with back
2526 * - with home
2527 * - Go to a screen that's not the default, then all
2528 * apps, and launch and app, and go back
2529 * - with back
2530 * -with home
2531 * - On workspace, long press power and go back
2532 * - with back
2533 * - with home
2534 * - On all apps, long press power and go back
2535 * - with back
2536 * - with home
2537 * - On workspace, power off
2538 * - On all apps, power off
2539 * - Launch an app and turn off the screen while in that app
2540 * - Go back with home key
2541 * - Go back with back key TODO: make this not go to workspace
2542 * - From all apps
2543 * - From workspace
2544 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2545 * - From all apps
2546 * - From the center workspace
2547 * - From another workspace
2548 */
2549
2550 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002551 * Zoom the camera out from the workspace to reveal 'toView'.
2552 * Assumes that the view to show is anchored at either the very top or very bottom
2553 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002554 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002555 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002556 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002557 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002558 mStateAnimation.cancel();
2559 mStateAnimation = null;
2560 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002561 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002562
Winson Chungf0ea4d32011-06-06 14:27:16 -07002563 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2564 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2565 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002566 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002567 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002568 final int startDelay =
2569 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002570
Michael Jurkab3e22d92011-10-31 15:58:33 -07002571 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002572
Michael Jurkad74c9842011-07-10 12:44:21 -07002573 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002574 Animator workspaceAnim =
2575 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002576
2577 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002578 toView.setScaleX(scale);
2579 toView.setScaleY(scale);
2580 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2581 scaleAnim.
2582 scaleX(1f).scaleY(1f).
2583 setDuration(duration).
2584 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002585
Winson Chungf0ea4d32011-06-06 14:27:16 -07002586 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002587 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002588 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002589 .ofFloat(toView, "alpha", 0f, 1f)
2590 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002591 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002592 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2593 @Override
2594 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002595 if (animation == null) {
2596 throw new RuntimeException("animation is null");
2597 }
Winson Chung70442722012-02-10 15:43:22 -08002598 float t = (Float) animation.getAnimatedValue();
2599 dispatchOnLauncherTransitionStep(fromView, t);
2600 dispatchOnLauncherTransitionStep(toView, t);
2601 }
2602 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002603
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002604 // toView should appear right at the end of the workspace shrink
2605 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002606 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002607 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002608 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002609
2610 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002611 boolean animationCancelled = false;
2612
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002613 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002614 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002615 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002616 // Prepare the position
2617 toView.setTranslationX(0.0f);
2618 toView.setTranslationY(0.0f);
2619 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002620 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002621 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002622 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002623 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002624 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2625 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002626
Michael Jurkafa7969f2012-09-21 16:39:14 -07002627 if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chung32174c82011-07-19 15:47:55 -07002628 // Hide the workspace scrollbar
2629 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002630 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002631 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002632 if (!animationCancelled) {
2633 updateWallpaperVisibility(false);
2634 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002635
2636 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002637 if (mSearchDropTargetBar != null) {
2638 mSearchDropTargetBar.hideSearchBar(false);
2639 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002640 }
2641
Adam Cohencff6af82011-09-13 14:51:53 -07002642 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002643 public void onAnimationCancel(Animator animation) {
2644 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002645 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002646 });
2647
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002648 if (workspaceAnim != null) {
2649 mStateAnimation.play(workspaceAnim);
2650 }
Michael Jurka1899a362011-11-03 13:50:45 -07002651
2652 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002653
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002654 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2655 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002656
2657 // If any of the objects being animated haven't been measured/laid out
2658 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002659 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002660 (mWorkspace.getMeasuredWidth() == 0) ||
2661 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002662 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002663 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002664
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002665 final AnimatorSet stateAnimation = mStateAnimation;
2666 final Runnable startAnimRunnable = new Runnable() {
2667 public void run() {
2668 // Check that mStateAnimation hasn't changed while
2669 // we waited for a layout/draw pass
2670 if (mStateAnimation != stateAnimation)
2671 return;
2672 setPivotsForZoom(toView, scale);
2673 dispatchOnLauncherTransitionStart(fromView, animated, false);
2674 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002675 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002676 }
2677 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002678 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002679 final ViewTreeObserver observer = toView.getViewTreeObserver();
2680 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2681 public void onGlobalLayout() {
2682 startAnimRunnable.run();
2683 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2684 }
2685 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002686 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002687 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002688 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002689 } else {
2690 toView.setTranslationX(0.0f);
2691 toView.setTranslationY(0.0f);
2692 toView.setScaleX(1.0f);
2693 toView.setScaleY(1.0f);
2694 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002695 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002696
Michael Jurkabed61d22012-02-14 22:51:29 -08002697 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2698 // Hide the workspace scrollbar
2699 mWorkspace.hideScrollingIndicator(true);
2700 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002701
2702 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002703 if (mSearchDropTargetBar != null) {
2704 mSearchDropTargetBar.hideSearchBar(false);
2705 }
Michael Jurkaabded662011-03-04 12:06:57 -08002706 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002707 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002708 dispatchOnLauncherTransitionStart(fromView, animated, false);
2709 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002710 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002711 dispatchOnLauncherTransitionStart(toView, animated, false);
2712 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002713 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002714 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002715 }
2716
2717 /**
2718 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002719 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002720 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002721 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002722 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2723 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002724
Michael Jurkab3e22d92011-10-31 15:58:33 -07002725 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002726 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002727 mStateAnimation.cancel();
2728 mStateAnimation = null;
2729 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002730 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002731
Winson Chungf0ea4d32011-06-06 14:27:16 -07002732 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002733 final int fadeOutDuration =
2734 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002735 final float scaleFactor = (float)
2736 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2737 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002738 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002739 Animator workspaceAnim = null;
2740
2741 if (toState == State.WORKSPACE) {
2742 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2743 workspaceAnim = mWorkspace.getChangeStateAnimation(
2744 Workspace.State.NORMAL, animated, stagger);
2745 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2746 workspaceAnim = mWorkspace.getChangeStateAnimation(
2747 Workspace.State.SPRING_LOADED, animated);
2748 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002749
Michael Jurkab3e22d92011-10-31 15:58:33 -07002750 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002751 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002752 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002753 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002754 final LauncherViewPropertyAnimator scaleAnim =
2755 new LauncherViewPropertyAnimator(fromView);
2756 scaleAnim.
2757 scaleX(scaleFactor).scaleY(scaleFactor).
2758 setDuration(duration).
2759 setInterpolator(new Workspace.ZoomInInterpolator());
2760
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002761 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002762 .ofFloat(fromView, "alpha", 1f, 0f)
2763 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002764 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002765 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2766 @Override
2767 public void onAnimationUpdate(ValueAnimator animation) {
2768 float t = 1f - (Float) animation.getAnimatedValue();
2769 dispatchOnLauncherTransitionStep(fromView, t);
2770 dispatchOnLauncherTransitionStep(toView, t);
2771 }
2772 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002773
Michael Jurka2ecf9952012-06-18 12:52:28 -07002774 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002775
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002776 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2777 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002778 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002779
2780 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002781 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002782 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002783 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002784 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002785 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2786 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002787 if (mWorkspace != null) {
2788 mWorkspace.hideScrollingIndicator(false);
2789 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002790 if (onCompleteRunnable != null) {
2791 onCompleteRunnable.run();
2792 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002793 mAppsCustomizeContent.updateCurrentPageScroll();
2794 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002795 }
2796 });
2797
Winson Chungf0ea4d32011-06-06 14:27:16 -07002798 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002799 if (workspaceAnim != null) {
2800 mStateAnimation.play(workspaceAnim);
2801 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002802 dispatchOnLauncherTransitionStart(fromView, animated, true);
2803 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002804 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002805 } else {
2806 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002807 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002808 dispatchOnLauncherTransitionStart(fromView, animated, true);
2809 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002810 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002811 dispatchOnLauncherTransitionStart(toView, animated, true);
2812 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002813 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002814 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002815 }
2816
Michael Jurkae326f182011-11-21 14:05:46 -08002817 @Override
2818 public void onTrimMemory(int level) {
2819 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002820 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002821 mAppsCustomizeTabHost.onTrimMemory();
2822 }
2823 }
2824
Winson Chung18f41f82012-05-09 13:28:10 -07002825 @Override
2826 public void onWindowFocusChanged(boolean hasFocus) {
2827 if (!hasFocus) {
2828 // When another window occludes launcher (like the notification shade, or recents),
2829 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2830 updateWallpaperVisibility(true);
2831 } else {
2832 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002833 mWorkspace.postDelayed(new Runnable() {
2834 @Override
2835 public void run() {
2836 disableWallpaperIfInAllApps();
2837 }
2838 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002839 }
2840 }
2841
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002842 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002843 showWorkspace(animated, null);
2844 }
2845
2846 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002847 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002848 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002849 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002850 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002851
Winson Chungc7d2b602012-05-16 17:02:20 -07002852 // Show the search bar (only animate if we were showing the drop target bar in spring
2853 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07002854 if (mSearchDropTargetBar != null) {
2855 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2856 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002857
Michael Jurkab737ee62011-11-15 15:57:22 -08002858 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002859 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002860
2861 // Set focus to the AppsCustomize button
2862 if (mAllAppsButton != null) {
2863 mAllAppsButton.requestFocus();
2864 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002865 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002866
Michael Jurkab737ee62011-11-15 15:57:22 -08002867 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002868
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002869 // Change the state *after* we've called all the transition code
2870 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002871
Winson Chung5fb63472011-02-02 17:03:37 -08002872 // Resume the auto-advance of widgets
2873 mUserPresent = true;
2874 updateRunning();
2875
alanv1d4fde62012-10-17 13:15:47 -07002876 // Send an accessibility event to announce the context change
2877 getWindow().getDecorView()
2878 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Joe Onorato00acb122009-08-04 16:04:30 -04002879 }
2880
Michael Jurkab3e22d92011-10-31 15:58:33 -07002881 void showAllApps(boolean animated) {
2882 if (mState != State.WORKSPACE) return;
2883
2884 showAppsCustomizeHelper(animated, false);
2885 mAppsCustomizeTabHost.requestFocus();
2886
Michael Jurkab3e22d92011-10-31 15:58:33 -07002887 // Change the state *after* we've called all the transition code
2888 mState = State.APPS_CUSTOMIZE;
2889
2890 // Pause the auto-advance of widgets until we are out of AllApps
2891 mUserPresent = false;
2892 updateRunning();
2893 closeFolder();
2894
2895 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07002896 getWindow().getDecorView()
2897 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002898 }
2899
Adam Cohen7777d962011-08-18 18:58:38 -07002900 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002901 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002902 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002903 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002904 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002905 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002906 }
Adam Cohen7777d962011-08-18 18:58:38 -07002907
Adam Cohened66b2b2012-01-23 17:28:51 -08002908 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2909 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002910 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2911
Winson Chunge7a03942011-08-05 15:05:12 -07002912 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002913 @Override
2914 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002915 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002916 // Before we show workspace, hide all apps again because
2917 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2918 // clean up our state transition functions
2919 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002920 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002921 } else {
2922 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002923 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002924 }
2925 }, (extendedDelay ?
2926 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2927 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2928 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002929
Michael Jurkad3ef3062010-11-23 16:23:58 -08002930 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002931 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002932 final boolean animated = true;
2933 final boolean springLoaded = true;
2934 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002935 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002936 }
2937 // Otherwise, we are not in spring loaded mode, so don't do anything.
2938 }
2939
Michael Jurkab737ee62011-11-15 15:57:22 -08002940 void hideDockDivider() {
2941 if (mQsbDivider != null && mDockDivider != null) {
2942 mQsbDivider.setVisibility(View.INVISIBLE);
2943 mDockDivider.setVisibility(View.INVISIBLE);
2944 }
2945 }
2946
2947 void showDockDivider(boolean animated) {
2948 if (mQsbDivider != null && mDockDivider != null) {
2949 mQsbDivider.setVisibility(View.VISIBLE);
2950 mDockDivider.setVisibility(View.VISIBLE);
2951 if (mDividerAnimator != null) {
2952 mDividerAnimator.cancel();
2953 mQsbDivider.setAlpha(1f);
2954 mDockDivider.setAlpha(1f);
2955 mDividerAnimator = null;
2956 }
2957 if (animated) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07002958 mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
2959 mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f),
2960 LauncherAnimUtils.ofFloat(mDockDivider, "alpha", 1f));
Winson Chungadf0c182012-08-23 14:59:07 -07002961 int duration = 0;
2962 if (mSearchDropTargetBar != null) {
2963 duration = mSearchDropTargetBar.getTransitionInDuration();
2964 }
2965 mDividerAnimator.setDuration(duration);
Michael Jurkab737ee62011-11-15 15:57:22 -08002966 mDividerAnimator.start();
2967 }
2968 }
2969 }
2970
Michael Jurkab3e22d92011-10-31 15:58:33 -07002971 void lockAllApps() {
2972 // TODO
2973 }
2974
2975 void unlockAllApps() {
2976 // TODO
2977 }
2978
Winson Chungf0ea4d32011-06-06 14:27:16 -07002979 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002980 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002981 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002982 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002983 if (!LauncherApplication.isScreenLarge()) {
2984 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002985 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002986 int duration = 0;
2987 if (mSearchDropTargetBar != null) {
2988 duration = mSearchDropTargetBar.getTransitionInDuration();
2989 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002990 mHotseat.animate().alpha(1f).setDuration(duration);
2991 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002992 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002993 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002994 }
2995 }
2996 }
2997
2998 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002999 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003000 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003001 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003002 if (!LauncherApplication.isScreenLarge()) {
3003 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003004 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003005 int duration = 0;
3006 if (mSearchDropTargetBar != null) {
3007 duration = mSearchDropTargetBar.getTransitionOutDuration();
3008 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003009 mHotseat.animate().alpha(0f).setDuration(duration);
3010 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003011 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003012 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003013 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003014 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003015 }
3016
Patrick Dubroy5f445422011-02-18 14:35:21 -08003017 /**
3018 * Add an item from all apps or customize onto the given workspace screen.
3019 * If layout is null, add to the current screen.
3020 */
3021 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003022 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003023 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003024 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003025 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003026
Winson Chungdff8ebb2011-09-08 17:25:31 -07003027 /** Maps the current orientation to an index for referencing orientation correct global icons */
3028 private int getCurrentOrientationIndexForGlobalIcons() {
3029 // default - 0, landscape - 1
3030 switch (getResources().getConfiguration().orientation) {
3031 case Configuration.ORIENTATION_LANDSCAPE:
3032 return 1;
3033 default:
3034 return 0;
3035 }
3036 }
3037
Michael Jurkaae65ee32012-04-30 11:45:54 -07003038 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003039 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003040 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003041 // Look for the toolbar icon specified in the activity meta-data
3042 Bundle metaData = packageManager.getActivityInfo(
3043 activityName, PackageManager.GET_META_DATA).metaData;
3044 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003045 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003046 if (iconResId != 0) {
3047 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003048 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003049 }
3050 }
3051 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003052 // This can happen if the activity defines an invalid drawable
3053 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3054 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003055 } catch (Resources.NotFoundException nfe) {
3056 // This can happen if the activity defines an invalid drawable
3057 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3058 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003059 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003060 return null;
3061 }
3062
3063 // if successful in getting icon, return it; otherwise, set button to use default drawable
3064 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003065 int buttonId, ComponentName activityName, int fallbackDrawableId,
3066 String toolbarResourceName) {
3067 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003068 Resources r = getResources();
3069 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3070 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003071
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003072 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003073 // If we were unable to find the icon via the meta-data, use a generic one
3074 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003075 toolbarIcon = r.getDrawable(fallbackDrawableId);
3076 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003077 if (button != null) {
3078 button.setCompoundDrawables(toolbarIcon, null, null, null);
3079 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003080 return null;
3081 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003082 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003083 if (button != null) {
3084 button.setCompoundDrawables(toolbarIcon, null, null, null);
3085 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003086 return toolbarIcon.getConstantState();
3087 }
3088 }
3089
3090 // if successful in getting icon, return it; otherwise, set button to use default drawable
3091 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003092 int buttonId, ComponentName activityName, int fallbackDrawableId,
3093 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003094 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003095 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003096
Michael Jurka19e0fc52011-07-22 18:00:21 -07003097 if (button != null) {
3098 // If we were unable to find the icon via the meta-data, use a
3099 // generic one
3100 if (toolbarIcon == null) {
3101 button.setImageResource(fallbackDrawableId);
3102 } else {
3103 button.setImageDrawable(toolbarIcon);
3104 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003105 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003106
3107 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3108
Michael Jurka0423dcf2010-10-05 14:56:18 -07003109 }
3110
Winson Chung1b884092012-06-08 17:13:02 -07003111 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003112 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003113 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003114 }
3115
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003116 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003117 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003118 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003119 }
3120
Winson Chungbb185bd2011-11-21 12:31:42 -08003121 private void invalidatePressedFocusedStates(View container, View button) {
3122 if (container instanceof HolographicLinearLayout) {
3123 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3124 layout.invalidatePressedFocusedStates();
3125 } else if (button instanceof HolographicImageView) {
3126 HolographicImageView view = (HolographicImageView) button;
3127 view.invalidatePressedFocusedStates();
3128 }
3129 }
3130
Winson Chungc51db6a2011-10-05 11:44:49 -07003131 private boolean updateGlobalSearchIcon() {
3132 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003133 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003134 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003135 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003136 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003137
Winson Chung1cad91e2011-05-25 17:41:01 -07003138 final SearchManager searchManager =
3139 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3140 ComponentName activityName = searchManager.getGlobalSearchActivity();
3141 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003142 int coi = getCurrentOrientationIndexForGlobalIcons();
3143 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003144 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3145 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3146 if (sGlobalSearchIcon[coi] == null) {
3147 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3148 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3149 TOOLBAR_ICON_METADATA_NAME);
3150 }
3151
Winson Chungc51db6a2011-10-05 11:44:49 -07003152 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3153 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003154 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003155 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003156 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003157 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003158 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3159 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3160 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003161 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07003162 if (voiceButtonProxy != null) {
3163 voiceButtonProxy.setVisibility(View.GONE);
3164 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003165 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003166 }
3167 }
3168
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003169 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003170 final View searchButtonContainer = findViewById(R.id.search_button_container);
3171 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003172 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003173 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003174 }
3175
Winson Chungc51db6a2011-10-05 11:44:49 -07003176 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003177 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003178 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003179 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003180
Winson Chungc51db6a2011-10-05 11:44:49 -07003181 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003182 final SearchManager searchManager =
3183 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3184 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3185
3186 ComponentName activityName = null;
3187 if (globalSearchActivity != null) {
3188 // Check if the global search activity handles voice search
3189 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3190 intent.setPackage(globalSearchActivity.getPackageName());
3191 activityName = intent.resolveActivity(getPackageManager());
3192 }
3193
3194 if (activityName == null) {
3195 // Fallback: check if an activity other than the global search activity
3196 // resolves this
3197 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3198 activityName = intent.resolveActivity(getPackageManager());
3199 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003200 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003201 int coi = getCurrentOrientationIndexForGlobalIcons();
3202 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003203 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3204 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3205 if (sVoiceSearchIcon[coi] == null) {
3206 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3207 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3208 TOOLBAR_ICON_METADATA_NAME);
3209 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003210 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003211 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003212 if (voiceButtonProxy != null) {
3213 voiceButtonProxy.setVisibility(View.VISIBLE);
3214 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003215 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003216 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003217 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003218 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003219 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003220 if (voiceButtonProxy != null) {
3221 voiceButtonProxy.setVisibility(View.GONE);
3222 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003223 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003224 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003225 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003226
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003227 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003228 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3229 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003230 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003231 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003232 }
3233
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003234 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003235 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003236 */
3237 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003238 final View marketButton = findViewById(R.id.market_button);
3239 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3240 // Find the app market activity by resolving an intent.
3241 // (If multiple app markets are installed, it will return the ResolverActivity.)
3242 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003243 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003244 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003245 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003246 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003247 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3248 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003249 marketButton.setVisibility(View.VISIBLE);
3250 } else {
3251 // We should hide and disable the view so that we don't try and restore the visibility
3252 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3253 marketButton.setVisibility(View.GONE);
3254 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003255 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003256 }
3257
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003258 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003259 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3260 Resources r = getResources();
3261 Drawable marketIconDrawable = d.newDrawable(r);
3262 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3263 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3264 marketIconDrawable.setBounds(0, 0, w, h);
3265
3266 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003267 }
3268
Michael Jurkad7c28052012-04-27 15:43:36 -07003269 @Override
3270 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003271 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003272 final List<CharSequence> text = event.getText();
3273 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003274 // Populate event with a fake title based on the current state.
3275 if (mState == State.APPS_CUSTOMIZE) {
3276 text.add(getString(R.string.all_apps_button_label));
3277 } else {
3278 text.add(getString(R.string.all_apps_home_button_label));
3279 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003280 return result;
3281 }
3282
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003283 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003284 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003285 */
3286 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3287 @Override
3288 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003289 closeSystemDialogs();
3290 }
3291 }
3292
3293 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003294 * Receives notifications whenever the appwidgets are reset.
3295 */
3296 private class AppWidgetResetObserver extends ContentObserver {
3297 public AppWidgetResetObserver() {
3298 super(new Handler());
3299 }
3300
3301 @Override
3302 public void onChange(boolean selfChange) {
3303 onAppWidgetReset();
3304 }
3305 }
3306
3307 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003308 * If the activity is currently paused, signal that we need to run the passed Runnable
3309 * in onResume.
3310 *
3311 * This needs to be called from incoming places where resources might have been loaded
3312 * while we are paused. That is becaues the Configuration might be wrong
3313 * when we're not running, and if it comes back to what it was when we
3314 * were paused, we are not restarted.
3315 *
3316 * Implementation of the method from LauncherModel.Callbacks.
3317 *
3318 * @return true if we are currently paused. The caller might be able to
3319 * skip some work in that case since we will come back again.
3320 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003321 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003322 if (mPaused) {
3323 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003324 if (deletePreviousRunnables) {
3325 while (mOnResumeCallbacks.remove(run)) {
3326 }
3327 }
Michael Jurka7607c2f2013-04-03 14:33:19 -07003328 mOnResumeCallbacks.add(run);
3329 return true;
3330 } else {
3331 return false;
3332 }
3333 }
3334
Michael Jurkac402cd92013-05-20 15:49:32 +02003335 private boolean waitUntilResume(Runnable run) {
3336 return waitUntilResume(run, false);
3337 }
3338
Michael Jurka7607c2f2013-04-03 14:33:19 -07003339 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003340 * If the activity is currently paused, signal that we need to re-run the loader
3341 * in onResume.
3342 *
3343 * This needs to be called from incoming places where resources might have been loaded
3344 * while we are paused. That is becaues the Configuration might be wrong
3345 * when we're not running, and if it comes back to what it was when we
3346 * were paused, we are not restarted.
3347 *
3348 * Implementation of the method from LauncherModel.Callbacks.
3349 *
3350 * @return true if we are currently paused. The caller might be able to
3351 * skip some work in that case since we will come back again.
3352 */
3353 public boolean setLoadOnResume() {
3354 if (mPaused) {
3355 Log.i(TAG, "setLoadOnResume");
3356 mOnResumeNeedsLoad = true;
3357 return true;
3358 } else {
3359 return false;
3360 }
3361 }
3362
3363 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003364 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003365 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003366 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003367 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003368 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003369 } else {
3370 return SCREEN_COUNT / 2;
3371 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003372 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003373
Joe Onorato9c1289c2009-08-17 11:03:03 -04003374 /**
3375 * Refreshes the shortcuts shown on the workspace.
3376 *
3377 * Implementation of the method from LauncherModel.Callbacks.
3378 */
3379 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003380 // If we're starting binding all over again, clear any bind calls we'd postponed in
3381 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3382 // from scratch again
3383 mOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003384
Michael Jurka7607c2f2013-04-03 14:33:19 -07003385 final Workspace workspace = mWorkspace;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003386 mNewShortcutAnimatePage = -1;
3387 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003388 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003389 int count = workspace.getChildCount();
3390 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003391 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003392 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3393 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003394 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003395 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003396 if (mHotseat != null) {
3397 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003398 }
3399 }
3400
3401 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003402 * Bind the items start-end from the list.
3403 *
3404 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003405 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003406 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end) {
3407 if (waitUntilResume(new Runnable() {
3408 public void run() {
3409 bindItems(shortcuts, start, end);
3410 }
3411 })) {
3412 return;
3413 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003414
Winson Chungf0c6ae02012-03-21 16:10:31 -07003415 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3416 Set<String> newApps = new HashSet<String>();
3417 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3418
3419 Workspace workspace = mWorkspace;
3420 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003421 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003422
3423 // Short circuit if we are loading dock items for a configuration which has no dock
3424 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3425 mHotseat == null) {
3426 continue;
3427 }
3428
Joe Onorato9c1289c2009-08-17 11:03:03 -04003429 switch (item.itemType) {
3430 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3431 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003432 ShortcutInfo info = (ShortcutInfo) item;
3433 String uri = info.intent.toUri(0).toString();
3434 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003435 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3436 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003437 boolean animateIconUp = false;
3438 synchronized (newApps) {
3439 if (newApps.contains(uri)) {
3440 animateIconUp = newApps.remove(uri);
3441 }
3442 }
3443 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003444 // Prepare the view to be animated up
3445 shortcut.setAlpha(0f);
3446 shortcut.setScaleX(0f);
3447 shortcut.setScaleY(0f);
3448 mNewShortcutAnimatePage = item.screen;
3449 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3450 mNewShortcutAnimateViews.add(shortcut);
3451 }
3452 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003453 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003454 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003455 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003456 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003457 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003458 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3459 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003460 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003461 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003462 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003463
Joe Onorato9c1289c2009-08-17 11:03:03 -04003464 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003465 }
3466
Joe Onorato9c1289c2009-08-17 11:03:03 -04003467 /**
3468 * Implementation of the method from LauncherModel.Callbacks.
3469 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003470 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
3471 if (waitUntilResume(new Runnable() {
3472 public void run() {
3473 bindFolders(folders);
3474 }
3475 })) {
3476 return;
3477 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003478 sFolders.clear();
3479 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003480 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003481
3482 /**
3483 * Add the views for a widget to the workspace.
3484 *
3485 * Implementation of the method from LauncherModel.Callbacks.
3486 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003487 public void bindAppWidget(final LauncherAppWidgetInfo item) {
3488 if (waitUntilResume(new Runnable() {
3489 public void run() {
3490 bindAppWidget(item);
3491 }
3492 })) {
3493 return;
3494 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003495
Daniel Sandler843e8602010-06-07 14:59:01 -04003496 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3497 if (DEBUG_WIDGETS) {
3498 Log.d(TAG, "bindAppWidget: " + item);
3499 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003500 final Workspace workspace = mWorkspace;
3501
3502 final int appWidgetId = item.appWidgetId;
3503 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003504 if (DEBUG_WIDGETS) {
3505 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3506 }
3507
Joe Onorato9c1289c2009-08-17 11:03:03 -04003508 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3509
Joe Onorato9c1289c2009-08-17 11:03:03 -04003510 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003511 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003512
Winson Chung3d503fb2011-07-13 17:25:49 -07003513 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003514 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003515 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3516
Joe Onorato9c1289c2009-08-17 11:03:03 -04003517 workspace.requestLayout();
3518
Daniel Sandler843e8602010-06-07 14:59:01 -04003519 if (DEBUG_WIDGETS) {
3520 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3521 + (SystemClock.uptimeMillis()-start) + "ms");
3522 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003523 }
3524
Adam Cohen1462de32012-07-24 22:34:36 -07003525 public void onPageBoundSynchronously(int page) {
3526 mSynchronouslyBoundPages.add(page);
3527 }
3528
Joe Onorato9c1289c2009-08-17 11:03:03 -04003529 /**
3530 * Callback saying that there aren't any more items to bind.
3531 *
3532 * Implementation of the method from LauncherModel.Callbacks.
3533 */
3534 public void finishBindingItems() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003535 if (waitUntilResume(new Runnable() {
3536 public void run() {
3537 finishBindingItems();
3538 }
3539 })) {
3540 return;
3541 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003542 if (mSavedState != null) {
3543 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003544 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003545 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003546 mSavedState = null;
3547 }
3548
Adam Cohen1462de32012-07-24 22:34:36 -07003549 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003550
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003551 // If we received the result of any pending adds while the loader was running (e.g. the
3552 // widget configuration forced an orientation change), process them now.
3553 for (int i = 0; i < sPendingAddList.size(); i++) {
3554 completeAdd(sPendingAddList.get(i));
3555 }
3556 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003557
Winson Chungc51db6a2011-10-05 11:44:49 -07003558 // Update the market app icon as necessary (the other icons will be managed in response to
3559 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003560 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003561
Winson Chungf0c6ae02012-03-21 16:10:31 -07003562 // Animate up any icons as necessary
3563 if (mVisible || mWorkspaceLoading) {
3564 Runnable newAppsRunnable = new Runnable() {
3565 @Override
3566 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003567 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003568 }
3569 };
Winson Chunga2413752012-04-03 14:22:34 -07003570
3571 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3572 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3573 if (canRunNewAppsAnimation()) {
3574 // If the user has not interacted recently, then either snap to the new page to show
3575 // the new-apps animation or just run them if they are to appear on the current page
3576 if (willSnapPage) {
3577 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3578 } else {
3579 runNewAppsAnimation(false);
3580 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003581 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003582 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003583 // are on another page (or just normally if they are added to the current page)
3584 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003585 }
3586 }
3587
3588 mWorkspaceLoading = false;
3589 }
3590
Winson Chunga2413752012-04-03 14:22:34 -07003591 private boolean canRunNewAppsAnimation() {
3592 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3593 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3594 }
3595
Winson Chungf0c6ae02012-03-21 16:10:31 -07003596 /**
3597 * Runs a new animation that scales up icons that were added while Launcher was in the
3598 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003599 *
3600 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003601 */
Winson Chunga2413752012-04-03 14:22:34 -07003602 private void runNewAppsAnimation(boolean immediate) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003603 AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003604 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003605
3606 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003607 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3608 @Override
3609 public int compare(View a, View b) {
3610 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3611 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3612 int cellCountX = LauncherModel.getCellCountX();
3613 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3614 }
3615 });
Winson Chunga2413752012-04-03 14:22:34 -07003616
3617 // Animate each of the views in place (or show them immediately if requested)
3618 if (immediate) {
3619 for (View v : mNewShortcutAnimateViews) {
3620 v.setAlpha(1f);
3621 v.setScaleX(1f);
3622 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003623 }
Winson Chunga2413752012-04-03 14:22:34 -07003624 } else {
3625 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3626 View v = mNewShortcutAnimateViews.get(i);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003627 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
Winson Chunga2413752012-04-03 14:22:34 -07003628 PropertyValuesHolder.ofFloat("alpha", 1f),
3629 PropertyValuesHolder.ofFloat("scaleX", 1f),
3630 PropertyValuesHolder.ofFloat("scaleY", 1f));
3631 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3632 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3633 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3634 bounceAnims.add(bounceAnim);
3635 }
3636 anim.playTogether(bounceAnims);
3637 anim.addListener(new AnimatorListenerAdapter() {
3638 @Override
3639 public void onAnimationEnd(Animator animation) {
Michael Jurkad6dd7c82012-10-19 17:15:16 +02003640 if (mWorkspace != null) {
3641 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3642 }
Winson Chunga2413752012-04-03 14:22:34 -07003643 }
3644 });
3645 anim.start();
3646 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003647
3648 // Clean up
3649 mNewShortcutAnimatePage = -1;
3650 mNewShortcutAnimateViews.clear();
3651 new Thread("clearNewAppsThread") {
3652 public void run() {
3653 mSharedPrefs.edit()
3654 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3655 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3656 .commit();
3657 }
3658 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003659 }
3660
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003661 @Override
3662 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003663 boolean searchVisible = updateGlobalSearchIcon();
3664 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003665 if (mSearchDropTargetBar != null) {
3666 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3667 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003668 }
3669
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003670 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003671 * Add the icons for all apps.
3672 *
3673 * Implementation of the method from LauncherModel.Callbacks.
3674 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003675 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003676 Runnable setAllAppsRunnable = new Runnable() {
3677 public void run() {
3678 if (mAppsCustomizeContent != null) {
3679 mAppsCustomizeContent.setApps(apps);
3680 }
3681 }
3682 };
3683
Michael Jurkac57b7a82011-08-09 22:02:20 -07003684 // Remove the progress bar entirely; we could also make it GONE
3685 // but better to remove it since we know it's not going to be used
3686 View progressBar = mAppsCustomizeTabHost.
3687 findViewById(R.id.apps_customize_progress_bar);
3688 if (progressBar != null) {
3689 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chungc93e5ae2012-07-23 20:48:26 -07003690
3691 // We just post the call to setApps so the user sees the progress bar
3692 // disappear-- otherwise, it just looks like the progress bar froze
3693 // which doesn't look great
3694 mAppsCustomizeTabHost.post(setAllAppsRunnable);
3695 } else {
3696 // If we did not initialize the spinner in onCreate, then we can directly set the
3697 // list of applications without waiting for any progress bars views to be hidden.
3698 setAllAppsRunnable.run();
Winson Chung785d2eb2011-04-14 16:08:02 -07003699 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003700 }
3701
3702 /**
3703 * A package was installed.
3704 *
3705 * Implementation of the method from LauncherModel.Callbacks.
3706 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003707 public void bindAppsAdded(final ArrayList<ApplicationInfo> apps) {
3708 if (waitUntilResume(new Runnable() {
3709 public void run() {
3710 bindAppsAdded(apps);
3711 }
3712 })) {
3713 return;
3714 }
3715
Winson Chungf0ea4d32011-06-06 14:27:16 -07003716
Winson Chung785d2eb2011-04-14 16:08:02 -07003717 if (mAppsCustomizeContent != null) {
3718 mAppsCustomizeContent.addApps(apps);
3719 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003720 }
3721
3722 /**
3723 * A package was updated.
3724 *
3725 * Implementation of the method from LauncherModel.Callbacks.
3726 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003727 public void bindAppsUpdated(final ArrayList<ApplicationInfo> apps) {
3728 if (waitUntilResume(new Runnable() {
3729 public void run() {
3730 bindAppsUpdated(apps);
3731 }
3732 })) {
3733 return;
3734 }
3735
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003736 if (mWorkspace != null) {
3737 mWorkspace.updateShortcuts(apps);
3738 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003739
Winson Chung785d2eb2011-04-14 16:08:02 -07003740 if (mAppsCustomizeContent != null) {
3741 mAppsCustomizeContent.updateApps(apps);
3742 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003743 }
3744
3745 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003746 * A package was uninstalled. We take both the super set of packageNames
3747 * in addition to specific applications to remove, the reason being that
3748 * this can be called when a package is updated as well. In that scenario,
3749 * we only remove specific components from the workspace, where as
3750 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003751 *
3752 * Implementation of the method from LauncherModel.Callbacks.
3753 */
Winson Chung83892cc2013-05-01 16:53:33 -07003754 public void bindComponentsRemoved(final ArrayList<String> packageNames,
3755 final ArrayList<ApplicationInfo> appInfos,
3756 final boolean matchPackageNamesOnly) {
3757 if (waitUntilResume(new Runnable() {
3758 public void run() {
3759 bindComponentsRemoved(packageNames, appInfos, matchPackageNamesOnly);
3760 }
3761 })) {
3762 return;
3763 }
3764
3765 if (matchPackageNamesOnly) {
3766 mWorkspace.removeItemsByPackageName(packageNames);
3767 } else {
3768 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003769 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003770
Winson Chung785d2eb2011-04-14 16:08:02 -07003771 if (mAppsCustomizeContent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -07003772 mAppsCustomizeContent.removeApps(appInfos);
Winson Chung785d2eb2011-04-14 16:08:02 -07003773 }
Winson Chunga1820962011-10-03 16:31:06 -07003774
3775 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003776 mDragController.onAppsRemoved(appInfos, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003777 }
Joe Onoratobe386092009-11-17 17:32:16 -08003778
3779 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003780 * A number of packages were updated.
3781 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003782
3783 private ArrayList<Object> mWidgetsAndShortcuts;
3784 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003785 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003786 bindPackagesUpdated(mWidgetsAndShortcuts);
3787 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003788 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003789 };
3790
3791 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3792 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3793 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003794 return;
3795 }
3796
Winson Chung785d2eb2011-04-14 16:08:02 -07003797 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003798 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003799 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003800 }
3801
Winson Chung400438b2011-01-16 17:53:48 -08003802 private int mapConfigurationOriActivityInfoOri(int configOri) {
3803 final Display d = getWindowManager().getDefaultDisplay();
3804 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3805 switch (d.getRotation()) {
3806 case Surface.ROTATION_0:
3807 case Surface.ROTATION_180:
3808 // We are currently in the same basic orientation as the natural orientation
3809 naturalOri = configOri;
3810 break;
3811 case Surface.ROTATION_90:
3812 case Surface.ROTATION_270:
3813 // We are currently in the other basic orientation to the natural orientation
3814 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3815 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3816 break;
3817 }
3818
3819 int[] oriMap = {
3820 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3821 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3822 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3823 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3824 };
3825 // Since the map starts at portrait, we need to offset if this device's natural orientation
3826 // is landscape.
3827 int indexOffset = 0;
3828 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3829 indexOffset = 1;
3830 }
3831 return oriMap[(d.getRotation() + indexOffset) % 4];
3832 }
Adam Cohen446e9402011-09-15 18:21:21 -07003833
Winson Chung4b919f82012-05-01 10:44:08 -07003834 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08003835 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07003836 getResources().getBoolean(R.bool.allow_rotation);
3837 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003838 }
Winson Chung4b919f82012-05-01 10:44:08 -07003839 public void lockScreenOrientation() {
3840 if (isRotationEnabled()) {
3841 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3842 .getConfiguration().orientation));
3843 }
3844 }
3845 public void unlockScreenOrientation(boolean immediate) {
3846 if (isRotationEnabled()) {
3847 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003848 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003849 } else {
3850 mHandler.postDelayed(new Runnable() {
3851 public void run() {
3852 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3853 }
3854 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003855 }
Winson Chung4b919f82012-05-01 10:44:08 -07003856 }
Winson Chung400438b2011-01-16 17:53:48 -08003857 }
3858
Winson Chung82f55532011-08-09 14:14:23 -07003859 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003860 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003861 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003862 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003863
Michael Jurkae233a8b2013-03-19 13:49:20 +01003864 // Restricted secondary users (child mode) will potentially have very few apps
3865 // seeded when they start up for the first time. Clings won't work well with that
Amith Yamasani9178ed82013-04-12 15:16:23 -07003866 boolean supportsLimitedUsers =
Michael Jurkae233a8b2013-03-19 13:49:20 +01003867 android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
Amith Yamasanid59b0642013-04-25 15:18:12 -07003868 Account[] accounts = AccountManager.get(this).getAccounts();
3869 if (supportsLimitedUsers && accounts.length == 0) {
3870 UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
3871 Bundle restrictions = um.getUserRestrictions();
3872 if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
3873 return false;
3874 }
Michael Jurkae233a8b2013-03-19 13:49:20 +01003875 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003876 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003877 }
Michael Jurka22143132012-10-04 17:42:38 +02003878
Winson Chung7d7541e2011-09-16 20:14:36 -07003879 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02003880 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07003881 if (cling != null) {
3882 cling.init(this, positionData);
3883 cling.setVisibility(View.VISIBLE);
3884 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3885 if (animate) {
3886 cling.buildLayer();
3887 cling.setAlpha(0f);
3888 cling.animate()
3889 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003890 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003891 .setDuration(SHOW_CLING_DURATION)
3892 .setStartDelay(delay)
3893 .start();
3894 } else {
3895 cling.setAlpha(1f);
3896 }
Michael Jurka22143132012-10-04 17:42:38 +02003897 cling.setFocusableInTouchMode(true);
3898 cling.post(new Runnable() {
3899 public void run() {
3900 cling.setFocusable(true);
3901 cling.requestFocus();
3902 }
3903 });
3904 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
3905 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003906 }
3907 return cling;
3908 }
Michael Jurka22143132012-10-04 17:42:38 +02003909
Winson Chung7d7541e2011-09-16 20:14:36 -07003910 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08003911 // To catch cases where siblings of top-level views are made invisible, just check whether
3912 // the cling is directly set to GONE before dismissing it.
3913 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003914 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003915 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003916 anim.addListener(new AnimatorListenerAdapter() {
3917 public void onAnimationEnd(Animator animation) {
3918 cling.setVisibility(View.GONE);
3919 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003920 // We should update the shared preferences on a background thread
3921 new Thread("dismissClingThread") {
3922 public void run() {
3923 SharedPreferences.Editor editor = mSharedPrefs.edit();
3924 editor.putBoolean(flag, true);
3925 editor.commit();
3926 }
3927 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003928 };
3929 });
3930 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02003931 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07003932 }
3933 }
Michael Jurka22143132012-10-04 17:42:38 +02003934
Winson Chung9d9d74f2011-09-19 11:49:12 -07003935 private void removeCling(int id) {
3936 final View cling = findViewById(id);
3937 if (cling != null) {
3938 final ViewGroup parent = (ViewGroup) cling.getParent();
3939 parent.post(new Runnable() {
3940 @Override
3941 public void run() {
3942 parent.removeView(cling);
3943 }
3944 });
Michael Jurka22143132012-10-04 17:42:38 +02003945 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003946 }
3947 }
Michael Jurka974c3862012-05-22 22:00:31 -07003948
3949 private boolean skipCustomClingIfNoAccounts() {
3950 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3951 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3952 if (customCling) {
3953 AccountManager am = AccountManager.get(this);
3954 Account[] accounts = am.getAccountsByType("com.google");
3955 return accounts.length == 0;
3956 }
3957 return false;
3958 }
3959
Winson Chung7d7541e2011-09-16 20:14:36 -07003960 public void showFirstRunWorkspaceCling() {
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() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003963 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3964 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02003965 // If we're not using the default workspace layout, replace workspace cling
3966 // with a custom workspace cling (usually specified in an overlay)
3967 // For now, only do this on tablets
3968 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02003969 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02003970 // Use a custom cling
3971 View cling = findViewById(R.id.workspace_cling);
3972 ViewGroup clingParent = (ViewGroup) cling.getParent();
3973 int clingIndex = clingParent.indexOfChild(cling);
3974 clingParent.removeViewAt(clingIndex);
3975 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
3976 clingParent.addView(customCling, clingIndex);
3977 customCling.setId(R.id.workspace_cling);
3978 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003979 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003980 } else {
3981 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003982 }
3983 }
3984 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003985 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003986 if (isClingsEnabled() &&
3987 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003988 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003989 } else {
3990 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003991 }
3992 }
3993 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003994 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003995 if (isClingsEnabled() &&
3996 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3997 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003998 } else {
3999 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004000 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004001 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004002 }
4003 public boolean isFolderClingVisible() {
4004 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004005 if (cling != null) {
4006 return cling.getVisibility() == View.VISIBLE;
4007 }
4008 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004009 }
Winson Chung82f55532011-08-09 14:14:23 -07004010 public void dismissWorkspaceCling(View v) {
4011 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004012 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004013 }
4014 public void dismissAllAppsCling(View v) {
4015 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004016 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4017 }
4018 public void dismissFolderCling(View v) {
4019 Cling cling = (Cling) findViewById(R.id.folder_cling);
4020 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004021 }
4022
Winson Chung80baf5a2010-08-09 16:03:15 -07004023 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004024 * Prints out out state for debugging.
4025 */
4026 public void dumpState() {
4027 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004028 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004029 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4030 Log.d(TAG, "mRestoring=" + mRestoring);
4031 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4032 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004033 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004034 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004035
Winson Chung785d2eb2011-04-14 16:08:02 -07004036 if (mAppsCustomizeContent != null) {
4037 mAppsCustomizeContent.dumpState();
4038 }
Joe Onoratobe386092009-11-17 17:32:16 -08004039 Log.d(TAG, "END launcher2 dump state");
4040 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004041
4042 @Override
4043 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4044 super.dump(prefix, fd, writer, args);
4045 writer.println(" ");
4046 writer.println("Debug logs: ");
4047 for (int i = 0; i < sDumpLogs.size(); i++) {
4048 writer.println(" " + sDumpLogs.get(i));
4049 }
4050 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004051
4052 public static void dumpDebugLogsToConsole() {
4053 Log.d(TAG, "");
4054 Log.d(TAG, "*********************");
4055 Log.d(TAG, "Launcher debug logs: ");
4056 for (int i = 0; i < sDumpLogs.size(); i++) {
4057 Log.d(TAG, " " + sDumpLogs.get(i));
4058 }
4059 Log.d(TAG, "*********************");
4060 Log.d(TAG, "");
4061 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004062}
Michael Jurka2763be32011-02-24 11:19:57 -08004063
Michael Jurkaabded662011-03-04 12:06:57 -08004064interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004065 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004066 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004067 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004068 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004069 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004070}